高分悬赏:请高手看一下啊!分析一段C++程序~~谢谢~~

由于程序太长了,字符数限制,所以无法全部粘贴出来,如果有意愿帮我分析一下啊!可以告诉我你的邮箱地址,我可以发给你,麻烦帮看看哦!谢谢诶~~回复完了可以将分析结果发到我的邮... 由于程序太长了,字符数限制,所以无法全部粘贴出来,如果有意愿帮我分析一下啊!可以告诉我你的邮箱地址,我可以发给你,麻烦帮看看哦!
谢谢诶~~
回复完了可以将分析结果发到我的邮箱524214757@163.com
我将会追加更多的分
谢谢
展开
 我来答
高金山
2008-11-12 · TA获得超过1万个赞
知道大有可为答主
回答量:4101
采纳率:0%
帮助的人:1700万
展开全部
我帮楼主公布下,代码是这样的:
(这段代码写的很好啊,运行起来很正常)

#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
using namespace std;
class CData
{
public:
CData(){};
virtual int comparename(CData &) =0;
virtual void show()=0;
virtual ~CData(){};
};
class CNode
{
public:
CNode(){pdata=0;pnext=0;}
CNode(CNode &n);
void inputdata(CData *pd){pdata=pd;}
void shownode(){pdata->show();}
CData *getdata(){return pdata;}
friend class CList;
private:
CData *pdata;
CNode *pnext;
};
CNode::CNode(CNode &n)
{
pdata=n.pdata;
pnext=n.pnext;
}

class CList
{
public:
CList(){phead=0;}
~CList(){deletelist();}
void addnode(CNode *pnode);
void deletelist();
CNode *deletenode(CNode *pnode);
CNode *lookup(CData &data);
CNode *getlisthead(){return phead;}
void showlist();
CNode *getnext(CNode *pnode);
private:
CNode * phead;
};
void CList::addnode(CNode *pnode)
{
if(phead==0)
{
phead=pnode;
pnode->pnext=0;
return;
}
else
{
pnode->pnext=phead;
phead=pnode;
}
}
void CList::deletelist()
{
CNode *p1,*p2;
p1=phead;
while(p1)
{
delete p1->pdata;
p2=p1;
p1=p1->pnext;
delete p2;
}
}
CNode *CList::deletenode(CNode *pnode)
{
CNode *p1,*p2;
p1=phead;
while(p1!=pnode&&p1->pnext!=0)
{
p2=p1;
p1=p1->pnext;
}
if(p1==phead)
{
phead=phead->pnext;
return pnode;
}
p2->pnext=p1->pnext;
return pnode;
}
CNode *CList::lookup(CData &data)
{
CNode *p1=phead;
while(p1)
{
if(p1->pdata->comparename(data)==0)
return p1;
p1=p1->pnext;
}
return 0;
}
void CList::showlist()
{
if(phead==0)
cout<<"对不起,没有任何记录.\n";
else
{
CNode *p=phead;
while(p)
{
p->pdata->show();
p=p->pnext;
}
}
}
CNode *CList::getnext(CNode *pnode)
{
CNode *p=pnode;
p=p->pnext;
return p;
}
class Student:public CData
{
private:
char s_class[17];
char s_num[17];
char s_name[17];
double ele_technique;
double c_program;
double mul_technique;
double col_english;
double sen_math;
double col_gym;
double marx_economy;
double average;
public:
Student();
virtual int comparename(CData &);
void show();
void set(char *c,char*n,char *nam,double e,double cp,
double m,double ce,double sm,double cg,double mar,double aver);
};
Student::Student()
{
strcpy(s_class,"\0");
strcpy(s_num,"\0");
strcpy(s_name,"\0");
ele_technique=0;
c_program=0;
mul_technique=0;
col_english=0;
sen_math=0;
col_gym=0;
marx_economy=0;
}
int Student::comparename(CData &data)
{
Student &temp=(Student &)data;
return strcmp(s_name,temp.s_name);
}
void Student::show()
{
cout<<setw(7)<<s_class<<setw(12)<<s_num<<setw(12)<<s_name;
cout<<setw(6)<<ele_technique<<setw(6)<<c_program<<setw(6)<<mul_technique;
cout<<setw(6)<<col_english<<setw(6)<<sen_math<<setw(6)<<col_gym;
cout<<setw(6)<<marx_economy<<" "<<setw(3)<<average<<endl;;
}
void Student::set(char *c,char*n,char *nam,double e,double cp,double m,double ce,double sm,double cg,double mar,double aver)

