还是找的最简单的做,但是最简单的都没有做好!
调试没有成功,第一步打开都出错了。但是不想做了,做了许久。理论上可以这样的啊!!!!!!
/*课题名称:学生成绩管理系统的设计
说明:成绩记录以下信息:班级,学号,姓名,课程名,成绩(百分制)。可以用能表示学生成绩的结构体数组存储数据。
要求:
1) 具备对成绩的管理功能(添加、删除、排序)
2) 具备对成绩的统计功能(最高分,最低分,平均分,及格率等)
3) 具备按学号、姓名查询成绩的功能。
*/
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;
struct position {//与存储有关
int dong = 0;//一个规定的值,用来判断输入的,动的是那个值
int all = 0;//所有的值
};
struct student
{
bool flag=0;//存的值,判断这个成员的存在。若为0则不存在
char classroom[10];//班级
char xuehao[13];//学号
char name[6];//名字
char classA[10];//课程A
float gradeA;//成绩A
char classB[10];
float gradeB;//B
float Allgrade;//总分
};
student shuruxinxi(student A,position add) {
cout << "请按照顺序输入。班级,学号,名字,课程A,课程A成绩,课程B,课程B成绩,···" << endl;
cin >> A.classroom;
cin >> A.xuehao;
cin >> A.name;
cin >> A.classA;
cin >> A.gradeA;
cin >> A.classA;
cin >> A.gradeA;
A.flag = 1;
A.Allgrade = A.gradeA + A.gradeB;
add.dong++;
add.all++;
system("cls");
return A;
}
void sort(student *stu,position add,char C[10]=0)
{
if (stu[0].classA == C) {
student temp;
for (int i = 0; i < add.all; i++)
{
for (int j = i+1; j < add.all; j++)
{
if (stu[i].gradeA <stu[j].gradeA) {
temp=stu[i];
stu[i]= stu[j];
stu[j] = stu[i];
}
}
}
}
else if(stu[0].classB==C)
{
student temp;
for (int i = 0; i < add.all; i++)
{
for (int j = i + 1; j < add.all; j++)
{
if (stu[i].gradeB <stu[j].gradeB) {
temp = stu[i];
stu[i] = stu[j];
stu[j] = stu[i];
}
}
}
}
else {
student temp;
for (int i = 0; i < add.all; i++)
{
for (int j = i + 1; j < add.all; j++)
{
if (stu[i].Allgrade <stu[j].Allgrade) {
temp = stu[i];
stu[i] = stu[j];
stu[j] = stu[i];
}
}
}
}
}
void display(student A,int i)
{
cout << i << "\t\t";
cout << A.classroom << "\t\t";
cout << A.xuehao << "\t\t";
cout << A.name<< "\t\t";
cout << A.classA<< "\t\t";
cout << A.gradeA << "\t\t";
cout << A.classB << "\t\t";
cout << A.gradeB << "\t\t";
}
void display_demo()
{
cout << "序号\t\t"<<"班级\t\t" << "学号\t\t" << "名字\t\t" << "课程A\t\t" << "A成绩\t\t"<<"课程B\t\t"<<"B成绩\t\t"<<"总分" << endl;
}
void display_operate()
{
cout << "0.退出操作" << endl;
cout << "1.添加学生" << endl;
cout << "2.删除学生" << endl;
cout << "3.学生排序" << endl;
cout << "4.统计学生" << endl;
cout << "5.查询学生" << endl;
}
void display_tongji()
{
cout << "1.最高分" << endl;
cout << "2.最低分" << endl;
cout << "3.平均分" << endl;
cout << "4.及格率" << endl;
}
void display_denghao()
{
cout << "=================================================================================================================================" << endl;
}
int query(student A,char xuehao[13] = 0, char name[6] = 0) {
if (strcmp(A.xuehao,xuehao)==0){
display_denghao();
display_demo();
display(A, 0);
return 1;
}
if (strcmp(A.name, name) == 0) {
display_denghao();
display_demo();
display(A, 0);
return 1;
}
return 0;
}
int main()
{
position add;
int xuhao;//del
char tempclassname[10];
student studA;
student studB;
int choose=0;
student *studpoint=&studB;
fstream iofile ("stud.dat",ios::in | ios::out | ios::binary);
if(!iofile)
{
cerr <<"open error!" << endl;
system("pause");
abort();
}
int i=1;
char panduan[4];
cout << "Follow the prompts to enter the information below" << endl;
add:while (i)
{
shuruxinxi(studA,add);
iofile.write((char *)&studA, sizeof(studA));
cout << "是否继续输入Y/N" << endl;
cin >> panduan;
if (panduan[0]== 'N' || panduan[0] == 'n')i = 0;
}
studB = studA;
cout << "输出完成,下表是你的输入的信息" << endl;
display_demo();
for (int j = 0; j < add.all; j++)
{
iofile.seekg(j * sizeof(studB), ios::beg);
iofile.read((char *)&studB, sizeof(studB));
display(studB,j);
}
choose: cout << "请选择你需要的操作" << endl;
display_operate();
cin >> choose;
if (choose == 0)goto end;
if (choose == 1)goto add;
if (choose == 2)goto del;
if (choose == 3)goto sort;
if (choose == 4)goto tongji;
if (choose == 5)goto query;
goto end;
del: {
cout << "下表学生信息,你删除那个学生数据。输入序号" << endl;
display_denghao();
display_demo();
for (int j = 0; j < add.all; j++)
{
iofile.read((char *)&studA, sizeof(studA));
display(studA, j);
}
display_denghao();
cin >> xuhao;
while (studB.flag) {
iofile.seekg((xuhao) * sizeof(studA), ios::beg);
iofile.read((char*)&studA, sizeof(studA));
iofile.seekg((xuhao + 1) * sizeof(studB), ios::beg);
iofile.read((char*)&studB, sizeof(studB));
if (studB.flag) {
iofile.seekp(xuhao * sizeof(studA), ios::beg);
iofile.write((char*)&studB, sizeof(studB));
}
else {
studA.flag = 0;
iofile.seekp(xuhao * sizeof(studA), ios::beg);
iofile.write((char*)&studA, sizeof(studB));
}
//studB.flag = 0;
//iofile.seekp((xuhao + 1) * sizeof(studA), ios::beg);
//iofile.write((char*)&studB, sizeof(studB));
xuhao++;
}
add.all--;
cout << "删除后的数据" << endl;
display_denghao();
display_demo();
for (int j = 0; j < add.all; j++)
{
iofile.read((char *)&studB, sizeof(studB));
display(studB, j);
}
display_denghao();
goto choose;
}
sort: {
cout << "1.课程排序" << endl;
cout << "2.总分排序" << endl;
cin >> choose;
if (choose == 1)goto kechengpaixu;
if (choose == 2)goto zongfenpaixu;
kechengpaixu:cout << "请输入以那一门课程排序" << endl;
cin >> tempclassname;
student *stu = new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu[j], sizeof(stu[j]));
}
sort(stu, add, tempclassname);
display_denghao();
display_demo();
for (int j = 0; j < add.all; j++)
{
display(stu[j], j);
}
display_denghao();
delete[] stu;
goto choose;
zongfenpaixu:
student *stu1 = new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu1[j], sizeof(stu[j]));
}
sort(stu, add);
display_denghao();
display_demo();
for (int j = 0; j < add.all; j++)
{
display(stu1[j], j);
}
display_denghao();
delete[] stu;
goto choose;
}
tongji: {display_tongji();
cin >> choose;
if(choose==1){
cout << "1.课程最高分" << endl;
cout << "2.总分最高分" << endl;
cin >> choose;
if (choose == 1)goto kechenzuigao;
if (choose == 2)goto zongfenzuigaofen;
kechenzuigao: cout << "请输入以那一门课程名字" << endl;
cin >> tempclassname;
student *stu1 = new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu1[j], sizeof(stu1[j]));
}
sort(stu1, add, tempclassname);
cout << tempclassname << "的最高分是" << endl;
display_denghao();
display_demo();
display(stu1[1],1);
display_denghao();
delete[] stu1;
goto choose;
zongfenzuigaofen:
student *stu2 = new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu2[j], sizeof(stu2[j]));
}
sort(stu2, add);
cout << tempclassname << "的最高分是" << endl;
display_denghao();
display_demo();
display(stu2[1], 1);
display_denghao();
delete[] stu2;
goto choose;
}//最高分
if(choose==2){
cout << "1.课程最低分" << endl;
cout << "2.总分最低分" << endl;
cin >> choose;
if (choose == 1)goto kechenzuidi;
if (choose == 2)goto zongfenzuidifen;
kechenzuidi: cout << "请输入以那一门课程名字" << endl;
cin >> tempclassname;
student *stu = new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu[j], sizeof(stu[j]));
}
sort(stu, add, tempclassname);
cout << tempclassname << "的最低分是" << endl;
display_denghao();
display_demo();
display(stu[add.all], add.all);
display_denghao();
delete[] stu;
goto choose;
zongfenzuidifen:
student *stu3= new student[add.all];
for (int j = 0; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&stu3[j], sizeof(stu3[j]));
}
sort(stu3, add);
cout <<"总分的最高分是" << endl;
display_denghao();
display_demo();
display(stu3[add.all], add.all);
display_denghao();
delete[] stu3;
goto choose;
}//最低分
if(choose==3){
float all=0.0;
float allclassa = 0.0;
float allclassb = 0.0;
for (int i = 0; i < add.all; i++) {
iofile.seekg(i * sizeof(studA), ios::beg);
iofile.read((char*)&studB, sizeof(studB));
all = all + studB.Allgrade;
allclassa = allclassa + studB.gradeA;
allclassb = allclassb + studB.gradeB;
}
cout << studA.classA << "的平均分是" << allclassa / add.all << endl;
cout << studA.classB << "的平均分是" << allclassb/ add.all << endl;
cout << "总分平均分是:" << all / add.all << endl;
}//平均分
if(choose==4){
float ajige=0.0;
float bjige=0.0;
for (int i = 0; i < add.all; i++) {
iofile.seekg(i * sizeof(studA), ios::beg);
iofile.read((char*)&studB, sizeof(studB));
if (studB.gradeA > 60)ajige++;
if (studB.gradeB > 60)bjige++;
}
cout << studA.classA << "的及格率是" << ajige / add.all << endl;
cout << studA.classB << "的及格率是" << bjige / add.all << endl;
}//及格率
}
query:
cout << "1.通过学号查询" << endl;
cout << "2.通过姓名查询" << endl;
cin >> choose;
if (choose == 1) {
cout << "输入查询的学号" << endl;
char t[13];
int a,j = 0;
cin >> t;
for ( j; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&studB, sizeof(studB));
a=query(studB, t);
if (a == 1)break;
}if (j == add.all)cout << "没找到" << endl;
}
if (choose == 2) {
cout << "输入查询的姓名" << endl;
char t[6];
char t1[13];
int a;
int j = 0;
cin >> t;
for ( j; j < add.all; j++) {
iofile.seekg(j * sizeof(studA), ios::beg);
iofile.read((char*)&studB, sizeof(studB));
a=query(studB, t1,t);
if (a == 1)break;
}
if (j == add.all)cout << "没找到" << endl;
}
goto choose;
end:
return 0;
}