/*程序使用方法:
1、在创建新用户时,请在user的大括号中输入名字课时数,注意,第一个{"",0}请不要删除,格式:{"名字",课时数},字符都是英文字符,如:{"caixvkun",20}。
2、在创建完新用户后,请在while前int后加一句"n++;"。
3、该程序指令有"exit"、"find the user"、"display"、"deduction of class hours"和"fill the class time",如输入其余指令,皆视为无效指令,注意:指令均为小写。
*/
#include <bits/stdc++.h>
using namespace std;
struct Account{
string name;
int Class;
};
Account user[100000]={{"",0}};
int main(){
int n=0;
n++;
while(true){
string s;
cout<<"Please give instructions.\n";
getline(cin,s);
if(s=="exit"){
cout<<"End of program.";
return 0;
}
else{
if(s=="find the user"){
string x;
cout<<"Please enter the user you are looking for.\n";
getline(cin,x);
bool f=false;
for(int i=1;i<=n;i++){
if(user[i].name==x){
cout<<"remainder class:"<<user[i].Class<<"\n";
if(user[i].Class<=5){
cout<<"Please inform students to fill up the class in time.\n";
}
f=true;
break;
}
}
if(!f){
cout<<"The student was not found.\n";
}
}
else{
if(s=="display"){
int ma,t;
string x;
for(int i=1;i<=n-1;i++){
ma=i;
for(int j=i;j<=n;j++){
if(user[ma].Class>user[j].Class){
ma=j;
}
}
t=user[i].Class;
user[i].Class=user[ma].Class;
user[ma].Class=t;
x=user[i].name;
user[i].name=user[ma].name;
user[ma].name=x;
}
for(int i=1;i<=n;i++){
cout<<"name:"<<user[i].name<<" class:"<<user[i].Class<<"\n";
}
}
else{
if(s=="deduction of class hours"){
string x;
cout<<"Please enter the user whose hours you want to deduct.\n";
getline(cin,x);
bool f=false;
for(int i=1;i<=n;i++){
if(user[i].name==x){
user[i].Class--;
cout<<"remainder class:"<<user[i].Class<<"\n";
if(user[i].Class<=5){
cout<<"Please inform students to fill up the class in time.\n";
}
f=true;
break;
}
}
if(!f){
cout<<"The student was not found.\n";
}
}
else{
if(s=="fill the class time"){
string x;
int t;
cout<<"Please enter the user you want to recharge.\n";
getline(cin,x);
cout<<"Please enter the number of hours you would like to charge\n";
cin>>t;
cin.ignore();
bool f=false;
for(int i=1;i<=n;i++){
if(user[i].name==x){
user[i].Class+=t;
cout<<"remainder class:"<<user[i].Class<<"\n";
if(user[i].Class<=5){
cout<<"Please inform students to fill up the class in time.\n";
}
f=true;
break;
}
}
if(!f){
cout<<"The student was not found.\n";
}
}
else{
cout<<"The instruction is incorrect.\n";
}
}
}
}
}
}
return 0;
}