You are on page 1of 11

/*41.

(A 类)机房收费管理系统
(1)输入功能:输入若干名学生的学号、班级、姓名、开始上机时间和结束上机时间。
(2)计算功能:计算每个学生的上机费用(计算公式:上机费用 = (结束上机时间 - 开始上机时间) * 收费
标准,(以分钟为单位))
(3)修改功能:修改学生上机的个人档案(如:增添或删除)
(4)查询功能:按条件(班级、学号、姓名)查询学生上机信息,并能显示查询学生的相应全部档案*/
#include <iostream>
#include <string>
using namespace std;
//学生结构体

struct record {
int y;
int m;
int d;
int s_h;
int s_m;
int e_h;
int e_m;
};
struct student {
//学号
string ID;
//班级
string Class;
//姓名
string Name;
//记录
struct record arr[100];
int num=0;
int time=0;
};

struct book {
struct student array[100];
int size;
};
void add(book *abs,string classname[], int* classnum) {
system("cls");
if (abs->size == 100) {
cout << "信息已满,无法添加!" << endl;
system("pause");
system("cls");
return;
}
else {
//struct record rec;
int i = abs->array[abs->size].num;
string id;
cout << "请输入学号:" << endl;
cin >> id;
abs->array[abs->size].ID = id;
string Class;
cout << "请输入班级:" << endl;
cin >> Class;
abs->array[abs->size].Class = Class;
string name;
cout << "请输入姓名:" << endl;
cin >> name;
abs->array[abs->size].Name = name;
cout << "请输入上机日期:" << endl;
cout << "____年__月__日 " << endl;
int y;
cin >> y;
abs->array[abs->size].arr[i].y = y;
int m;
cin >> m;
abs->array[abs->size].arr[i].m = m;
int d;
cin >> d;
abs->array[abs->size].arr[i].d = d;
cout << "请输入开始时间:" << endl;
cout << "__时__分 " << endl;
int s_h;
cin>>s_h;
abs->array[abs->size].arr[i].s_h = s_h;
int s_m;
cin >> s_m;
abs->array[abs->size].arr[i].s_m = s_m;
a: cout << "请输入结束时间:" << endl;
cout << "__时__分 " << endl;
int e_h;
cin >> e_h;
if (e_h < s_h) {
cout << "输入错误!"<<endl;
goto a;
}
abs->array[abs->size].arr[i].e_h = e_h;
int e_m;
cin >> e_m;
if (e_h == s_h&&e_m<=s_m) {
cout << "输入错误!" << endl;
goto a;
}
abs->array[abs->size].arr[i].e_m = e_m;
//计算时间
int time;
if (abs->array[abs->size].arr[i].e_h > abs->array[abs->size].arr[i].s_h) {
time = (abs->array[abs->size].arr[i].e_h - abs->array[abs-
>size].arr[i].s_h) * 60 + abs->array[abs->size].arr[i].e_m - abs->array[abs-
>size].arr[i].s_m;
}
else {
time = abs->array[abs->size].arr[i].e_m - abs->array[abs-
>size].arr[i].s_m;
}
abs->array[abs->size].time = time;
abs->array[abs->size].num++;
abs->size++;
int flag = 1;
for (int i = 0; i < abs->size-1; i++) {
if (abs->array[i].Class == abs->array[abs->size-1].Class)flag = 0;
}
if (flag) {
*classnum= *classnum+1;
classname[*classnum - 1] = abs->array[abs->size-1].Class;
}
cout << "输入成功"<<endl;
system("Pause");
system("cls");
}
}

void change(book* abs,string classname[],int* classnum) {


while (true) {
if (abs->size == 0) {
cout << "当前无记录!" << endl;
system("Pause");
system("cls");
return;
}
int flag = 1;
c: cout << "请选择要修改的学生:" << endl;
for (int i = 0; i < abs->size; i++) {
cout << i + 1 << "、" << abs->array[i].Name << endl;
}
cout << "(输入 0 返回主菜单)" << endl;
int sel;
cin >> sel;
if (sel == 0) {
system("cls");
return;
}
if (sel<0 || sel>abs->size) {
cout << "选择错误,请重新选择!" << endl;
system("Pause");
system("cls");
goto c;
}
d: cout << "请选择下列操作:" << endl;
cout << "1、添加记录" << endl;
cout << "2、删除记录" << endl;
cout << "3、删除学生" << endl;
cout << "0、返回主菜单" << endl;
int sel2;
cin >> sel2;
if (sel2 > 3 || sel2 < 0) {
cout << "选择错误,请重新选择!" << endl;
system("Pause");
system("cls");
goto d;
}
switch (sel2) {
case 1:
cout << "请输入上机日期:" << endl;
cout << "____年__月__日 " << endl;
int y;
cin >> y;
abs->array[sel - 1].arr[abs->array[sel - 1].num].y = y;
int m;
cin >> m;
abs->array[sel - 1].arr[abs->array[sel - 1].num].m = m;
int d;
cin >> d;
abs->array[sel - 1].arr[abs->array[sel - 1].num].d = d;
cout << "请输入开始时间:" << endl;
cout << "__时__分 " << endl;
int s_h;
cin >> s_h;
abs->array[sel - 1].arr[abs->array[sel - 1].num].s_h = s_h;
int s_m;
cin >> s_m;
abs->array[sel - 1].arr[abs->array[sel - 1].num].s_m = s_m;
e: cout << "请输入结束时间:" << endl;
cout << "__时__分 " << endl;
int e_h;
cin >> e_h;
if (e_h < s_h) {
cout << "输入错误!" << endl;
goto e;
}
abs->array[sel - 1].arr[abs->array[sel - 1].num].e_h = e_h;
int e_m;
cin >> e_m;
if (e_h == s_h && e_m <= s_m) {
cout << "输入错误!" << endl;
goto e;
}
abs->array[sel - 1].arr[abs->array[sel - 1].num].e_m = e_m;
//计算时间
int time;
if (abs->array[sel - 1].arr[abs->array[sel - 1].num].e_h > abs-
>array[sel - 1].arr[abs->array[sel - 1].num].s_h) {
time = (abs->array[sel - 1].arr[abs->array[sel - 1].num].e_h - abs-
>array[sel - 1].arr[abs->array[sel - 1].num].s_h) * 60 + abs->array[sel -
1].arr[abs->array[sel - 1].num].e_m - abs->array[sel - 1].arr[abs->array[sel -
1].num].s_m;
}
else {
time = abs->array[sel - 1].arr[abs->array[sel - 1].num].e_m - abs-
>array[sel - 1].arr[abs->array[sel - 1].num].s_m;
}
abs->array[sel - 1].time += time;
abs->array[sel - 1].num++;
cout << "输入成功" << endl;
system("Pause");
system("cls");
break;
case 2:
if (abs->array[sel - 1].num == 0) {
cout << "该学生无记录!" << endl;
system("Pause");
system("cls");
break;
}
y: cout << abs->array[sel - 1].Name << "的记录:" << endl;
for (int i = 0; i < abs->array[sel - 1].num; i++) {
cout << i + 1 << "、" << abs->array[sel - 1].arr[i].y << "年" <<
abs->array[sel - 1].arr[i].m << "月" << abs->array[sel - 1].arr[i].d << "日 " <<
abs->array[sel - 1].arr[i].s_h << "时" << abs->array[sel - 1].arr[i].s_m << "分 至 "
<< abs->array[sel - 1].arr[i].e_h << "时" << abs->array[sel - 1].arr[i].e_m << "分"
<< endl;
}
cout << "请选择要删除的记录:" << endl;
cout << "(输入 0 返回上一级菜单)" << endl;
int sel3;
cin >> sel3;
if (sel3 < 0 || sel3 > abs->array[sel - 1].num) {
cout << "输入错误!" << endl;
system("Pause");
system("cls");
goto y;
}
if (sel3 == 0) {
system("cls");
continue;
}
if (abs->array[sel - 1].arr[sel3 - 1].e_h > abs->array[sel -
1].arr[sel3 - 1].s_h) {
time = (abs->array[sel - 1].arr[sel3 - 1].e_h - abs->array[sel -
1].arr[sel3 - 1].s_h) * 60 + abs->array[sel - 1].arr[sel3 - 1].e_m - abs->array[sel
- 1].arr[sel3 - 1].s_m;
}
else {
time = abs->array[sel - 1].arr[sel3 - 1].e_m - abs->array[sel -
1].arr[sel3 - 1].s_m;
}
for (int i = sel-1; i < abs->array[sel - 1].num-1; i++) {
abs->array[sel - 1].arr[i] = abs->array[sel - 1].arr[i + 1];
}
abs->array[sel - 1].time -= time;
abs->array[sel - 1].num--;

cout << "删除成功!" << endl;


system("pause");
system("cls");
break;
case 3:
for (int i = 0; i < abs->size; i++) {
if (abs->array[sel-1].Class==abs->array[i].Class&&i!=sel-1)flag =
0;
}
for (int i = sel - 1; i < abs->size - 1; i++) {
abs->array[i] = abs->array[i + 1];
}
abs->array[sel - 1].num = 0;
abs->size--;
if (flag)*classnum = *classnum - 1;
cout << "删除成功!"<<endl;
system("pause");
system("cls");
break;
case 0:
system("cls");
return;
break;
}
}
}
void cal(book* abs) {
if (abs->size == 0) {
cout << "当前无记录!" << endl;
system("pause");
system("cls");
return;
}
int x;
cout << "请输入收费标准(元/小时):";
cin >> x;
d: cout << "请选择要查询的学生:"<<endl;
for (int i = 0; i < abs->size; i++) {
cout << i + 1 << "、" << abs->array[i].Name << endl;
}
int sel;
cin >> sel;
if (sel<1 || sel>abs->size) {
cout << "输入有误,请重新输入!"<<endl;
system("pause");
system("cls");
goto d;
}
cout << abs->array[sel - 1].Name << "共上机" << abs->array[sel - 1].time << "分
钟"<<endl;
cout<<"费用为"<< abs->array[sel - 1].time*x<<"元"<<endl;
system("pause");
system("cls");
return;
}
void showinf(int i,book abs) {
cout << "姓名:" << abs.array[i].Name << endl;
cout << "学号:" << abs.array[i].ID << endl;
cout << "班级:" << abs.array[i].Class << endl;
cout << "上机记录如下:" << endl;
for (int j = 0; j < abs.array[i].num; j++) {
cout << j + 1 << "、" << abs.array[i].arr[j].y << "年" <<
abs.array[i].arr[j].m << "月" << abs.array[i].arr[j].d << "日 " <<
abs.array[i].arr[j].s_h << "时" << abs.array[i].arr[j].s_m << "分 至 " <<
abs.array[i].arr[j].e_h << "时" << abs.array[i].arr[j].e_m << "分" << endl;
}
cout << "总时长:" << abs.array[i].time << "分钟" << endl;
}
void search(book* abs, string classname[], int* classnum) {
if (abs->size == 0) {
cout << "当前无记录" << endl;
system("pause");
system("cls");
return;
}
while (true) {
e: cout << "1、按班级查询" << endl;
cout << "2、按学号查询" << endl;
cout << "3、按姓名查询" << endl;
cout << "4、显示人员列表" << endl;
cout << "0、返回主菜单" << endl;
int sel;
cin >> sel;
if (sel < 0 || sel>4) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto e;
}
switch (sel) {
case 1:
f: cout << "请选择查询方式:" << endl;
cout << "1、输入班级名称" << endl;
cout << "2、显示班级列表" << endl;
int sel2;
cin >> sel2;
if (sel2 != 1 && sel2 != 2) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto f;
}
switch (sel2) {
case 1: {
cout << "请输入要查询的班级:" << endl;
string c;
cin >> c;
int classarr[100];
int j = 0;
for (int i = 0; i < abs->size; i++) {
if (abs->array[i].Class == c) {
classarr[j] = i;
j++;
}
}
if (j == 0) {
cout << "查无此班级!" << endl;
system("pause");
system("cls");
continue;
}
system("cls");
z: cout << c << "班的同学如下:" << endl;
for (int i = 0; i < j; i++) {
cout << classarr[i] + 1 << "、" << abs->array[classarr[i]].Name
<< endl;
}
int sel;
cout << "请选择要查询的学生:";
cin >> sel;
if (sel<1 || sel>j) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto z;
}
system("cls");
showinf(classarr[sel - 1], *abs);
system("pause");
system("cls");
break;
}
case 2:
g: cout << "班级列表如下:" << endl;
for (int i = 0; i < *classnum; i++) {
cout << i + 1 << "、" << classname[i] << endl;
}
cout << "请选择要查询的班级:" << endl;
int sel2;
cin >> sel2;
if (sel2<1 || sel2>*classnum) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto g;
}
int classarr[100];
int j = 0;
for (int i = 0; i < abs->size; i++) {
if (abs->array[i].Class == classname[sel2 - 1]) {
classarr[j] = i;
j++;
}
}
l: cout << classname[sel2 - 1] << "班的同学如下:" << endl;
for (int i = 0; i < j; i++) {
cout << i + 1 << "、" << abs->array[classarr[i]].Name << endl;
}
int sel;
cout << "请选择要查询的学生:";
cin >> sel;
if (sel<1 || sel>j) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto l;
}
system("cls");
showinf(classarr[sel - 1], *abs);
system("pause");
system("cls");
break;
}
break;
case 2: {
cout << "请输入学号:";
string id;
cin >> id;
int p = -1;
for (int i = 0; i < abs->size; i++) {
if (abs->array[i].ID == id) {
p = i;
break;
}
}
if (p == -1) {
system("cls");
cout << "查无此人!" << endl;
system("pause");
system("cls");
continue;
}
system("cls");
showinf(p, *abs);
system("pause");
system("cls");
break;
}
case 3: {
cout << "请输入姓名:";
string name;
cin >> name;
int p2 = -1;
for (int i = 0; i < abs->size; i++) {
if (abs->array[i].Name == name) {
p2 = i;
break;
}
}
if (p2 == -1) {
system("cls");
cout << "查无此人!" << endl;
system("pause");
system("cls");
continue;
}
system("cls");
showinf(p2, *abs);
system("pause");
system("cls");
break;
}
case 4:
system("cls");
m: for (int i = 0; i < abs->size; i++) {
cout << i + 1 << "、" << abs->array[i].Name << endl;
}
cout << "请选择要查询的学生:" << endl;
int sel;
cin >> sel;
if (sel<1 || sel>abs->size) {
cout << "输入有误,请重新输入!" << endl;
system("pause");
system("cls");
goto m;
}
system("cls");
showinf(sel - 1, *abs);
system("pause");
system("cls");
break;
case 0:
system("cls");
return;
break;

}
}
}
//菜单显示功能
void showmenue() {
cout << "*************************" << endl;
cout << "*** 机房收费管理系统 **" << endl;
cout << "***** 1、新建人员 *****" << endl;
cout << "***** 2、查询费用 *****" << endl;
cout << "***** 3、修改人员 *****" << endl;
cout << "***** 4、查询人员 *****" << endl;
cout << "***** 0、退出系统 *****" << endl;
cout << "*************************" << endl;
}
int main() {
int classnum = 0;
string classname[100];
book abs;
abs.size = 0;
abs.array->time = 0;
abs.array->num = 0;
int sel = 0;
while (true) {
showmenue();
cin >> sel;
switch (sel) {
case 1: //1、输入功能
add(&abs,classname, &classnum);
break;
case 2: //2、计算功能
cal(&abs);
break;
case 3: //3、修改功能
change(&abs,classname, &classnum);
break;
case 4: //查询功能
search(&abs,classname,&classnum);
break;
case 0: //0、退出
system("cls");
cout << "欢迎下次使用!" << endl;
system("pause");
return 0;
default:
cout << "输入有误!" << endl;
system("pause");
system("cls");
break;
}
}
system("pause");
return 0;
}

You might also like