{
strcpy(s_class,c);
strcpy(s_num,n);
strcpy(s_name,nam);
ele_technique=e;
c_program=cp;
mul_technique=m;
col_english=ce;
sen_math=sm;
col_gym=cg;
marx_economy=mar;
average=aver;
}
void print()
{
cout<<setw(7)<<"class"<<setw(12)<<"number"<<setw(12)<<"name";
cout<<setw(6)<<"ele"<<setw(6)<<"C++"<<setw(6)<<"media";
cout<<setw(6)<<"eng"<<setw(6)<<"math"<<setw(6)<<"gym";
cout<<setw(6)<<"marx"<<setw(6)<<"aver"<<endl;
}
void display(CList &stulist)
{
print();
stulist.showlist();
cout<<endl;
cout<<"按任意键返回主菜单";
getchar();getchar();
}
void add(CList &stulist)
{
CNode *p;
Student *s;
char c[17],n[17],nam[17];
double e,cp,m,ce,sm,cg,mar;float aver;
cout<<"请输入姓名(输入0结束):";
cin.ignore();
cin.getline(nam,17);
while(strcmp(nam,"0"))
{
cout<<"输入学号:";cin.getline(n,17);
cout<<"输入班级:";cin.getline(c,17);
cout<<"输入大学物理成绩:";cin>>e;
cout<<"输入C++成绩:";cin>>cp;
cout<<"输入大学生心理健康成绩:";cin>>m;
cout<<"输入大学英语成绩:";cin>>ce;
cout<<"输入高等数学成绩:";cin>>sm;
cout<<"输入大学体育成绩:";cin>>cg;
cout<<"输入工程制图成绩:";cin>>mar;
aver=((e+cp+m+ce+sm)*0.8/5+cg*0.15+mar*0.05);
s=new Student;
s->set(c,n,nam,e,cp,m,ce,sm,cg,mar,aver);
p=new CNode;
p->inputdata(s);
stulist.addnode(p);
cout<<"记录添加成功."<<endl;
cout<<"请输入姓名(输入0结束):";
cin.ignore();
cin.getline(nam,17);
}
}
void lookup(CList &stulist)
{
CNode *plook;
char name[17];
cout<<"请输入你要查找的姓名(输入0结束):";
cin.ignore();
cin.getline(name,17);
while(strcmp(name,"0"))
{
Student s;
s.set("0","0",name,0,0,0,0,0,0,0,0);
plook=stulist.lookup(s);
if(plook)
{
print();
plook->shownode();
}
else
cout<<"对不起,在学生记录中查找不到"<<name<<"的记录."<<endl;
cout<<"请输入你要查找的姓名(输入0结束):";
cin.getline(name,17);
}
}
void deletes(CList &stulist)
{
CNode *plook;
char name[17];
cout<<"请输入要删除的记录的学生姓名(输入0结束):";
cin.ignore();
cin.getline(name,17);
while(strcmp(name,"0"))
{
Student s;
s.set("0","0",name,0,0,0,0,0,0,0,0);
plook=stulist.lookup(s);
if(plook)
{
print();
plook->shownode();
stulist.deletenode(plook);
cout<<name<<"的记录已经删除.\n";
}
else
cout<<"对不起,在学生记录中查找不到"<<name<<"的记录.\n"<<endl;
cout<<"请输入要删除的记录的学生姓名(输入0结束):";
cin.getline(name,17);
}
}
void storefile(CList &stulist)
{
ofstream outfile("student.dat",ios::binary);
if(!outfile)
{
cout<<"数据文件打开错误,数据存入文件失败!"<<endl;
return;
}
CNode *p;
Student *s;
p=stulist.getlisthead();
while(p)
{
s=(Student *)p->getdata();
outfile.write((char *)s,sizeof(Student));
p=stulist.getnext(p);
}
outfile.close();
}
void loadfile(CList &stulist)
{
ifstream infile("student.dat",ios::binary);
if(!infile)
{
cout<<"没有数据文件!"<<endl;
return;
}
CNode *p;
Student *s;
while(! infile.eof())
{
s=new Student;
infile.read((char *)s,sizeof(Student));
p=new CNode;
p->inputdata(s);
stulist.addnode(p);
}
stulist.deletenode(p);
infile.close();
}
void operate(CList &stulist)
{
int choice;
do
{
system("cls");
cout<<" →欢迎进入学生成绩管理系统←\n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
<<"1.输出所有学生成绩记录\n"
<<"2.增加学生成绩记录\n"
<<"3.删除学生成绩记录\n"
<<"4.查询学生成绩记录\n"
<<"0.退出学生能够成绩管理系统\n"
<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"提示:按0-4进行选择您要的服务";
cin>>choice;
cout<<endl;
switch(choice)
{case 1:display(stulist);break;
case 2:add(stulist);break;
case 3:deletes(stulist);break;
case 4:lookup(stulist);break;
case 0:storefile(stulist);break;
default:cout<<"输入错误,请重新输入您的选择:";
}
}while(choice!=0);
}
int main()
{
CList stulist;
loadfile(stulist);
operate(stulist);
cout<<"谢谢使用学生成绩管理系统,再见!";
return 0;
}
咯噢可
2008-11-10 · TA获得超过301个赞
知道小有建树答主
回答量:125
采纳率:0%
帮助的人:0
展开全部
真是搞笑
你的程序呢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
碧海a星辰
2008-11-10 · TA获得超过146个赞
知道小有建树答主
回答量:189
采纳率:0%
帮助的人:124万
展开全部
你的程序呢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
帐号已注销
2008-11-10 · TA获得超过484个赞
知道小有建树答主
回答量:527
采纳率:0%
帮助的人:322万
展开全部
你这100分看来就白丢了~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式