#include<iostream>
#include<iostream>
#include<fstream>
using namespace std;
class Student
{
public:
Student();
void set();
void save();
void reset();
void length();
void print();
void select();
void find();
void choose();
protected:
long long num;
char name[30];
int clas;
double score;
int nu, t, f;
double swap;
};
Student s[58];
Student::Student(){
}
void Student::choose()
{
cout << "************************************************" << endl;
cout << "请选择功能:" << endl;
cout << "1.输入学生信息 " << "2.输出学生信息 " << endl;
cout << "3.查找学生信息 " << "4.修改学生信息 " << endl;
cout << "5.成绩排名 " << "6.成绩状况分析 " << endl;
cout << "7.数据保存 " << "0.退出系统 "<< endl;
cout << "请选择(1~0)并按回车键确认:"<<endl;
cout << "************************************************" << endl;
}
void Student::save()
{
cout << "是否保存(y/n)?" << endl;
ofstream fout("C:\\学生成绩.txt", ios::out | ios::binary);
char i = 'y';
cin >> i;
if (i == 'y')
{
if (!fout)cout << "文件不能打开!" << endl;
else
{
for (int i = 0; ;i++,i = nu - 1)
fout << "学号:" << s[i].num << " 姓名:" << s[i].name << " 班级:" << s[i].clas << " 成绩:" << s[i].score << endl;
cout << "保存成功!" << endl;
}
}
fout.close();
}
void Student::reset()
{
char c = 'y';
while (c == 'y')
{
cout << "修改学生信息(y/n)?" << endl;
cin >> c;
if (c == 'y')
{
cout << "请输入要修改信息的学生学号:";
cin >> t;
cout << "请重新输入学生信息:" << endl;
cin >> s[t - 1].num >> s[t - 1].name >> s[t - 1].clas >> s[t - 1].score;
}
else
{
break;
}
}
}
void Student::set()
{
cout << "请输入录入成绩学生个数:" << endl;
cin >> nu;
cout << "请输入学生信息,例如:1(学号) 张三(姓名) 1192(班级) 78(成绩)" << endl;
for (int i = 0; i < nu; i++)
{
cin >> s[i].num >> s[i].name >> s[i].clas >> s[i].score;
}
}
void Student::length()
{
int l=0,p=0,q=0;
for (int i = 0; i < nu; i++)
{
if (s[i].score >= 85)
l++;
else
{
if (s[i].score >= 60)
p++;
else
q++;
}
}
cout << "共有学生:" << nu << "人" << endl;
cout << "优秀学生(85~100)共有:" << l << "人" << endl;
cout << "一般学生(60~84)共有:" << p << "人" <<endl;
cout << "及格学生(60~100)共有:" << p+l << "人" << endl;
cout << "不及格学生(0~59)共有:" << q << "人" << endl;
}
void Student::find()
{
char j = 'y';
while (j == 'y')
{
cout << "是否要查询学生成绩(y/n)?" << endl;
cin >> j;
if (j == 'y')
{
cout << "请输入所查学生学号:" << endl;
cin >> f;
cout << "所查学生信息为:" << endl;
cout << "学号:" << s[f - 1].num << " 姓名:" << s[f - 1].name << " 班级:" << s[f - 1].clas << " 成绩:" << s[f - 1].score << endl;
}
else
{
break;
}
}
}
void Student::print()
{
cout << "学生信息:" << endl;
cout << "************************************************" << endl;
for (int i = 0; i < nu; i++)
cout <<"学号:"<<s[i].num <<" "<<"姓名:"<< s[i].name<<" "<<"班级:"<< s[i].clas<<" "<< "成绩:" << s[i].score<<endl;
cout << "************************************************" << endl;
}
void Student::select()
{
for (int i = 0; i < nu; i++)
{
for (int j = 0; j < nu - i; j++)
{
if (s[j].score < s[j + 1].score)
{
Student swap = s[j];
s[j] = s[j + 1];
s[j + 1] = swap;
}
}
}
cout << "************************************************" << endl;
for (int i = 0; i < nu; i++)
{
cout << "学号:" << s[i].num << " 姓名:" << s[i].name << " 班级:" << s[i].clas << " 成绩:" << s[i].score << endl;
}
cout << "************************************************" << endl;
}
int main()
{
int choice;
cout << "************欢迎进入学生成绩管理系统************" << endl;
Student m;
ofstream ofile("C:\\学生成绩.txt", ios::out | ios::binary);
if (!ofile.fail()) {
ofile.write((char*)&m, sizeof(m));
}
ofile.close();
ifstream ifile("C:\\学生成绩.txt", ios::in | ios::binary);
if (!ifile.fail()) {
ifile.read((char*)&m, sizeof(m));
do
{
m.choose();
cin >> choice;
switch (choice)
{
case 1: m.set(); break;
case 2: m.print(); break;
case 3: m.find(); break;
case 4: m.reset(); break;
case 5: m.select(); break;
case 6: m.length(); break;
case 7: m.save(); break;
default: break;
}
} while (choice != 0);
}
ifile.close();
return 0;
}
C++学生成绩管理系统(可自行修改有关内容,轻点喷)
于 2020-05-28 20:20:55 首次发布