主题:路过的朋友,进来下。帮忙修改下程序错误!!谢谢,谢谢!!
谢谢 雪光风剑 大哥的指点,谢谢!
调试没问题了,测试也成功了。谢谢!!!![em8][em8][em8]
[code=c]
/********************************************************************
created: 2010/03/11
created: 11:3:2010 19:12
filename: 3.2.cpp
file path: ..\P86
file base: 3.2
file ext: cpp
author: FengGuy
purpose: 用数组编写学生成绩系统
*********************************************************************/
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
struct data
{
int no;
char name[6];
float chinese;
float english;
float math;
};
struct structlist
{
data student[10];
int LastPoint;//用于存放数组成员的总数
} list;
/************************************************************************/
/* 输入姓名,删除成绩 */
/************************************************************************/
int deldata(structlist& nlist)
{
int i=0;
int j=0;
int temp=0;
char inputname[6];
cout<<"Please Input Student's Name:";
cin>>inputname;
for (i=0; i<nlist.LastPoint; i++)
{
if (strcmp(nlist.student[i].name,inputname)==0)//判断是否和输入名字相同
{
for (j=i; j<=i; j++)
{
nlist.student[j].no=nlist.student[j+1].no;//用后一个数据覆盖前一个数据
strcpy(nlist.student[j].name,nlist.student[j+1].name);
nlist.student[j].chinese=nlist.student[j+1].chinese;
nlist.student[j].english=nlist.student[j+1].english;
nlist.student[j].math=nlist.student[j+1].math;
}
list.LastPoint--;//删除后,数组最后标记自减一
cout<<"Success!";
return 1;
}
}
return 0;
}
int print(structlist& nlist)
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;
for (int i=0; i<nlist.LastPoint; i++)
{
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
}
return 1;
}
/************************************************************************/
/* 通过输入的姓名修改成绩 */
/************************************************************************/
int Modify(structlist& nlist)
{
char inputname[6];
float english;
float chinese;
float math;
cout<<"Plesse Input Student's Name:";
cin>>inputname;
for (int i=0; i<=nlist.LastPoint; i++)
{
if (strcmp(nlist.student[i].name,inputname)==0)//判断是否和输入名字相同
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;//输出找到的相应数据
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
cout<<"Please Input Student's Chinese Score:";//等待用户输入并修改数据
cin>>chinese;
cout<<"Please Input Student's English Score:";
cin>>english;
cout<<"Please Input Student's Math Score:";
cin>>math;
nlist.student[i].chinese=chinese;
nlist.student[i].english=english;
nlist.student[i].math=math;
cout<<"Success!";
return 1;
}
}
return 0;
}
/************************************************************************/
/* 通过查找姓名,查询成绩 */
/************************************************************************/
int locate(structlist &nlist)
{
char inputname[6];
cout<<"Plesse Input Student's Name:";
cin>>inputname;
for (int i=0; i<=nlist.LastPoint; i++)//遍历数组并输出
{
if (strcmp(nlist.student[i].name,inputname)==0)
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
return 1;
}
}
return 0;
}
/************************************************************************/
/* 添加成绩 */
/************************************************************************/
int append(structlist& nlist)
{
float chinese;
float english;
float math;
char name[6];
int no;
cout<<"Please Input No:";//等待用户输入,并添加数据
cin>>no;
cout<<"\nPlease Input Name:";
cin>>name;
cout<<"\nPlease Input Chinese Score:";
cin>>chinese;
cout<<"\nPlease Input Enlish Score:";
cin>>english;
cout<<"\nPlease Input Math Score:";
cin>>math;
nlist.student[nlist.LastPoint].no=no;
strcpy(nlist.student[nlist.LastPoint].name,name);
nlist.student[nlist.LastPoint].chinese=chinese;
nlist.student[nlist.LastPoint].english=english;
nlist.student[nlist.LastPoint].math=math;
nlist.LastPoint++;
return 1;
}
/************************************************************************/
/* 全班平均成绩 */
/************************************************************************/
int average(structlist &nlist)
{
int i=0;
float totalChin=0;
float totalEng=0;
float totalMat=0;
for (i=0; i<nlist.LastPoint; i++)//遍历数组,求出各科成绩的和
{
totalChin =totalChin+ nlist.student[i].chinese;
totalEng =totalEng+ nlist.student[i].english;
totalMat =totalMat+ nlist.student[i].math;
}
cout<<"Average Chinese Score:"<< totalChin/nlist.LastPoint
<<"\nAverage English Score:"<<totalEng/nlist.LastPoint
<<"\nAverage Math Score:"<<totalMat/nlist.LastPoint
<<endl;
return 1;
}
/************************************************************************/
/* 主函数 */
/************************************************************************/
int main()
{
structlist list;
list.LastPoint=0;
int choose;
while (1)
{
cout<<"-----Choose:-----\n"
<<"1.Append\n"
<<"2.Locate\n"
<<"3.Modify\n"
<<"4.Delete\n"
<<"5.Average Score\n"
<<"6.Print All\n"
<<"------------------\n"
<<"0.EXIT"<<endl;
cin>>choose;
switch(choose)
{
case 1: append(list);
break;
case 2:locate(list);
break;
case 3:Modify(list);
break;
case 4:deldata(list);
break;
case 5:average(list);
break;
case 6:print(list);
break;
case 0: exit(1);
break;
default:
break;
}
}
return 1;
}
[/code]
调试没问题了,测试也成功了。谢谢!!!![em8][em8][em8]
[code=c]
/********************************************************************
created: 2010/03/11
created: 11:3:2010 19:12
filename: 3.2.cpp
file path: ..\P86
file base: 3.2
file ext: cpp
author: FengGuy
purpose: 用数组编写学生成绩系统
*********************************************************************/
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
struct data
{
int no;
char name[6];
float chinese;
float english;
float math;
};
struct structlist
{
data student[10];
int LastPoint;//用于存放数组成员的总数
} list;
/************************************************************************/
/* 输入姓名,删除成绩 */
/************************************************************************/
int deldata(structlist& nlist)
{
int i=0;
int j=0;
int temp=0;
char inputname[6];
cout<<"Please Input Student's Name:";
cin>>inputname;
for (i=0; i<nlist.LastPoint; i++)
{
if (strcmp(nlist.student[i].name,inputname)==0)//判断是否和输入名字相同
{
for (j=i; j<=i; j++)
{
nlist.student[j].no=nlist.student[j+1].no;//用后一个数据覆盖前一个数据
strcpy(nlist.student[j].name,nlist.student[j+1].name);
nlist.student[j].chinese=nlist.student[j+1].chinese;
nlist.student[j].english=nlist.student[j+1].english;
nlist.student[j].math=nlist.student[j+1].math;
}
list.LastPoint--;//删除后,数组最后标记自减一
cout<<"Success!";
return 1;
}
}
return 0;
}
int print(structlist& nlist)
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;
for (int i=0; i<nlist.LastPoint; i++)
{
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
}
return 1;
}
/************************************************************************/
/* 通过输入的姓名修改成绩 */
/************************************************************************/
int Modify(structlist& nlist)
{
char inputname[6];
float english;
float chinese;
float math;
cout<<"Plesse Input Student's Name:";
cin>>inputname;
for (int i=0; i<=nlist.LastPoint; i++)
{
if (strcmp(nlist.student[i].name,inputname)==0)//判断是否和输入名字相同
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;//输出找到的相应数据
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
cout<<"Please Input Student's Chinese Score:";//等待用户输入并修改数据
cin>>chinese;
cout<<"Please Input Student's English Score:";
cin>>english;
cout<<"Please Input Student's Math Score:";
cin>>math;
nlist.student[i].chinese=chinese;
nlist.student[i].english=english;
nlist.student[i].math=math;
cout<<"Success!";
return 1;
}
}
return 0;
}
/************************************************************************/
/* 通过查找姓名,查询成绩 */
/************************************************************************/
int locate(structlist &nlist)
{
char inputname[6];
cout<<"Plesse Input Student's Name:";
cin>>inputname;
for (int i=0; i<=nlist.LastPoint; i++)//遍历数组并输出
{
if (strcmp(nlist.student[i].name,inputname)==0)
{
cout<<"No\t"<<"Name\t"<<"Chinese\t"<<"Enlist\t"<<"Math\t"<<endl;
cout<<nlist.student[i].no<<"\t"
<<nlist.student[i].name<<"\t"
<<nlist.student[i].chinese<<"\t"
<<nlist.student[i].english<<"\t"
<<nlist.student[i].math<<endl;
return 1;
}
}
return 0;
}
/************************************************************************/
/* 添加成绩 */
/************************************************************************/
int append(structlist& nlist)
{
float chinese;
float english;
float math;
char name[6];
int no;
cout<<"Please Input No:";//等待用户输入,并添加数据
cin>>no;
cout<<"\nPlease Input Name:";
cin>>name;
cout<<"\nPlease Input Chinese Score:";
cin>>chinese;
cout<<"\nPlease Input Enlish Score:";
cin>>english;
cout<<"\nPlease Input Math Score:";
cin>>math;
nlist.student[nlist.LastPoint].no=no;
strcpy(nlist.student[nlist.LastPoint].name,name);
nlist.student[nlist.LastPoint].chinese=chinese;
nlist.student[nlist.LastPoint].english=english;
nlist.student[nlist.LastPoint].math=math;
nlist.LastPoint++;
return 1;
}
/************************************************************************/
/* 全班平均成绩 */
/************************************************************************/
int average(structlist &nlist)
{
int i=0;
float totalChin=0;
float totalEng=0;
float totalMat=0;
for (i=0; i<nlist.LastPoint; i++)//遍历数组,求出各科成绩的和
{
totalChin =totalChin+ nlist.student[i].chinese;
totalEng =totalEng+ nlist.student[i].english;
totalMat =totalMat+ nlist.student[i].math;
}
cout<<"Average Chinese Score:"<< totalChin/nlist.LastPoint
<<"\nAverage English Score:"<<totalEng/nlist.LastPoint
<<"\nAverage Math Score:"<<totalMat/nlist.LastPoint
<<endl;
return 1;
}
/************************************************************************/
/* 主函数 */
/************************************************************************/
int main()
{
structlist list;
list.LastPoint=0;
int choose;
while (1)
{
cout<<"-----Choose:-----\n"
<<"1.Append\n"
<<"2.Locate\n"
<<"3.Modify\n"
<<"4.Delete\n"
<<"5.Average Score\n"
<<"6.Print All\n"
<<"------------------\n"
<<"0.EXIT"<<endl;
cin>>choose;
switch(choose)
{
case 1: append(list);
break;
case 2:locate(list);
break;
case 3:Modify(list);
break;
case 4:deldata(list);
break;
case 5:average(list);
break;
case 6:print(list);
break;
case 0: exit(1);
break;
default:
break;
}
}
return 1;
}
[/code]

您所在位置:
