求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这

求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这已经是我第三次发布这个问题了!希望有靠谱的人,帮忙,大恩不言谢€... 求一个100到300行之间的c++程序!方向不限,有必要的注释!希望不要去网上复制粘贴,多谢了!这已经是我第三次发布这个问题了!希望有靠谱的人,帮忙,大恩不言谢😊 展开
 我来答
小小小小度无名
推荐于2016-09-08 · 超过15用户采纳过TA的回答
知道答主
回答量:32
采纳率:0%
帮助的人:19.8万
展开全部
#include<iostream>
#include<conio.h>
#include<string.h>
#include<iomanip>
#include<windows.h>
#include<fstream>
using namespace std;
 
class student //定义学生类
{
 private://定义学生类的私有成员
       charname[20]; //名字
       charsex[5]; //性别
       intnumber; //学号
       intscore[5]; //分数
       inttotal; //总分
       doubleaverage; //平均分
 public: //公有成员
       student();//学生构造函数,用于学生数据的初始化及保存学生数据
       voidadd(); //添加学生信息函数
       voidoutput(); //输出学生信息函数
       voidfind(); //查找学生数据函数
       voidmodify(); //修改学生信息函数
       voiddeleted(); //删除学生信息函数
       voidsort(); //排序函数
       voidsave(); //保存学生信息并写入文件函数
       voidload (); //打开写有学生信息的文件的函数
       student& operator = (student & T); //重载"="符号
       friendistream & operator >> (istream&, student&); //重载">>"符号
       friendostream & operator << (ostream&, student&); //重载"<<"符号
};
 
student stu[100];
int n=0;
 
void student::add() //添加函数
{
       charflag='Y';
       while(toupper(flag)=='Y')
       {
              system("cls");
              cin>> stu[n];
              n++;
              cout<< "\t要继续添加吗(y/n)";
              cin>> flag;
              if(toupper(flag)!= 'Y')
              {
                     if(toupper(flag)== 'N')
                     {
                            break;
                     }
                     else
                     {
                            cout<< "\t错误,请重输:";
                            cin>> flag;
                     }
              }
       }
}
 
void student::output() //输出函数
{
       if(n!=0)
       { 
              for(intt = 0;t < n;t++)
              {
                     cout<< stu[t];
              }
       }
       getch();
       system("cls");
}
void student::find() //查找函数
{
       intchoose;
       cout<< "\t\t\t——————查询方式——————" << endl;
       cout<< "\t\t\t1.某个学生全部成绩" << endl;
       cout<< "\t\t\t2.不及格学生的信息" << endl;
       cout<< "\t\t\t3.平均分高于80的学生信息"<< endl;
       cout<<"你的查询方式是:";
       cin>> choose;
       switch(choose)
       {
              case1:
                     {
                            intf3 = 0;
                            charn1[20];
                            studenttemp;
                            cout<<"\t输入你要查找的人的姓名: ";
                            cin>> n1;
                            for(intj=0;j<n;j++)
                            {
                                   if(strcmp(stu[j].name,n1)==0)
                                   {
                                          temp=stu[j];
                                          f3=1;
                                   }
                            }
                            if(f3==0)
                                   cout<<"\t对不起,没有你要查找的学生成绩"<<endl;
                    
                            else
                            {
                                   cout<< temp;
                            }
                            getch();
                            system("cls");
                     };break;
                    
              case2:
                     {
                            intflag = 0;
                            for(intj = 0;j < n;j++)
                            {
                                   if(stu[j].average< 60)
                                   {
                                          flag= 1;
                                          cout<< stu[j];
                                   }
                                         
                            }
                            if(flag== 0)
                                   cout<< "\t没有不及格的学生"<<endl;
                            getch();
                            system("cls");
                     }
                    
              case3:
                     {
                            intflag = 0;
                            for(intj = 0;j < n;j++)
                            {
                                   if(stu[j].average> 80)
                                   {
                                          flag= 1;
                                          cout<< stu[j];
                                   }
                                         
                            }
                            if(flag== 0)
                                   cout<< "\t没有高于80分的学生"<<endl;
                            getch();
                            system("cls");
                     }
       }
      
}
 
void student::modify() //修改函数
{
       intf4=0;
       intt;
       charn2[50];
       cout<<"\t输入你要修改的人的姓名:";
       cin>>n2;
       for(intj=0;j<n;j++)
       {
              if(strcmp(stu[j].name,n2)==0)
              {
                     t=j;
                     f4=1;
              }
       }
       if(f4==0)
              cout<<"\t对不起,没有你要修改的学生成绩"<<endl;
       else
       {
              cout<<"\t\t请输入学号: ";
              cin>>stu[t].number;
              cout<<"\t\t姓名: ";
              cin>>stu[t].name;
              cout<<"\t----------修改成绩的科目----------"<<endl;
              cout<<"\t\t1.数学\n\t\t2.英语\n\t\t3.C++\n\t\t4.汇编\n\t\t5.组成原理"<<endl;
              inti;
              cin>> i;
              cout<<"\t\t成绩:";
              cin>>stu[t].score[i];              
              stu[t].total=stu[t].score[0]+stu[t].score[1]+stu[t].score[2]+stu[t].score[3]+stu[t].score[4];
              stu[t].average=stu[t].total/5;
              cout<<"修改成功!"<<endl;
       }
       getch();
       system("cls");
}
 
