本系统可实现通过密码登录选择进入老师模式或管理员模式,进而实现学生成绩录入,学生成绩查询,成绩储存,成绩单调取,学生老师添加查找删除等功能。
#include"iostream"
#include"conio.h"
#include"iomanip"
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"fstream"
using namespace std;
class teacher{
public:
int number;
char name[20];
teacher();
teacher& operator=(teacher& R);
friend istream& operator >> (istream& scin, teacher& t1);
friend ostream& operator << (ostream& scout, teacher& t2);
};
class operate{
public:
void add();
void del();
void find();
void output();
};
operate ope;
teacher tea[20];
int m = 0;
void operate::add()
{
char flag = 'Y';
while (toupper(flag) == 'Y') //toupper()函数将值转变为大写
{
cin >> tea[m];
m++;
cout << "请问要继续录入吗?(请输入Y或N)";
cin >> flag;
if (toupper(flag) != 'Y')
{
if (toupper(flag) == 'N')
{
break;
}
else
{
cout << "输入错误,请重新输入: ";
cin >> flag;
}
}
}
}
void operate::output()
{
if (m != 0)
{
cout << "" << endl;
cout << "/" << endl;
cout << "工号 姓名 " << endl;
cout << "---------------------" << endl;
cout << "+++++++++++++++++++++" << endl;
for (int t = 0; t < m; t++)
{
cout << tea[t];
}
}
system("pause");
getchar();
}
void operate::del()
{
char n3[40];
bool f5 = 0;
char c;
do {
cout << 'n';
cout << "输入你要删除的老师姓名:";
cin >> n3;
for (int i = 0; i < m; i++)
{
if (strcmp(n3, tea[i].name) == 0)
{
f5 = 1;
m--;
do {
tea[i] = tea[i + 1];
i++;
} while (i <= m);
}
}
if (f5 == 0)
cout << "你要删除的老师不存在" << endl;
cout << "是否要继续删除?(请输入Y或N)" << endl;
cin >> c;
if (toupper(c) != 'Y' && toupper(c) != 'N')
{
cout << "输入错误!你只能输入Y或N" << endl;
cin >> c;
}
} while (toupper(c) == 'Y');
getchar();
}
//=============================================================
teacher& teacher::operator = (teacher& R)
{
strcpy_s(name, R.name);
number = R.number;
return (*this);
}
ostream& operator << (ostream& scout, teacher& t1)
{
cout << setw(5) << t1.number << setw(6) << t1.name << setw(6) << 'n';
return scout;
}
istream& operator >>(istream& scin, teacher& t1)
{
cout << 'n';
cout << "工号:";
scin >> t1.number;
cout << "姓名:";
scin >> t1.name;
return scin;
}
teacher::teacher()
{
strcpy_s(name, " ");
number = 0;
}
void menu1()
{
system("cls");
cout << "tt----------------------------------------------------" << endl;
cout << "tt----------------------------------------------------" << endl;
cout << "tt----------------------------------------------------" << endl;
cout << "tt◎tttttt ◎" << endl;
cout << "tt◎★★★★【 欢迎进入学生成绩管理系统 】★★★★◎" << endl;
cout << "tt◎tttttt ◎" << endl;
cout << "tt----------------------------------------------------" << endl;
cout << "tt----------------------------------------------------" << endl;
cout << "tt----------------------------------------------------制作人:李思怡n" << endl;;
cout << "请选择进入模式:n如果选择老师模式请输入“2”,选择管理员模式请按“1”。并按回车键确认【退出请输0】:" << endl;
}
void menu2()
{
system("cls");
cout << "******************************************************************制作人:李思怡" << endl;
cout << "〓〓〓〓〓〓〓〓〓〓 ☆ 管理员管理系统 ☆ 〓〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓★★★★★ ★★★★★★★ ★★★★★〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 1.添加老师信息 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 2.删除老师信息 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 3.查询学生信息 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 4.查询老师信息 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 5.展示老师信息 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "〓〓〓〓〓〓〓〓〓★ ☆ 0.返回主页面 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "nnt请输入一位数字(1-4)选择你所需的功能,并按回车键确认:";
}
int secret_operate(){
system("cls");
string password = "123456";
char psd[100];
int time = 3;
while (1)
{
cout << "请输入位密码";
cin >> psd;
if (password == psd)
{
cout << "登陆成功" << endl;
return 1;
}
else
{
time--;
cout << "密码错误,还有" << time << "次机会" << endl;
}
if (time == 0)
return -1;
}
}
int secret_teacher(){
system("cls");
string password = "000000";
char psd[100];
int time = 3;
while (1)
{
cout << "请输入位密码";
cin >> psd;
if (password == psd)
{
cout << "登陆成功" << endl;
system("pause");
return 1;
}
else
{
time--;
cout << "密码错误,还有" << time << "次机会" << endl;
}
if (time == 0)
return -1;
}
}
void operate::find()
{
int f3 = 0;
char n1[40];
teacher temp;
cout << 'n';
cout << "请输入要查找的老师的姓名:";
cin >> n1;
for (int j = 0; j < m; j++)
{
if (strcmp(tea[j].name, n1) == 0)
{
temp = tea[j];
f3 = 1;
}
}
if (f3 == 0)
cout << "对不起,没有要查找的老师" << endl;
else
{
cout << "n";
cout << "///" << endl;
cout << "工号 姓名 " << endl;
cout << "-----------------------" << endl;
cout << "+++++++++++++++++++++++" << endl;
cout << setw(5) << temp.number << setw(6) << temp.name << setw(6) << endl;
}
system("pause");
getchar();
}
class student
{
public:
char name[20];
char sex[6];
int number;
int score[7];
int total;
int average;
int last;
public:
student();
void input();
void output();
void find();
void modify();
void deleted();
void save();
void load();
student & operator=(student & T);
friend istream & operator >> (istream & scin, student &s1);
friend ostream & operator << (ostream & scout, student &s2);
};
student stu[200];
int n = 0;
void student::input()
{
char flag = 'Y';
while (toupper(flag) == 'Y')
{
cin >> stu[n];
n++;
cout << "请问还要继续录入吗?(请输入 y or n )";
cin >> flag;
if (toupper(flag) != 'Y')
{
if (toupper(flag) == 'N')
{
break;
}
else
{
cout << "输入错误,请重输:";
cin >> flag;
}
}
}
}
void student::output()
{
if (n != 0)
{
cout << "==============================================================================n";
cout << " 学号 姓名 性别 语文 英语 数学 物理 化学 生物 平时成绩 总评 n";
cout << "------------------------------------------------------------------------------n";
for (int t = 0; t> n1;
for (int j = 0; j> n2;
for (int j = 0; j> stu[t].number;
cout << "请输入修改后的学生姓名:";
cin >> stu[t].name;
cout << "请输入修改后的学生性别:";
cin >> stu[t].sex;
cout << "请输入修改后的语文成绩:";
cin >> stu[t].score[0];
cout << "请输入修改后的英语成绩:";
cin >> stu[t].score[1];
cout << "请输入修改后的数学成绩:";
cin >> stu[t].score[2];
cout << "请输入修改后的物理成绩:";
cin >> stu[t].score[3];
cout << "请输入修改后的化学成绩:";
cin >> stu[t].score[4];
cout << "请输入修改后的生物成绩:";
cin >> stu[t].score[5];
cout << "请输入修改后的平时成绩:";
cin >> stu[t].score[6];
stu[t].total = stu[t].score[0] + stu[t].score[1] + stu[t].score[2] + stu[t].score[3] + stu[t].score[4] + stu[t].score[5];
stu[t].average = stu[t].total / 6;
stu[t].last = (int)(stu[t].score[6] * 0.3 + stu[t].average*0.7);
cout << " 修改成功 !" << endl;
}
_getch();
}
void student::deleted()
{
char n3[20];
bool f5 = 0;
char c;
do{
cout << 'n';
cout << "请输入你要删除的学生姓名:";
cin >> n3;
for (int i = 0; i> c;
if (toupper(c) != 'Y'&&toupper(c) != 'N')
{
cout << "输入错误!您只能输入Y或N" << endl;
cin >> c;
}
} while (toupper(c) == 'Y');
_getch();
}
void student::save()
{
char filename1[20];
cout << "请输入文件名:";
cin >> filename1;
ofstream fout(filename1, ios::app);
if (!fout)cout << "文件打不开!" << endl;
else
{
for (int i = 0; i> filename2;
ifstream fin(filename2, ios::in);
if (!fin)cout << "" << endl;
else
{
for (int i = 0;; i++, n = i - 1)
{
if (fin.eof())
break;
fin >> stu[i].number >> stu[i].name >> stu[i].sex >> stu[i].score[0] >> stu[i].score[1] >> stu[i].score[2] >> stu[i].score[3] >> stu[i].score[4] >> stu[i].score[5] >> stu[i].score[6] >> stu[i].total >> stu[i].average >> stu[i].last;
}
cout << " 文件已读取成功 !" << endl;
}
fin.close();
_getch();
}
student & student::operator=(student & T)
{
strcpy_s(name, T.name);
strcpy_s(sex, T.sex);
number = T.number;
for (int i = 0; i<7; i++)
score[i] = T.score[i];
total = T.total;
average = T.average;
last = T.last;
return(*this);
}
ostream & operator << (ostream & scout, student &s2)
{
cout << setw(5) << s2.number << setw(6) << s2.name << setw(6) << s2.sex << setw(6) << s2.score[0]
<< setw(6) << s2.score[1] << setw(6) << s2.score[2] << setw(6) << s2.score[3] << setw(6) << s2.score[4]
<< setw(6) << s2.score[5] << setw(6) << s2.score[6] << setw(9) << s2.last << 'n';
return scout;
}
istream & operator >> (istream & scin, student &s1)
{
cout << 'n';
cout << "学号:";
scin >> s1.number;
cout << "姓名:";
scin >> s1.name;
cout << "性别:";
scin >> s1.sex;
cout << "语文:";
scin >> s1.score[0];
cout << "英语:";
scin >> s1.score[1];
cout << "数学:";
scin >> s1.score[2];
cout << "物理:";
scin >> s1.score[3];
cout << "化学:";
scin >> s1.score[4];
cout << "生物:";
scin >> s1.score[5];
cout << "平时成绩:";
scin >> s1.score[6];
s1.total = s1.score[0] + s1.score[1] + s1.score[2] + s1.score[3] + s1.score[4] + s1.score[5];
s1.average = s1.total / 6;
s1.last = (int)(s1.score[6] * 0.3 + s1.average*0.7);
return cin;
}
student::student()
{
strcpy_s(name, " ");
strcpy_s(sex, " ");
number = 0;
for (int i = 0; i<7; i++)
score[i] = 0;
total = 0;
average = 0;
last = 0;
}
void menu()
{
system("cls");
cout << "******************************************************************制作人:李思怡" << endl;
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 << "〓〓〓〓〓〓〓〓〓★ ☆ 0.退出系统 ☆ ★〓〓〓〓〓〓〓〓〓" << endl;
cout << "nnt请输入一位数字(1-7)选择您所需的功能,并按回车键确认【退出请输0】:";
}
int main()
{
int choose1;
do{
menu1();
int choose;
student s;
cin >> choose1;
while (choose1)
{
if (choose1 == 2)
{
int kind1 = secret_teacher();
if (kind1 == -1)
break;
do {
menu();
cin >> choose;
switch (choose)
{
case 1: s.input(); break;
case 2: s.output(); break;
case 3: s.find(); break;
case 4: s.modify(); break;
case 5: s.deleted(); break;
case 6: s.save(); break;
case 7: s.load(); break;
default:break;
}
} while (choose != 0);
break;
}
else if (choose1 == 1)
{
int kind2 = secret_operate();
if (kind2 == -1)
break;
int choose2;
do{
menu2();
cin >> choose2;
switch (choose2)
{
case 1:ope.add(); break;
case 2:ope.del(); break;
case 3:s.find(); break;
case 4:ope.find(); break;
case 5:ope.output(); break;
default: break;
}
} while (choose2 != 0);
break;
}
else if (choose1 == 0)
break;
else
{
cout << "输入有误,请重新输入" << endl;
cin >> choose1;
}
}
} while (choose1 != 0);
return 0;
}



