本系统可实现通过密码登录选择进入老师模式或管理员模式,进而实现学生成绩录入,学生成绩查询,成绩储存,成绩单调取,学生老师添加查找删除等功能。
#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 << "\t\t----------------------------------------------------" << endl;
cout << "\t\t----------------------------------------------------" << endl;
cout << "\t\t----------------------------------------------------" << endl;
cout << "\t\t◎\t\t\t\t\t\t ◎" << end