自动扣课系统

/*程序使用方法: 
  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;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值