#include <iostream.h>
#include <string>
class Student
{
char *name;
double x,y;//随堂考试成绩
double m,n,f;//期中考试成绩、期末考试成绩和总评成绩
char g;//等级
public:
Student();
void Input();
double Output();
double Evaluate();
void Alter();
};
Student::Student()
{
g='B';
}
void Student::Input()
{
char a[20];
double b,c,d,e;
cout<<"请输入姓名:";
cin>>a;
strcpy(name,a);
do
{cout<<"请输入第一次随堂考试成绩:";
cin>>b;
}while(b<0||b>10);
x=b;
do
{cout<<"请输入第二次随堂考试成绩:";
cin>>c;
}while(c<0||c>10);
y=c;
do
{cout<<"请输入期中考试成绩:";
cin>>d;
}while(d<0||d>100);
m=d;
do
{cout<<"请输入期末考试成绩:";
cin>>e;
}while(e<0||e>100);
n=e;
}
double Student::Output()
{
cout<<"姓名:"<<*name<<endl;
cout<<"第一次随堂考试成绩:"<<x<<endl;
cout<<"第二次随堂考试成绩:"<<y<<endl;
cout<<"期中考试成绩:"<<m<<endl;
cout<<"期末考试成绩:"<<n<<endl;
cout<<"总评成绩:"<<f<<endl;
cout<<"等级:"<<g<<endl;
return 0;
}
double Student::Evaluate()
{
f=(n*0.5)+(m*0.25)+((x+y)*0.25);
if(f<=100&&f>=90)g='A';
if(f<=89&&f>=80)g='B';
if(f<=79&&f>=70)g='C';
if(f<=69&&f>=60)g='D';
if(f<60&&f>=0)g='E';
return 0;
}
void Student::Alter()
{
char a[20];
double b,c,d,e;
cout<<"请输入姓名:";
cin>>a;
strcpy(name,a);
do
{cout<<"请输入第一次随堂考试成绩:";
cin>>b;
}while(b<0||b>10);
x=b;
do
{cout<<"请输入第二次随堂考试成绩:";
cin>>c;
}while(c<0||c>10);
y=c;
do
{cout<<"请输入期中考试成绩:";
cin>>d;
}while(d<0||d>100);
m=d;
do
{cout<<"请输入期末考试成绩:";
cin>>e;
}while(e<0||e>100);
n=e;
}
int main()
{
Student Array[5];
Student input(Student *);
void alter(Student *);
int p;
do
{cout<<"输入学生成绩——1"<<endl<<"修改学生成绩——2"<<endl;
cin>>p;
switch(p)
{
case 1:input(Array);
break;
case 2:alter(Array);
break;
}while(p!=2);
return 0;
}
char* input(Student *Array)
{
int i;
for(i=0;i=5;i++)
{
Array[i].Input();
Array[i].Evaluate();
}
for(i=0;i<5;i++)
Array[i].Output();
return 0;
}
void alter(Student *Array)
{
int i;
cout<<"请输入要修改的学生序号:";
cin>>i;
cout>>Array[i];
Array[i].Alter;
cout>>Array[i].Output;
}
#include <string>
class Student
{
char *name;
double x,y;//随堂考试成绩
double m,n,f;//期中考试成绩、期末考试成绩和总评成绩
char g;//等级
public:
Student();
void Input();
double Output();
double Evaluate();
void Alter();
};
Student::Student()
{
g='B';
}
void Student::Input()
{
char a[20];
double b,c,d,e;
cout<<"请输入姓名:";
cin>>a;
strcpy(name,a);
do
{cout<<"请输入第一次随堂考试成绩:";
cin>>b;
}while(b<0||b>10);
x=b;
do
{cout<<"请输入第二次随堂考试成绩:";
cin>>c;
}while(c<0||c>10);
y=c;
do
{cout<<"请输入期中考试成绩:";
cin>>d;
}while(d<0||d>100);
m=d;
do
{cout<<"请输入期末考试成绩:";
cin>>e;
}while(e<0||e>100);
n=e;
}
double Student::Output()
{
cout<<"姓名:"<<*name<<endl;
cout<<"第一次随堂考试成绩:"<<x<<endl;
cout<<"第二次随堂考试成绩:"<<y<<endl;
cout<<"期中考试成绩:"<<m<<endl;
cout<<"期末考试成绩:"<<n<<endl;
cout<<"总评成绩:"<<f<<endl;
cout<<"等级:"<<g<<endl;
return 0;
}
double Student::Evaluate()
{
f=(n*0.5)+(m*0.25)+((x+y)*0.25);
if(f<=100&&f>=90)g='A';
if(f<=89&&f>=80)g='B';
if(f<=79&&f>=70)g='C';
if(f<=69&&f>=60)g='D';
if(f<60&&f>=0)g='E';
return 0;
}
void Student::Alter()
{
char a[20];
double b,c,d,e;
cout<<"请输入姓名:";
cin>>a;
strcpy(name,a);
do
{cout<<"请输入第一次随堂考试成绩:";
cin>>b;
}while(b<0||b>10);
x=b;
do
{cout<<"请输入第二次随堂考试成绩:";
cin>>c;
}while(c<0||c>10);
y=c;
do
{cout<<"请输入期中考试成绩:";
cin>>d;
}while(d<0||d>100);
m=d;
do
{cout<<"请输入期末考试成绩:";
cin>>e;
}while(e<0||e>100);
n=e;
}
int main()
{
Student Array[5];
Student input(Student *);
void alter(Student *);
int p;
do
{cout<<"输入学生成绩——1"<<endl<<"修改学生成绩——2"<<endl;
cin>>p;
switch(p)
{
case 1:input(Array);
break;
case 2:alter(Array);
break;
}while(p!=2);
return 0;
}
char* input(Student *Array)
{
int i;
for(i=0;i=5;i++)
{
Array[i].Input();
Array[i].Evaluate();
}
for(i=0;i<5;i++)
Array[i].Output();
return 0;
}
void alter(Student *Array)
{
int i;
cout<<"请输入要修改的学生序号:";
cin>>i;
cout>>Array[i];
Array[i].Alter;
cout>>Array[i].Output;
}
错误:
C:\Users\10055\Desktop\Cpp2.cpp(116) : error C2062: type 'char' unexpected
C:\Users\10055\Desktop\Cpp2.cpp(117) : error C2143: syntax error : missing ';' before '{'
C:\Users\10055\Desktop\Cpp2.cpp(129) : error C2601: 'alter' : local function definitions are illegal
C:\Users\10055\Desktop\Cpp2.cpp(137) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
C:\Users\10055\Desktop\Cpp2.cpp(117) : error C2143: syntax error : missing ';' before '{'
C:\Users\10055\Desktop\Cpp2.cpp(129) : error C2601: 'alter' : local function definitions are illegal
C:\Users\10055\Desktop\Cpp2.cpp(137) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.