c++怎么保存输入的信息?

2025-04-10 01:18:07
推荐回答(1个)
回答1:

#include
#include
struct node
{ float no;
char name[8];
float cj1;
float cj2;
float cj3;
float zf;
float pj;
node *next; };
node *student,*top,*head;
node *Create(node *student)
{ node *Ttemp;
char Tname[8];float Tcj1,Tcj2,Tcj3,Tno,Tmake=1;
student=new node;
student->next=NULL;head=top=student;
cout<<"输入学号,姓名,成绩1,成绩2,成绩3,成绩4\n";
while (Tmake)
{ cout<<"学号:";cin>>Tno;cout<<"姓名:";cin>>Tname;cout<<"成绩1:";cin>>Tcj1;
cout<<"成绩2:";cin>>Tcj2;cout<<"成绩3:";cin>>Tcj3;cout<cout<<"是否继续添加学生('0'结束 '1'继续)";cin>>Tmake;
Ttemp=new node;
Ttemp->no=Tno;
strcpy(Ttemp->name,Tname);
Ttemp->cj1=Tcj1;Ttemp->cj2=Tcj2;Ttemp->cj3=Tcj3;
Ttemp->next=NULL;
top->next=Ttemp;top=Ttemp; }
return student; }
void Chang()
{ node *total=head;
while(total->next!=NULL)
{ total->next->zf=total->next->cj1+total->next->cj2+total->next->cj3;
total->next->pj=total->next->zf/3;total=total->next; }
}
void Append()
{ char Aname[8];float Acj1,Acj2,Acj3,Ano;
node *Atemp=new node;
cout<<"学号:";cin>>Ano;cout<<"姓名:";cin>>Aname;cout<<"成绩1:";cin>>Acj1;
cout<<"成绩2:";cin>>Acj2;cout<<"成绩3:";cin>>Acj3;cout<Atemp=new node;Atemp->no=Ano;
strcpy(Atemp->name,Aname);
Atemp->cj1=Acj1;Atemp->cj2=Acj2;Atemp->cj3=Acj3;
Atemp->next=NULL;
top->next=Atemp;top=Atemp; }
void Delete()
{ if (head==NULL)
{
cout<<"数据为空无法操作!请先输入数据!\n";
return; }
node *Dlast;node *Dhead=head;
int Dmake;cout<<"选择按类型删除('0'学号,其他姓名):";
cin>>Dmake;
if(Dmake==0)
{ cout<<"请输入要删除的学号:"; int Dno;cin>>Dno;
Dlast=Dhead->next;
while (Dlast!=NULL&&Dlast->no!=Dno)
{ Dhead=Dlast;
Dlast=Dlast->next; }
if(Dlast!=NULL)
{ Dhead->next=Dlast->next;
delete Dlast;cout<<"删除成功!"<else cout<<"数据中没有您要删除的值!删除失败!\n"; }
else

jykf4614
采纳率:40% 11级 2013.07.05
补充下 cout<next->no<<" "<next->name<<" "<next->cj1<<" "<next->cj2<<" ";
cout<next->cj3<<" "<next->pj<<" "<next->zf<}
else cout<<"数据中没有您要查找的数据!\n";
}
}

void Count()
{
Chang();
float cj1total(0),cj2total(0),cj3total(0),zftotal(0);
int y=1;
node *Chead=head;
while(Chead->next!=NULL)
{
cj1total+=Chead->next->cj1;cj2total+=Chead->next->cj2;cj3total+=Chead->next->cj3;
zftotal+=Chead->next->zf; Chead=Chead->next;y++;
}
node *Ctemp=new node;
Ctemp->cj1=cj1total/y;Ctemp->cj2=cj2total/y;Ctemp->cj3=cj3total/y;Ctemp->no=0;Ctemp->pj=0;
strcpy(Ctemp->name,"平均分");
Ctemp->zf=zftotal/y;
Ctemp->next=NULL;
Chead->next=Ctemp;

}

void Show()
{
if (head==NULL)
{
cout<<"数据为空无法操作!请先输入数据!\n";
return;
}
node *l=head;
while (l->next!=NULL)
{
cout<next->no<<" "<next->name<<" "<next->cj1<<" "<next->cj2<<" "<next->cj3<<" "<next->pj<<" "<next->zf<l=l->next;
}
}
void ShowMain()
{
cout<<"\t << C++ 课程设计 >> 制作人员:"<cout<<"\t *********************交大理工学生成绩管理系统********************* "<cout<<"\t (1) ********创建学生成绩信息*******"<cout<<"\t (2) ********修改学生成绩********"<cout<<"\t (3) ********追加记录********"<cout<<"\t (4) ********删除记录 ********"<cout<<"\t (5) ********查找学生成绩********"<cout<<"\t (6) ********统计学生成绩v"<cout<<"\t (7) ********显示目前数据 ********"<cout<<"\t (8) ********退出系统******** "<
}

void main()
{

int MakePoint=1,SelectNumber;
while (MakePoint)
{
ShowMain();
cout<<"\t请选择操作:";
cin>>SelectNumber;
switch (SelectNumber)
{
case 1:
Create(student);
break;
case 2:
Chang();
break;
case 3:
Append();
break;
case 4:
Delete();
break;
case 5:
Find();
break;
case 6:
Count();
break;
case 7:
Show();
break;
case 8:
MakePoint=0;
break;
}
}
}