void student::sort() //排序函数
{
       inti,j,k;
       students3;
       for(i=0;i<(n-1);i++)
       {
              k=i;
              for(j=i+1;j<n;j++)
                     if(stu[j].average>stu[i].average)
                            k=j;
                     if(k!=i)
                     {
                            s3=stu[i];
                            stu[i]=stu[k];
                            stu[k]=s3;
                     }
       }
       cout<<"\n\n\t排序成功!\n\n";
       getch();
       system("cls");
 
}
 
void student::save() //保存函数
{
       charfilename1[20];
       cout<<"\t请输入文件名: ";
       cin>>filename1;
       ofstreamfout(filename1,ios::app);
       if(!fout)cout<<"\t文件不能打开!"<<endl;
       else
       {
              for(inti=0;i<n;i++)
                     fout<<''<<stu[i].name<<' '<<stu[i].sex<<''<<stu[i].number<<' '
                     <<stu[i].score[0]<<''<<stu[i].score[1]<<' '<<stu[i].score[2]<<''<<stu[i].total<<' '<<stu[i].average<<' ';
              cout<<"\t保存成功!"<<endl;
       }
       fout.close();
       getch();
}
void student::load() //读取函数
{
       charfilename2[20];
       cout<<"\t请输入你要读取的文件名: ";
       cin>>filename2;
       ifstreamfin(filename2,ios::in);
       if(!fin)cout<<"\t文件打不开 !"<<endl;
       else
       {
              for(inti=0;;i++,n=i-1)
              {
                     if(fin.eof())break;
                     fin>>stu[i].name>>stu[i].sex>>stu[i].number
                            >>stu[i].score[0]>>stu[i].score[1]>>stu[i].score[2]>>stu[i].total>>stu[i].average;
              }
              cout<<"\t文件已读取成功!"<<endl;
       }
       fin.close();
       getch();
}
student & student::operator=(student& T) //重载=
{
       strcpy(name,T.name);
       strcpy(sex,T.sex);
       number=T.number;
       for(inti=0;i<5;i++)score[i]=T.score[i];
       total=T.total;
       average=T.average;
       return( * this );
}
ostream & operator << (ostream& scout, student &s2) //重载<<
{
       cout<<"\t****************************************************"<<endl;
       cout<<"\t\t\t姓名:"<<s2.name<<endl;
       cout<<"\t\t\t学号:"<<s2.number<<endl;
       cout<<"\t\t\t性别:"<<s2.sex<<endl;
       cout<<"\t\t\t数学:"<<s2.score[0]<<endl;
       cout<<"\t\t\t英语:"<<s2.score[1]<<endl;
       cout<<"\t\t\tC++:"<<s2.score[2]<<endl;
       cout<<"\t\t\t汇编:"<<s2.score[3]<<endl;
       cout<<"\t\t\t组成原理:"<<s2.score[4]<<endl;
   cout<<"\t\t\t总成绩:"<<s2.total<<endl;
       cout<<"\t\t\t平均分:"<<s2.average<<endl<<endl<<endl;
      
       returnscout;
}
 
istream & operator >> (istream& scin,student &s1) //重载>>
{
       cout<<" \t学号:";
       scin>>s1.number;
       cout<<" \t姓名:";
       scin>>s1.name;
       cout<<" \t性别 :";
       scin>>s1.sex;
       cout<<" \t数学成绩:";
       scin>>s1.score[0];
       cout<<" \tC++成绩:";
       scin>>s1.score[1];
       cout<<" \t英语成绩:";
       scin>>s1.score[2];
       cout<<" \t汇编成绩:";
       scin>>s1.score[3];
       cout<<" \t组成原理成绩:";
       scin>>s1.score[4];
       s1.total=s1.score[0]+s1.score[1]+s1.score[2]+ s1.score[3] + s1.score[4];
       s1.average=s1.total* 1.0 / 5;
       returnscin;
}
 
student::student() //构造函数
{
       strcpy(name,"");
       strcpy(sex,"");
       number=0;
       for(inti = 0;i < 5;i++) score[i] = 0;
       total=0;
       average=0.0;
}
 
void menu() //菜单函数
{
       cout<<"*******************************************************************************"<<endl;
       cout<<"\t\t\t学生成绩管理系统主菜单 "<<endl;
       cout<<"\n\t\t\t1.录入学生成绩 "<<endl;
       cout<<"\t\t\t2.输出学生成绩 "<<endl;
       cout<<"\t\t\t3.查找学生成绩 "<<endl;
       cout<<"\t\t\t4.修改学生成绩 "<<endl;
       cout<<"\t\t\t5.按成绩排序 "<<endl;
       cout<<"\t\t\t6.保存数据 "<<endl;
       cout<<"\t\t\t7.读出数据 "<<endl;
       cout<<"\t\t\t8.退出系统 "<<endl;
       cout<<"\n\n请选择(1~8)并按回车键确认:";

 
int main() //主函数
{
       intchoose;
       students;
       do{
              menu();
              cin>>choose;
              switch(choose)
              {
                     case1: s.add(); break;
                     case2: s.output(); break;
                     case3: s.find(); break;
                     case4: s.modify(); break; 
                     case5: s.sort(); break;
                     case6: s.save(); break;
                     case7: s.load(); break;
                     default: choose = 8;
              }
       }while(choose!=8);
       cout<< "退出成功!"<<endl;
       return0;
}



这是我的课程设计,禁止用做其他与发版有关的商用。
更多追问追答
追问
好长哦!有短一点的吗?100到300行之间
追答
这个其实不长,中间空行比较多 ,有些输出语句写到一行就短了,你也可以删除一些功能。程序又不复杂。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式