| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 489 人关注过本帖
标题:注释 C++
只看楼主 加入收藏
麦田打望者
Rank: 2
等 级:论坛游民
帖 子:62
专家分:34
注 册:2010-5-31
结帖率:77.78%
收藏
已结贴  问题点数:0 回复次数:2 
注释 C++
哪位大侠把长省略号前面的程序帮我注释下,我查了很多资料都没找到,本人自学严重需要各位的帮助。
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
class  Stu       //构建学生类
{
public:
    friend void Input(Stu stud[]) ;
    friend void Output(Stu stud[]) ;
    friend void Lookup(Stu stud[]) ;
    friend void Xiugai(Stu stud[]) ;
    friend void Delete(Stu stud[]) ;
    friend void Insert(Stu stud[]) ;
    friend void Sort(Stu stud[]) ;
    friend void Write(Stu stud[],int n);
    friend int Read(Stu stud[]);
private:
    char class_0[20];
    int num;
    char name[8];

    float c_program;
   
    float english;
    float math;

    float average;
    int order;
}stud[100];

void Input(Stu stud[])  //---------------输入学生成绩
{
    system("cls"); /*运行前清屏*/
    int i=0;
    int flag;
    char sign;
    cout<<endl<<"====>> 请输入学生成绩 <<===="<<endl;
    while(sign!='n'&&sign!='N') /*判断*/
    {
        cout<<"    班级:"; /*交互输入*/
        cin>>stud[i].class_0;
loop:
        cout<<"    学号:";
        cin>>stud[i].num;
        int c=0;
        while(c<i)//................................
        {
            c++;
            if(stud[i].num==stud[i-c].num)
            {
                cout<<" 你输入的学号已经存在!请重新输入。"<<endl;
                goto loop;
            }        
        }
        cout<<"    姓名:";
        cin>>stud[i].name;
        
        do{     
            flag=0;
            cout<<"    C++程序设计成绩:";
            cin>>stud[i].c_program;
            if(stud[i].c_program>100 ||stud[i].c_program<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
        
        do{   
            flag=0;
             cout<<"    大学英语成绩:";
             cin>>stud[i].english;
            if(stud[i].english>100 ||stud[i].english<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
        do{   
            flag=0;
            cout<<"    高等数学成绩:";
            cin>>stud[i].math;
            if(stud[i].math>100 ||stud[i].math<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
      
    stud[i].average=(stud[i].c_program+stud[i].english+stud[i].math)/3;
        cout<<"    平均分为:"<<stud[i].average<<endl;
         cout<<"====>提示:是否继续写入学生成绩?(Y/N)";
        cin>>sign; /*输入判断*/
        i++; //...................................
    }
    Write(stud,i);
}

void Write(Stu stud[],int n)  //向文件中写入数据
{
    fstream myFile;//.......................................
    myFile.open("student.dat",ios::out|ios::binary);// .........................ios::binary二进制
    if(!myFile)
    {
        cout<<"student.dat can't open!"<<endl;
        abort();//..............................................
    }
    int count=n;//..............................................................
    myFile<<count<<endl<<endl;
    for(int i=0;i<=count;i++)
    {
        myFile<<stud[i].class_0<<" "<<stud[i].num<<" "<<stud[i].name<<" "<<stud[i].c_program<<" "<<stud[i].english
<<" "<<stud[i].math<<" "<<stud[i].average<<endl;
    }
      myFile.close();
}
int Read(Stu stud[])  //从文件中读数据
{
      fstream myFile;
      myFile.open("student.dat",ios::in|ios::binary);
      if(!myFile)
    {
        cout<<"student.dat can't open!"<<endl;
        abort();
    }
      int count;
      myFile.seekg(0);
      myFile>>count;//............................................................
      for(int i=0;i<=count;i++)
      {   
myFile>>stud[i].class_0>>stud[i].num>>stud[i].name>>stud[i].c_program>>stud[i].english>>stud[i].math>>stud[i].average;
      }
   myFile.close();
   return count ;
}


void Lookup(Stu stud[]) //---------------查找学生成绩
{
    system("cls"); /*运行前清屏*/
    int n=Read(stud);
    int s;
    int i=0;
    cout<<endl<<"====>> 查找学生成绩 <<===="<<endl;
    cout<<"请输入需要查找学生的学号:"<<endl;
    cin>>s;
    while((stud[i].num-s)!=0&&i<n) i++; /*查找判断*/
    if(i==n)
    {
        cout<<"=====>提示:对不起,无法找到该学生的信息!"<<endl; /*输入失败信息*/
    }
    else
    {
        cout<<"---------------------------"<<endl;
        cout<<"班级:"<<stud[i].class_0<<endl; /*输出该学生信息*/
        cout<<"学号:"<<stud[i].num<<endl;
        cout<<"姓名:"<<stud[i].name<<endl;
   
        cout<<"C++程序设计:"<<stud[i].c_program<<endl;
        
        cout<<"大学英语:"<<stud[i].english<<endl;
        cout<<"高等数学:"<<stud[i].math<<endl;
   
        cout<<"平均分:"<<stud[i].average<<endl;
    }
}
void Xiugai(Stu stud[])   //---------------修改学生成绩
{
    system("cls"); /*运行前清屏*/
    int n=Read(stud);
    int s;
    int i=0;
    cout<<endl<<"====>> 修改学生成绩 <<===="<<endl;
    cout<<"请输入需要修改成绩学生的学号:"<<endl;
    cin>>s;
    while((stud[i].num-s)!=0&&i<n) i++; /*查找判断*/
    if(i==n)
    {
        cout<<"=====>提示:对不起,无该学生的成绩……"<<endl; /*输入失败信息*/
    }
    else
    {
        cout<<"----------该学生的信息----------"<<endl; /*格式头*/
        cout<<"班级"<<"\t"<<"学号"<<"\t"<<"姓名"<<"\t"<<"c++"<<"\t"<<"\t"<<"英语"<<"\t"<<"数学"<<"\t"<<"平均分"<<endl;
        cout<<"---------------------------------"<<endl;
    cout<<stud[i].class_0<<"\t"<<stud[i].num<<"\t"<<stud[i].name<<"\t"<<stud[i].c_program<<"\t"<<stud[i].english<<"\t"<<stud[i].math<<"\t"<<stud[i].average<<endl;
        cout<<"请重新输入该学生的信息"<<endl;
        cout<<"班级:"<<endl; /*交互输入*/
        cin>>stud[i].class_0;
        cout<<"学号:"<<endl;
        cin>>stud[i].num;
        cout<<"姓名:"<<endl;
        cin>>stud[i].name;
   
        cout<<"C++程序设计成绩:"<<endl;
        cin>>stud[i].c_program;
   
        cout<<"大学英语成绩:"<<endl;
        cin>>stud[i].english;
        cout<<"高等数学成绩:"<<endl;
        cin>>stud[i].math;
   
   
    stud[i].average=(stud[i].c_program+stud[i].english+stud[i].math)/3;
        cout<<"平均分为:"<<stud[i].average<<endl;
        char c;
        cout<<"是否保存数据?(y/n)"<<endl;
        cin>>c;
        if(c!='n'&&c!='N')
        Write(stud,n);
    }
}
void Delete(Stu stud[]) //---------------按学号查找,删除学生信息
{
    system("cls"); /*运行前清屏*/
    int n=Read(stud);
    int s;
    int i=0,j;
    cout<<endl<<"====>> 删除学生成绩 <<===="<<endl;
    cout<<"请输入需要删除学生的学号:"<<endl; /*交互式问寻*/
    cin>>s;
    while((stud[i].num-s)!=0&&i<n) i++; /*查找判断*/
    if(i==n)
    {
        cout<<"====>提示:对不起,无法找到该学生……"<<endl; /*返回失败信息*/
    }
    else
    {
        for(j=i;j<n-1;j++) /*删除操作*/
        {
            strcpy(stud[j].class_0,stud[j+1].class_0);
            stud[j].num=stud[j+1].num;
            strcpy(stud[j].name,stud[j+1].name);
            
            stud[j].c_program=stud[j+1].c_program;
            
            stud[j].english=stud[j+1].english;
            stud[j].math=stud[j+1].math;
            
            stud[j].average=stud[j+1].average;
        }
        cout<<"====>提示:已成功删除!"<<endl; /*返回成功信息*/
    }
    Write(stud,n-1);
}
void Insert(Stu stud[])  //---------------增加学生成绩
{
    system("cls"); /*运行前清屏*/
    int n=Read(stud);
    char s;
    cout<<endl<<"====>> 增加学生成绩<<===="<<endl;
    while(s!='n'&&s!='N')
    {
        cout<<"班级:"<<endl; /*交互输入*/
        cin>>stud[n].class_0;
        cout<<"学号:";
        cin>>stud[n].num;
        cout<<"姓名:";
        cin>>stud[n].name;
        
        cout<<"C++程序设计成绩:";
        cin>>stud[n].c_program;
      
        cout<<"大学英语成绩:";
        cin>>stud[n].english;
        cout<<"高等数学成绩:";
        cin>>stud[n].math;
        
         
    stud[n].average=(stud[n].c_program+stud[n].english+ stud[n].math)/3;
    cout<<"平均分"<<stud[n].average;
    n++;
    cout<<"=====>提示:插入成功!"<<endl; /*返回成功信息*/
    cout<<"是否继续输入(y/n)"<<endl;
    cin>>s;
    }
    Write(stud,n);
}
void Sort(Stu stud[]) //---------------按平均分对学生成绩记录项进行降序排序
{
    system("cls"); /*运行前清屏*/
    int i,j,k;
    float s;
    char t[20];
    cout<<endl<<"====>> 降序排序成绩 <<===="<<endl;
    int n=Read(stud);
    for(i=0;i<n-1;i++) /*冒泡法排序*/
        for(j=0;j<n-1-i;j++)
            if(stud[j].average<stud[j+1].average)
            {
                strcpy(t,stud[j+1].class_0);
                strcpy(stud[j+1].class_0,stud[j].class_0);
                strcpy(stud[j].class_0,t);
                k=stud[j+1].num;
                stud[j+1].num=stud[j].num;
                stud[j].num=k;
                strcpy(t,stud[j+1].name);
                strcpy(stud[j+1].name,stud[j].name);
                strcpy(stud[j].name,t);
            
                s=stud[j+1].c_program;
                stud[j+1].c_program=stud[j].c_program;
                stud[j].c_program=s;
            
                s=stud[j+1].english;
                stud[j+1].english=stud[j].english;
                stud[j].english=s;
                s=stud[j+1].math;
                stud[j+1].math=stud[j].math;
                stud[j].math=s;
            
            
                s=stud[j+1].average;
                stud[j+1].average=stud[j].average;
                stud[j].average=s;
            }
    cout<<"----------------------------------------------------"<<endl; /*格式头*/
    cout<<"班级"<<"\t"<<"学号"<<"\t"<<"姓名"<<"\t"<<"C++"<<"\t"<<"英语"<<"\t"<<"数学"<<"平均分"<<"\t"<<"名次"<<endl;
    cout<<"----------------------------------------------------"<<endl;
            for(i=0;i<n;i++) /*循环输入*/
            {
                stud[i].order=i+1;
    cout<<stud[i].class_0<<"\t"<<stud[i].num<<"\t"<<stud[i].name<<"\t"<<stud[i].c_program<<"\t "<<stud[i].english<<" \t"<< stud[i].math<<"\t"<<stud[i].average<<"\t"<<stud[i].order<<endl;     
            }
            Write(stud,n);
}
void Output(Stu stud[]) //---------------显示全部学生成绩
{
    system("cls"); /*运行前清屏*/
    int n=Read(stud);
    cout<<endl<<"====>> 显示全部学生成绩 <<===="<<endl;
    if(!stud)
        cout<<"没有记录";
    else
    {
    cout<<"----------------------------------------------------"<<endl; /*格式头*/
        cout<<"班级"<<"\t"<<"学号"<<"\t"<<"姓名"<<"\t"<<"c++"<<"\t"<<"英语"<<"\t"<<"数学"<<"\t"<<"平均分"<<endl;
        cout<<"------------------------------------------------"<<endl;
        for(int i=0;i<n;i++) /*循环输入*/
    {
        cout<<stud[i].class_0<<"\t "<<stud[i].num<<"\t "<<stud[i].name<<" \t"<<stud[i].c_program<<"\t "<<stud[i].english<<"\t "<< stud[i].math<<"\t"<<stud[i].average<<endl;
    }
cout<<"--------------------------------------------------------"<<endl;
    }
}
int menu() /*菜单函数*/
{
    char c;
    do
    {
        system("cls"); /*运行前清屏*/
        
    cout<<" -----------------欢迎您使用学生成绩管理系统--------------\n"<<endl;
    cout<<" ************************************************************\n\n"<<endl;/*菜单选择*/  
cout<<"    *                 1 输入学生成绩               *     "<<endl;
    cout<<"    *                 2 显示输入的信息             *     "<<endl;

    cout<<"    *                 3 查找学生成绩               *     "<<endl;
    cout<<"    *                 4 修改学生成绩               *    "<<endl;
    cout<<"    *                 5 删除学生成绩               *     "<<endl;
    cout<<"    *                 6 插入新同学成绩             *     "<<endl;
    cout<<"    *                 7 排列名次                   *     "<<endl;
    cout<<"    *                 0 退出本系统                 *   "<<endl<<endl;

    cout<<"请你选择操作(0-7):"<<endl;
    c=getchar(); /*读入选择*/
    }
    while(c<'0'||c>'7');
    return(c-'0'); /*返回选择*/
}
void main() /*主函数*/
{
    for(;;) //实现不断选择
    {
        switch(menu()) /*选择判断*/
        {
            case 1:
                Input(stud);/*输入学生成绩*/      
                break;
    case 2:
                Output(stud);  /*显示全部学生成绩*/
                cout<<"\t\t\t";
                system("pause");
                break;
            
            case 3:      
                Lookup(stud); /*查找学生成绩*/
                cout<<"\t\t\t";
                system("pause");
                break;
            case 4:     
                Xiugai(stud); /*修改学生成绩*/
                cout<<"\t\t\t";
                system("pause");
                break;
            case 5:
                Delete(stud); /*按学号查找,删除学生信息*/
                cout<<"\t\t\t";
                system("pause");
                break;
            case 6:     
                Insert(stud);/*增加学生成绩*/
                cout<<"\t\t\t";
                system("pause");
                break;
            case 7:     
                Sort(stud); /*按平均分对成绩记录项进行降序排序*/  
                cout<<"\t\t\t";
                system("pause");
                break;
        
            case 0:
                cout<<endl<<" ================================<<感谢您使用学生成绩管理系统>>===============================\n"<<endl; /*结束程序*/
                cout<<"\t\t\t";
                system("pause");
                exit(0);
        }
    }
}
搜索更多相关主题的帖子: 学生 
2011-01-10 09:33
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:20 
程序代码:
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
class  Stu       //构建学生类
{
public:
    friend void Input(Stu stud[]) ;       
    friend void Output(Stu stud[]) ;
    friend void Lookup(Stu stud[]) ;
    friend void Xiugai(Stu stud[]) ;
    friend void Delete(Stu stud[]) ;
    friend void Insert(Stu stud[]) ;
    friend void Sort(Stu stud[]) ;
    friend void Write(Stu stud[],int n);    
    friend int Read(Stu stud[]);
private://................................上面是成员函数的声明................................//
    char class_0[20];
    int num;
    char name[8];

    float c_program;
   
    float english;
    float math;

    float average;
    int order;
}stud[100];//****************************私有数据成员 每个学生的信息**************************************//

void Input(Stu stud[])  //---------------输入学生成绩
{
    system("cls"); /*运行前清屏*/
    int i=0;
    int flag;
    char sign;
    cout<<endl<<"====>> 请输入学生成绩 <<===="<<endl;
    while(sign!='n'&&sign!='N') /*判断*/
    {
        cout<<"    班级:"; /*交互输入*/
        cin>>stud[i].class_0;
loop:
        cout<<"    学号:";
        cin>>stud[i].num;//输入语句  不会不知道吧
        int c=0;
        while(c<i)//................................这是历遍所有的学生信息检查是否重复
        {
            c++;
            if(stud[i].num==stud[i-c].num)
            {
                cout<<" 你输入的学号已经存在!请重新输入。"<<endl;
                goto loop;//可恶谁写的!  竟然用goto!!!!!!!!!!!!!!!!
            }       
        }
        cout<<"    姓名:";
        cin>>stud[i].name;
       
        do{     //输入不合法就不会跳出循环
            flag=0;
            cout<<"    C++程序设计成绩:";
            cin>>stud[i].c_program;
            if(stud[i].c_program>100 ||stud[i].c_program<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
       
        do{    //同上
            flag=0;
             cout<<"    大学英语成绩:";
             cin>>stud[i].english;
            if(stud[i].english>100 ||stud[i].english<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
        do{   
            flag=0;
            cout<<"    高等数学成绩:";
            cin>>stud[i].math;
            if(stud[i].math>100 ||stud[i].math<1)
               cout<<"对不起,请输入1-100之间的数字!!\n";
            else
               flag=1;
        }while(flag==0);
     
    stud[i].average=(stud[i].c_program+stud[i].english+stud[i].math)/3;
        cout<<"    平均分为:"<<stud[i].average<<endl;
         cout<<"====>提示:是否继续写入学生成绩?(Y/N)";
        cin>>sign; /*输入判断*/
        i++; //...................................学生人数计数器  记录总人数
    }
    Write(stud,i);
}

void Write(Stu stud[],int n)  //向文件中写入数据
{
    fstream myFile;//..定义文件流对象,不应该是fstream  既然要写文件就应该是ofstream
    myFile.open("student.dat",ios::out|ios::binary);// .........................ios::binary二进制
    if(!myFile)
    {
        cout<<"student.dat can't open!"<<endl;
        abort();//....异常终止一个进程。中止当前的过程,返回一个错误代码。错误代码的缺省值是3
    }
    int count=n;//.........还是学生数量  接受的是参数
    myFile<<count<<endl<<endl;
    for(int i=0;i<=count;i++)
    {
        myFile<<stud[i].class_0<<" "<<stud[i].num<<" "<<stud[i].name<<" "<<stud[i].c_program<<" "<<stud[i].english
<<" "<<stud[i].math<<" "<<stud[i].average<<endl;
    }
      myFile.close();
}

int Read(Stu stud[])  //从文件中读数据
{
      fstream myFile;
      myFile.open("student.dat",ios::in|ios::binary);
      if(!myFile)
    {
        cout<<"student.dat can't open!"<<endl;
        abort();
    }
      int count;
      myFile.seekg(0);//移动文件指针到文件头部
      myFile>>count;//............从文件流中提取数据以空字符为区分
      for(int i=0;i<=count;i++)
      {  
myFile>>stud[i].class_0>>stud[i].num>>stud[i].name>>stud[i].c_program>>stud[i].english>>stud[i].math>>stud[i].average;
      }
   myFile.close();
   return count ;
}

楼主可以用链表写个   这个不太好既然用类写
还要出现全局函数   还有就是goto我意见是  坚决不用
除非是程序会崩溃,可以goto到结束程序的代码

                                         
===========深入<----------------->浅出============
2011-01-10 09:57
麦田打望者
Rank: 2
等 级:论坛游民
帖 子:62
专家分:34
注 册:2010-5-31
收藏
得分:0 
回复 2楼 laoyang103
谢谢你!虽然还是不懂,但有你的热心,让我坚定了学好C的决心
2011-01-10 10:23
快速回复:注释 C++
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037630 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved