| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 478 人关注过本帖
标题:[求助]详细分析一下这个VC++程序
取消只看楼主 加入收藏
ayghwp
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-19
收藏
 问题点数:0 回复次数:0 
[求助]详细分析一下这个VC++程序

#ifndef Score
#define Score
#include<iostream.h>
#include<string.h>
class student//定义class student类
{
friend class list;//声明class list 是class student的友元类
private:
char name[20];
double num;
double grade[4];
public:
student(){next=0;}
void s();
student *next;
char * outname(){return name;};
double outgrade(int i){return grade[i];};
void intgrade();
};
void student::intgrade()//定义intgrade
{ cout<<" 请输入语文成绩\n";
cin>>grade[0];
cout<<"请输入英语成绩\n";
cin>>grade[1];
cout<<"请输入数学成绩\n";
cin>>grade[2];
cout<<"请输入C++成绩\n";
cin>>grade[3];
}
void student::s()
{
cout<<"请输入姓名\n";
cin>>name;
cout<<"请输入学号\n";
cin>>num;
cout<<"请输入语文成绩\n";
cin>>grade[0];
cout<<"请输入英语成绩\n";
cin>>grade[1];
cout<<"请输入数学成绩\n";
cin>>grade[2];
cout<<"请输入C++成绩\n";
cin>>grade[3];
}
class list
{
private:
double high[5],low[5];
double totoal;
student *last,*first;
public:
list(){last=0;first=0;totoal=0;};//定义初始值为0
~list();//声明析构函数
void instu();
void outstu(char *);
int delstu(char *n);
void think();
void search(char s[10]);
double hi(int i);
double lo(int i);
void av(int i);
void ev(int i);
};
list::~list()//定义析构函数
{
if(first!=0)
{
student *p=first,*temp;
while(p!=0)
{
temp=p;
p=p->next;
delete temp;
cout<<"ok\n";
}
}
}
void list::instu()
{ student *p=new student();
p->s();
if(first==0){first=last=p;}else{last->next=p;last=p;}
totoal++;
}

void list::outstu(char *n)
{
student *temp=first;for(;temp!=NULL;temp=temp->next)
if(strcmp(temp->outname(),n)==0)
{ cout<<"姓名 语文 英语 数学 C++ \n ";
cout<<temp->outname()<<" "<<temp->outgrade(0)<<" "<<temp->outgrade(1)<<
" "<<temp->outgrade(2)<<" "<<temp->outgrade(3);}


}
int list::delstu(char *n)
{
student *temp=first,*p;if(strcmp(first->outname(),n)==0)
{ first->next=first;delete temp;}
else if(temp->next!=0)
{if(strcmp(temp->next->outname(),n)==0)
{p=temp->next;temp->next=temp->next->next;delete p;}
else temp=temp->next;}
totoal--;
cout<<"\n删除成功\n";
return 0;
}
void list::think()
{
cout<<"人数"<<totoal<<endl;
cout<<" 语文 、\n";
cout<<"最高分"<<hi(0)<<"最低分"<<lo(0)<<"";
av(0);
ev(0);
cout<<"英语\n";
cout<<"最高分"<<hi(1)<<"最低分"<<lo(1);
av(1);
ev(1);
cout<<"数学、\n";
cout<<"最高分"<<hi(2)<<"最低分"<<lo(2);
av(2);
ev(2);
cout<<"C++";
cout<<"最高分"<<hi(3)<<"最低分"<<lo(3);
av(3);
ev(3);
}

double list::hi(int i)//定义hi(int i)
{
high[i]=0.00;
student *temp=first;
if(temp!=0)
{if(temp->outgrade(i)>high[i])
high[i]=temp->outgrade(i);
temp=temp->next;
}
return high[i];
}

double list::lo(int i)//定义lo(int)
{
low[i]=100;
student *temp=first;if(temp!=0)
{if(temp->outgrade(i)<low[i])
low[i]=temp->outgrade(i);
temp=temp->next;
}
return low[i];
}
void list::av(int i)//定义av(int i )
{ double aver=0;
student *temp=first;if(temp!=0)
{aver+=temp->outgrade(i);
temp=temp->next;
}
cout<<aver/totoal<<endl;

}
void list::ev(int i)//定义ev(int i)
{ int a=0,b=0,c=0,d=0,e=0,f=0;
student *temp=first;if(temp!=0)
{switch((int)temp->outgrade(i)/10)
{
case 10:a++;break;case 9:a++;break;
case 8:b++;break;case 7:c++;break;
case 6:d++;break;case 5:e++;break;
default:f++;
}
temp=temp->next;
}
cout<<"100-90、"<<a<<"89-80、"<<b<<"79-70、"<<c
<<"69-60、"<<e<<"59-50、"<<"50以下"<<f
<<"及格"<<(a+b+c+d)/(a+b+c+d+e+f)*100<<'%'<<endl;
}

void list::search(char s[10])
{
student *temp=first;for(;temp!=NULL;temp=temp->next)
if(strcmp(temp->outname(),s)==0)temp->intgrade();
}

#endif

void main()
{
list will;
int m=0;
do{
cout<<" 学 生 成 绩 管 理 系 统\n";
cout<<" ┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓\n"
<<" ┃录 入 成 绩 ┇ 请 按 1 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃查 询 成 绩 ┇ 请 按 2 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃修 改 成 绩 ┇ 请 按 3 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃删 除 成 绩 ┇ 请 按 4 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃分 析 成 绩 ┇ 请 按 5 并 确 定 ! ┃\n"
<<" ┣┅┅┅┅┅┅┅┅┅┅┅╇┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┫\n"
<<" ┃各分数段人数和及格率 ┇ 请 按 6 并 确 定 ! ┃\n"
<<" ┗━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┛\n";
cin>>m;
switch(m)
{
case 1:
will.instu();
break;
case 2:
char n[9];
cout<<"请输入姓名\n";
cin>>n;
will.outstu(n);
cout<<"\n";
break;
case 3:
char nb[9];
cout<<"请输入姓名\n";
cin>>nb;
will.outstu(nb);
cout<<"\n";
will.search(nb);

break;
case 4:
char naa[9];
cout<<"请输入姓名\n";
cin>>naa;
will.outstu(naa);
will.delstu(naa);
break;


case 5:
will.think();
break;
}
cout<<"1,继续2,退出\n";
cin>>m;
}
while(m==1);
}

搜索更多相关主题的帖子: private include friend 
2007-06-28 19:55
快速回复:[求助]详细分析一下这个VC++程序
数据加载中...
 
   



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

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