m0_52814484
m0_52814484
2021-06-15 11:00
采纳率: 0%
浏览 120

求大家看个课设,很急

基本要求:

假设每位学生必须完成基础课50学分,专业课50学分,选修课24学分,人文类课程8学分,实践性课程20学分才能够毕业。在管理学分时,要考虑每个学分的课程类别。

功能要求:

1、系统以菜单方式工作;

2、能够通过键盘输入、修改和删除某位学生的学分;

3、查询:给定学号,显示某位学生的学分完成情况;给定某个班级编号,显示该班所有学生的学分完成情况;给定某位学生的学号,修改该学生的学分信息;

4、按照某类课程的学分高低排序;

5、能够将所有学生的学分信息读写文件。

 

c++的课设

不用很复杂的那种,但是必须要用链表,谢谢了

  • 点赞
  • 收藏

3条回答 默认 最新

  • technologist_36
    CSDN专家-sinjack 2021-06-15 11:01
    1、Student类
    #include <string>
    #include "Course.h"
    using namespace std;
    class Student{
    	private:
    		string name;
    		string sid;
    		string cid;
    		Course course;
    	public:
    	
    		Student(){
    			name="null";
    			sid="null";
    			cid="null";
    		}
    		
    	
    		void setRecord(int basicCla,int professionCla,int selectCla,int cultureCla//重新设置课程学分 
    				,int practiceCla){
    					course.setBasicCla(basicCla);
    					course.setProfessionCla(professionCla);
    					course.setSelectCla(selectCla);
    					course.setCultureCla(cultureCla);
    					course.setPracticeCla(practiceCla);
    		}
    		
    		
    		Course* getCourse(){//返回课程信息对象 
    				return &course;
    		}
    		
    		void setName(string name){
    			this->name=name;
    		}
    		void setSid(string sid){
    			this->sid=sid;
    		}
    		void setCid(string cid){
    			this->cid=cid;
    		}
    		
    	
    		string getName(){
    			return name;
    		}
    		string getSid(){
    			return sid;
    		}
    		string getCid(){
    			return cid;
    		}
    	
    };
    
    2、Course类
    #include <string>
    using namespace std;
    
    class Course{
    	private:
    		int basicCla;//基础课程学分50
    		int professionCla;//专业课程学分50
    		int selectCla;//选修课程学分24
    		int cultureCla;//人文课程学分8
    		int practiceCla;//实践课程学分20
    	public:
    		
    		Course(){
    			this->basicCla=0;
    			this->professionCla=0;
    			this->selectCla=0;
    			this->cultureCla=0;
    			this->practiceCla=0;
    		}
    		
    		int getBasicCla(){//获取基础课程学分
    			return basicCla;
    		}
    		int getProfessionCla(){//获取专业课程学分
    			return professionCla;
    		}
    		int getSelectCla(){//获取选修课程学分
    			return selectCla;
    		}
    		int getCultureCla(){//获取人文课程学分
    			return cultureCla;
    		}
    		int getPracticeCla(){//获取实践课程学分
    			return practiceCla;
    		}
    		
    		
    		void setBasicCla(int basicCla){//设置基础课程学分
    			this->basicCla=basicCla;
    		}
    		void setProfessionCla(int professionCla){//设置专业课程学分
    			this->professionCla=professionCla;
    		}
    		
    		void setSelectCla(int selectCla){//设置选修课程学分
    			this->selectCla=selectCla;
    		}
    		
    		void setCultureCla(int cultureCla){//设置人文课程学分
    			this->cultureCla=cultureCla;
    		}
    		
    		void setPracticeCla(int practiceCla){//设置实践课程学分
    			this->practiceCla=practiceCla;
    		}
    				
    	};
    
    
    3、main.cpp逻辑代码
    #include <iostream>
    #include <string>
    #include "fstream"
    #include "Student.h" 
    #include "fstream"
    #include <sstream>
    #include<stdlib.h>
    
    //数组长度函数  int sizeof(array) 
    using namespace std;
    const int size=5;
    
    int main(){
    	//函数声明 
    	void ViewBySid(string sid,Student *students);
    	void ViewCidAll(string cid,Student *students); 
    	void changeRecord(string sid,Student *students,int basicCla,int professionCla,int selectCla,int cultureCla,int practiceCla);
    	void setStudents(Student* students);
    	void updateStudents(Student *students);
    	void sortByRecord(int num,Student *students);
    	
    	
    	
    	
    	//将文件中的数据存入对象数组中 
    		Student students[size];
    		setStudents(students);
    		string strNum="";
    		
    		cout<<"菜单"<<endl;
    		cout<< "1.查询某个学生信息"<<endl;
    		cout<< "2.查询班级学生信息" <<endl;
    		cout<< "3.修重置某个学生学分"<<endl;
    		cout<< "4.根据学分排序" <<endl; 
    		
    		cout<<"请输入序号选择对应功能:" ;
     		strNum=cin.get();
     		
     		
    		while(strNum!="esc") {
    		int num=atoi(strNum.c_str());
     		//输入 
     		if(num==1){
     			cout<<"请输入学生的学号"<<endl;
    			string sid;
    			cin>>sid;
    			ViewBySid(sid,students);
    		 }else if(num==2){
    		 	cout<<"请输入班级"<<endl;
    			 string cid;
    			 cin>> cid;
    			 ViewCidAll(cid,students);
    		 }else if(num==3){
    		 	cout<<"请输入学号"<<endl;
    			 string sid;
    			 int basicCla;
    			 int professionCla;
    			 int selectCla;
    			 int cultureCla;
    			 int practiceCla;
    			 cin>>sid;
    			 cout<<"请输入基础课学分"<<endl;
    			 cin>>basicCla;
    			 cout<<"请输入专业课学分"<<endl;
    			 cin>>professionCla;
    			 cout<<"请输入选修课学分"<<endl;
    			 cin>>selectCla;
    			 cout<<"请输入文体课学分"<<endl;
    			 cin>>cultureCla;
    			 cout<<"请输入实践课学分"<<endl;
    			 cin>>practiceCla;
    			 changeRecord(sid,students,basicCla,professionCla,selectCla,cultureCla,practiceCla);
    			 
    			  
    		 }else if(num==4){
    		 	cout<<"输入下列序号选择排序的种类"<<endl; 
    		 	cout<<"1.按照基础课程学分进行排序"<<endl;
    		 	cout<<"2.按照专业课程学分进行排序"<<endl;
    		 	cout<<"3.按照选修课程学分进行排序"<<endl;
    		 	cout<<"4.按照文体课程学分进行排序"<<endl;
    		 	cout<<"5.按照实践课程学分进行排序"<<endl;
    		 	string orderNum;
    		 	cin>>orderNum;
    		 	int num=atoi(orderNum.c_str());
    		 	sortByRecord(num,students);
    		 }
     		updateStudents(students);
     		cout<<endl;
     		cout<<"继续输入序号使用其他功能,输入esc退出程序"<<endl; 
     		cin.get();
    		cin>>strNum;
     	}
     	cout<<"谢谢使用!"<<endl; 
     		
                         
            
    	
    		
    	
    	
    	
    	return 0;
    }
    
    //传入学号,显示该学生的信息 
    void ViewBySid(string sid,Student *students){
    	for(int i=0;i<size;i++){
    		if(sid==students[i].getSid()){
    			Course *course=students[i].getCourse();
    			cout<<students[i].getName()<<"  ";
    			cout<<students[i].getSid()<<"  ";
    			cout<<students[i].getCid()<<"  ";
    			cout<<course->getBasicCla()<<"  ";
    			cout<<course->getProfessionCla()<<"  ";
    			cout<<course->getSelectCla()<<"  ";
    			cout<<course->getCultureCla()<<"  ";
    			cout<<course->getPracticeCla()<<"  ";
    			break;
    			
    		}
    	}
    }
    
    //传入班号,显示所有学生的信息 
    void ViewCidAll(string cid,Student *students){
    	for(int i=0;i<size;i++){
    		if(cid==students[i].getCid()){
    			Course *course=students[i].getCourse();
    			cout<<students[i].getName()<<"  ";
    			cout<<students[i].getSid()<<"  ";
    			cout<<students[i].getCid()<<"  ";
    			cout<<course->getBasicCla()<<"  ";
    			cout<<course->getProfessionCla()<<"  ";
    			cout<<course->getSelectCla()<<"  ";
    			cout<<course->getCultureCla()<<"  ";
    			cout<<course->getPracticeCla()<<"  "<<endl;
    			
    		}
    	}
    }
    
    
    // 传入学号,修改学分信息
    void changeRecord(string sid,Student *students,int basicCla,int professionCla,int selectCla,int cultureCla,int practiceCla){
    		for(int i=0;i<size;i++){
    		if(sid==students[i].getSid()){
    			Course *course=students[i].getCourse();
    			course->setBasicCla(basicCla);
    			course->setProfessionCla(professionCla);
    			course->setSelectCla(selectCla);
    			course->setCultureCla(cultureCla);
    			course->setPracticeCla(practiceCla);
    		}
    	}
    
    
    
    } 
    //将文件中信息存储到students对象数组中 
    
    void setStudents(Student* students){
    	char filename[]="D://student.txt";
    		ifstream fin;
            fin.open(filename,ios::in);
            if(!fin){
            	cout<<"文件打开失败"; 
    		}
    		for(int i=0;i<size;i++){
    			string str;
    			fin>>str;
    			students[i].setName(str);
    			
    			fin>>str;
    			students[i].setSid(str);
    			
    			fin>>str;
    			students[i].setCid(str);
    			
    			
    			fin>>str;
    			students[i].getCourse()->setBasicCla(atoi(str.c_str()));
    			fin>>str;
    			students[i].getCourse()->setProfessionCla(atoi(str.c_str()));
    			fin>>str;
    			students[i].getCourse()->setSelectCla(atoi(str.c_str()));
    			fin>>str;
    			students[i].getCourse()->setCultureCla(atoi(str.c_str()));
    			fin>>str;
    			students[i].getCourse()->setPracticeCla(atoi(str.c_str()));
     		
    		}
    		fin.close();
    		
    } 
    //将数组信息更新到文件中 
    
    void updateStudents(Student *students){
    	 	char filename[] = "D://student.txt";
            char buff[1024]= {0};
            /***********  写文件  *************/
            //输出流ofstream对象调用fopen函数
            ofstream fout;
            fout.open(filename,ios::out);
            if(!fout)
            {
                    cout<<"打开文件失败"<<filename<<endl;
            }
            
            
            
            
            for(int i=0;i<size;i++){
            	if(students[i].getName()==""){
            		fout<<"null"<<" ";
    			}else{
    				fout<<students[i].getName()<<" ";
    			}
    			if(students[i].getSid()==""){
            		fout<<"null"<<" ";
    			}else{
    				fout<<students[i].getSid()<<" ";
    			}
    			if(students[i].getCid()==""){
            		fout<<"null"<<" ";
    			}else{
    				fout<<students[i].getCid()<<" ";
    			}
     			
     			
     			
     			
     			Course * course =students[i].getCourse();
     			fout<<course->getBasicCla()<<" ";
    			fout<<course->getProfessionCla()<<" ";
    			fout<<course->getSelectCla()<<" ";
    			fout<<course->getCultureCla()<<" ";
    			fout<<course->getPracticeCla()<<endl;
    		}
            
            
            
            fout.flush();
            fout.close();
    
    }
    
    
    //对某类课程的分数进行排序    通过switch让用户进行数字选择,对应相应的课程 
    void sortByRecord(int num,Student *students){
    	Student *stus[5];
    	for(int i=0;i<size;i++){
    		stus[i]=&students[i];
    	}
    	
    	if(num==1){//根据基础课程进行排序 
    		for(int i=0;i<size-1;i++){
    			for(int j=0;j<size-i-1;j++){
    				Course *course=stus[j]->getCourse();
    				Course *course2=stus[j+1]->getCourse();
    				if(course->getBasicCla() > course2->getBasicCla()){
    					
    					Student *temp;
    					temp=stus[j];
    					stus[j]=stus[j+1];
    					stus[j+1]=temp;
    				}
    			}
    		}
    		
    	
    		
    	}else if(num==2){//根据专业课程进行排序 
    		for(int i=0;i<size-1;i++){
    			for(int j=0;j<size-i-1;j++){
    				Course *course=stus[j]->getCourse();
    				Course *course2=stus[j+1]->getCourse();
    				if(course->getProfessionCla() > course2->getProfessionCla()){
    					
    					Student *temp;
    					temp=stus[j];
    					stus[j]=stus[j+1];
    					stus[j+1]=temp;
    				}
    			}
    		}
    		
    		
    	}else if(num==3){//根据 选修课程进行排序 
    		for(int i=0;i<size-1;i++){
    			for(int j=0;j<size-i-1;j++){
    				Course *course=stus[j]->getCourse();
    				Course *course2=stus[j+1]->getCourse();
    				if(course->getSelectCla() > course2->getSelectCla()){
    					
    					Student *temp;
    					temp=stus[j];
    					stus[j]=stus[j+1];
    					stus[j+1]=temp;
    				}
    			}
    		}
    		
    	}else if(num==4){//根据文体课程进行排序 
    		for(int i=0;i<size-1;i++){
    			for(int j=0;j<size-i-1;j++){
    				Course *course=stus[j]->getCourse();
    				Course *course2=stus[j+1]->getCourse();
    				if(course->getCultureCla() > course2->getCultureCla()){
    					
    					Student *temp;
    					temp=stus[j];
    					stus[j]=stus[j+1];
    					stus[j+1]=temp;
    				}
    			}
    		}
    		
    		
    	}else if(num==5){//根据实践课程进行排序 
    		
    		for(int i=0;i<size-1;i++){
    			for(int j=0;j<size-i-1;j++){
    				Course *course=stus[j]->getCourse();
    				Course *course2=stus[j+1]->getCourse();
    				if(course->getPracticeCla() > course2->getPracticeCla()){
    					
    					Student *temp;
    					temp=stus[j];
    					stus[j]=stus[j+1];
    					stus[j+1]=temp;
    				}
    			}
    		}
    		
    		
    	}else{}
    	for(int i=0;i<size;i++){
    		Student stu=*stus[i];
    			Course *course=stu.getCourse();
    			cout<<stu.getName()<<"  ";
    			cout<<stu.getSid()<<"  ";
    			cout<<stu.getCid()<<"  ";
    			cout<<course->getBasicCla()<<"  ";
    			cout<<course->getProfessionCla()<<"  ";
    			cout<<course->getSelectCla()<<"  ";
    			cout<<course->getCultureCla()<<"  ";
    			cout<<course->getPracticeCla()<<"  "<<endl;
    		}
    } 
    
    

    如有帮助,望采纳。点击我回答右上角【采纳】按钮。

    点赞 评论
  • technologist_37
    CSDN专家-link 2021-06-15 13:27

    你是想网上找一个用,还是全新的写一个?必须要链表和继承吗?那得单独写才行,没有现成的

    点赞 评论
  • Feng_wwf
    NDSC专家-王文峯 2021-06-15 14:06

    上面csdn专家不是给你写好了吗

    点赞 评论

相关推荐