#include <iostream.h>
#include <string.h>
#include <windows.h>
using namespace std;
#define RIGHT 1
class Student
{
public:
Student();
void show();
void write_in();
friend void shownum(Student &);
static int number;
friend string returnname(Student &);
friend string returnno(Student &);
private:
string Name;
string No;
int Age;
string Sex;
};
Student::Student()
{
}
void Student::show()//打印学生信息
{
cout<<Name<<"\t"<<No<<"\t"<<Age<<"\t"<<Sex<<endl;
}
void Student::write_in()//输入学生信息
{
cout<<"please write in:"<<endl;
cout<<"name:";
cin>>Name;
cout<<"no:";
cin>>No;
cout<<"age:";
cin>>Age;
cout<<"sex:";
cin>>Sex;
number++;
}
void shownum(Student &s)//打印目前学生人数
{
cout<<"目前学生总人数为:"<<s.number<<endl;
}
int Student::number=0;
string returnname (Student &s)
{
return s.Name;
}
string returnno (Student &s)
{
return s.No;
}
class Score
{
public:
Score();
void show(Score &);
void write_in();
friend double ave(Score &);
friend void Change(Score &);
private:
int Math;
int English;
int C;
int Chinese;
};
Score::Score()
{
Math=0;English=0;C=0;Chinese=0;
}
void Score::show(Score &c)//打印学生成绩
{
double ave=(Math+English+C+Chinese)/4.0;
cout<<Math<<"\t"<<English<<"\t"<<C<<"\t"<<Chinese<<"\t"<<ave<<endl;
}
void Score::write_in()//输入学生成绩
{
cout<<"please write in:"<<endl;
cout<<"Math:";
cin>>Math;
cout<<"English:";
cin>>English;
cout<<"C:";
cin>>C;
cout<<"Chinese:";
cin>>Chinese;
}
//double ave(Score &c)//该学生的平均成绩
//{
//
c.Ave=(c.Math+c.English+c.C+c.Chinese)/4;
//
return 0;
//}
void Change(Score &s)
{
cout<<"please write in:"<<endl;
cout<<"Math:";
cin>>s.Math;
cout<<"English:";
cin>>s.English;
cout<<"C:";
cin>>s.C;
cout<<"Chinese:";
cin>>s.Chinese;
}
class Operate//操作(对学生各门课程成绩的增、删、改、查)
{
public:
Operate()
{}
void add(Student &stu,Score &sco);
void deletesco(Student &stu,Score &sco,int );
void change(Score &sco);
void check(Student stu,Score sco);
private:
Student stu;
Score sco;
};
void Operate::add(Student &stu,Score &sco)//添加学生
{
stu.write_in();
sco.write_in();
}
void Operate::deletesco(Student &stu,Score &sco,int i)//删除学生
{
Student *s;
Score *sc;
s=new Student[stu.number];
sc=new Score[stu.number];
cout<<"删除学生信息为:"<<endl;
cout<<"Name"<<"\t"<<"No"<<"\t"<<"Age"<<"\t"<<"Sex"<<endl;
stu.show();
cout<<"Math"<<"\t"<<"English"<<"\t"<<"C"<<"\t"<<"Chinese"<<"\t"<<"Ave"<<endl;
sco.show(sco);
for (i;i<stu.number;i++)
{
s[i]=s[i+1];
sc[i]=sc[i+1];
}
s[i-1].number--;
}
void Operate::change(Score &sco)//修改学生成绩。
{
cout<<"当前学生成绩为:"<<endl;
cout<<"Math"<<"\t"<<"English"<<"\t"<<"C"<<"\t"<<"Chinese"<<"\t"<<"Ave"<<endl;
sco.show(sco);
Change(sco);
}
void Operate::check(Student stu,Score sco)//查找学生
{
cout<<"Name"<<"\t"<<"No"<<"\t"<<"Age"<<"\t"<<"Sex"<<endl;
stu.show();
cout<<"Math"<<"\t"<<"English"<<"\t"<<"C"<<"\t"<<"Chinese"<<"\t"<<"Ave"<<endl;
sco.show(sco);
}
int main ()
{
int n=0;//n用来做数组下标。
Student stu[10];
Score sco[10];
int i=1;
int j,k=0;
string c;
string ch;
Operate ope;
while (i)
{
system("cls");
cout <<"******************欢迎进入学生成绩管理系统******************"<<endl;
cout <<"-----------------------------------------------------------"<<endl;
cout<<"******************
录入学生信息和成绩:1
******************"<<endl;
cout<<"******************
按学号查询学生的信息:2 ******************"<<endl;
cout<<"******************
按名字查询学生的信息:3 ******************"<<endl;
cout<<"******************
按学号删除学生的信息:4 ******************"<<endl;
cout<<"******************
按名字删除学生的信息:5 ******************"<<endl;
cout<<"******************
按学号修改学生的信息:6 ******************"<<endl;
cout<<"******************
按名字修改学生的信息:7 ******************"<<endl;
cout<<"******************
查询当前总学生的情况:8 ******************"<<endl;
cout<<"******************
退出该系统请按:
0 ******************"<<endl;
cout <<"-----------------------------------------------------------"<<endl;
cin>>j;
//getchar();
switch (j)
{
case 1:
//录入学生信息和成绩:1
ope.add(stu[n],sco[n]);
n++;
break;
case 2://按学号查询学生的信息:2
cout<<"请输入学生学号:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnno(stu[k]);
if (c==ch)
{
cout<<"该学生的信息为:"<<endl;
ope.check(stu[k],sco[k]);
goto tt;
}
if (k==n-1&&c!=returnno(stu[k]))
{
cout<<"输入该学号错误"<<endl;
}
}
getchar();
break;
case 3://按名字查询学生的信息:3
cout<<"请输入学生名字:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnname(stu[k]);
if (c==ch){
cout<<"该学生的信息为:"<<endl;
ope.check(stu[k],sco[k]);
goto tt;}
if (k==n-1&&c!=ch)
{
cout<<"输入该名字错误"<<endl;
}
}
getchar();
break;
case 4:// 按学号删除学生的信息:4
cout<<"请输入学生学号:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnno( stu[k]);
if (c==ch){
ope.deletesco(stu[k],sco[k],k);
goto tt;}
if (k==n-1&&c!=ch)
{
cout<<"输入该学号错误"<<endl;
}
}
getchar();
break;
case 5://按名字删除学生的信息:5
cout<<"请输入学生名字:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnname(stu[k]);
if (c==ch){
ope.deletesco(stu[k],sco[k],k);
goto tt;}
if (k==n-1&&c!=ch)
{
cout<<"输入该名字错误"<<endl;
}
}
getchar();
break;
case 6://按学号修改学生的信息:6
cout<<"请输入学生学号:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnno( stu[k]);
if (c==ch){
ope.change(sco[k]);
goto tt ;}
if (k==n-1&&c!=ch)
{
cout<<"输入该学号错误"<<endl;
}
}
getchar();
break;
case 7://按名字修改学生的信息:7
cout<<"请输入学生名字:"<<endl;
cin >>c;
for (k=0;k<n;k++)
{
ch=returnname(stu[k]);
if (c==ch){
ope.change(sco[k]);
goto tt;}
if (k==n-1&&c!=ch)
{
cout<<"输入该名字错误"<<endl;
}
}
getchar();
break;
case 8://查询当前总学生情况8。
shownum(stu[0]);
for (k=0;k<n;k++)
{
ope.check(stu[k],sco[k]);
}
getchar();
break;
case 0:
return -1;
}
tt:getchar();
getchar();
}
return 0;
}
这里有一个程序是从论坛里找的(有问题,但大神可以根据这个来修改),我用winTC说#include <iostream.h>和#include <windows.h>
有错误,不知道为什么