求C语言学习成绩管理系统源代码

2025-02-23 11:40:35
推荐回答(1个)
回答1:

这是我今天写的一部分代码,领会精神。建议做链表时先画图分析一下数据结构,你可以先看一下别人的代码,先分析别人的代码,然后试试自己编一个简单的(没有参照的编程)。看一下数据结构方面的书会对你学习链表有很大的帮助。记着要勤加练习哦!
#include
#include
#include
#include

static int n;

struct student
{
int stu_number;
char stu_name[10];
char stu_sex[4];
int stu_age;
int math;
int english;
int cplu_plus;
int total;
float average;
};

class stu
{
student boy;
public:
int getnum();
void in_put(student *p1,int num);
void in_file(struct student *p,int number);
void readout(struct student *p);
void A_caculate(struct student *p);
void T_caculate(struct student *p);
int Cacu_aver(struct student *p,int number);
int Cacu_total(struct student *p,int number);
void out_put(struct student *p);

};

void stu::in_put(student *p1,int num)
{
int i;
for (i=0;i {
cout<<"学号:"< cin>>p1[i].stu_number;
cout<<"姓名:"< cin>>p1[i].stu_name;
cout<<"性别:"< cin>>p1[i].stu_sex;
cout<<"年龄:"< cin>>p1[i].stu_age;
cout<<"数学成绩:"< cin>>p1[i].math;
cout<<"英语成绩:"< cin>>p1[i].english;
cout<<"c++成绩:"< cin>>p1[i].cplu_plus;
p1[i].total=0;
p1[i].average=0;
system("cls");
}

}

void stu::in_file(struct student *p,int number)
{
int i;
ofstream ofs("feifei.txt",ios::out);
if (!ofs)
{
cerr<<"can not open the file!"< exit(1);
}
else
{
for (i=0;i {
ofs< < < < < < <
}
cout< ofs.close();
}
}

void stu::readout(student *p)
{
int i,m;
ifstream ifs("feifei.txt",ios::in|ios::binary);
if (!ifs)
{
cerr<<"can not open the file!"< exit(1);
}
else
{
for (i=0;i {

}
}
ifs.close();
}

void stu::T_caculate(struct student *p)
{
int i,j;
struct student temp;
for (i=0;i {
p[i].total=p[i].math+p[i].english+p[i].cplu_plus;
cout< }

for (i=0;i {
for (j=i+1;j {
if (p[i].total>p[j].total)
{
temp=p[j];
p[j]=p[i];
p[i]=temp;
}
}
}
}

void stu::A_caculate(struct student *p)
{
int i,j;
struct student temp;
for (i=0;i {
for (j=i+1;j {
if (p[i].stu_age>p[j].stu_age)
{
temp=p[j];
p[j]=p[i];
p[i]=temp;
}
}
}
}

int stu::Cacu_aver(struct student *p,int number)
{
int i,flag=1;
for (i=0;i {
p[i].average=(p[i].math+p[i].english+p[i].cplu_plus)/3.0;
if (p[i].stu_number==number)
{
cout< flag=0;
}

}
if (flag!=0&&i==n)
{
cout<<"!您输入的号码不存在,请查证后重新输入"< }
return flag;
}

int stu::Cacu_total(struct student *p,int number)
{
int i,flag=1;
for (i=0;i {
p[i].total=p[i].math+p[i].english+p[i].cplu_plus;
if (p[i].stu_number==number)
{
cout< flag=0;
}

}
if (flag!=0&&i==n)
{
cout<<"-------------------!您输入的号码不存在,请查证后重新输入---------------"< }
return flag;
}

void stu::out_put(struct student *p)
{
int i;
cout<<"student's information list here:"< cout<<" "< cout< cout< for (i=0;i {
cout<<"第"< cout< cout< if (p[i].total!=0)
{
cout< }
if (p[i].average!=0)
{
cout< }
cout< }
}

int main()
{
stu boy;
student *per,*outp;
int m;
cout<<"请从下面的菜单中选出您所要进行的操作选项:"< do
{
cout<<"1.输入学生信息并保存到文件"< cout<<"2.按年龄从大到小显示学生各项信息"< cout<<"3.按各门成绩由高到低显示学生信息"< cout<<"4.输入学号计算学生平均成绩并显示"< cout<<"5.输入学号计算学生总成绩并显示"< cout<<"6.按学生总成绩排名并显示排名结果"< cout<<"7.退出所在系统"< cin>>m;
system("cls");
switch (m)
{
case 1:
{
cout<<"please input the number of students you want to input:"< cin>>n;
per=new student[n];
boy.in_put(per,n);
boy.in_file(per,n);
delete []per;
break;
}

case 2:
{
outp=new student[n];
boy.readout(outp);
boy.A_caculate(outp);
boy.out_put(outp);
delete[]outp;
break;
}

case 3:
{
outp=new student[n];
boy.readout(outp);
boy.T_caculate(outp);
boy.out_put(outp);
delete[]outp;
break;
}

case 4:
{
int number,flag;
char flag1;
outp=new student[n];
boy.readout(outp);
do
{
cout<<"please input the number of the students you want to find:"< cin>>number;
flag=boy.Cacu_aver(outp,number);
if (flag==1)
{
cout<<"do you want to input again?'Y'/'N'"< cin>>flag1;
}
else
break;
}
while (flag1=='y'||flag1=='Y');
boy.in_file(outp,n);
delete[]outp;
break;
}

case 5:
{
int number,flag;
char flag1;
outp=new student[n];
boy.readout(outp);
do
{
cout<<"please input the number of the students you want to find:"< cin>>number;
flag=boy.Cacu_total(outp,number);
if (flag==1)
{
cout<<"do you want to input again?'Y'/'N'"< cin>>flag1;
}
else
break;
}
while (flag1=='y'||flag1=='Y');
boy.in_file(outp,n);
delete[]outp;
break;

}

case 6:
{
outp=new student[n];
boy.readout(outp);
boy.out_put(outp);
break;
}

}
}
while (m!=7);
return 0;
}

简单的提示你一下,要自己多联系的,不然很难学好