#include<iostream>#include<fstream>#include<cstring>usingnamespace std;char judge;char account[100], password_input[10], password_real[10];int num;char lessons[10][10]={{"Lessons"},{"C++"},{"Math"},{"English"},{"Physics"}};voidlimit_0_1(){while(judge !='1'&& judge !='0'){
cout <<"Warning! You can only choose 1 or 0 rather than any other words."<< endl;
cin >> judge;getchar();}}voidlimit_1_4(){while(judge !='1'&&judge !='2'&&judge !='3'&&judge !='4'){
cout <<"Warning! You can only choose 1, 2, 3 and 4 rather than any other words."<< endl;
cin >> judge;getchar();}}voidHello(){
cout <<"Hello, welcome to the course selection system of Umbrella Corporation."<< endl;
cout <<"Now, you can log in or sign in. 1/0?"<< endl;
cin >> judge;getchar();limit_0_1();}voidsign_in(char ch){
cout <<"Please input your account."<< endl;
cin.getline(account,101);
ofstream out(account, ios::out);if(ch =='1')
out <<"1"<< endl;elseif(ch =='0')
out <<"0"<< endl;
cout <<"Please input your password."<< endl;
cin.getline(password_real,101);
out << password_real << endl;
out.close();
cout <<"Congratulations! You have succeeded in signing in."<< endl;}voidadding_lesson(int a){if(a ==1){
cout <<"Please input the student's account who you want to manage."<< endl;
cin.getline(account,101);}
ofstream out(account, ios::app);
cout <<"Please tell me which lesson you want to choose. 1 is C++, 2 is Math, 3 is English and 4 is Physics."<< endl;
cin >> judge;getchar();limit_1_4();
out << lessons[judge -'0']<<"\n";
out.close();
cout <<"Congratulations! You have succeeded in adding the lesson."<< endl;}voiddeleting_lesson(int a){if(a ==0){
cout <<"Please tell me which lesson you want to delete. 1 is C++, 2 is Math, 3 is English and 4 is Physics."<< endl;
cin >> judge;getchar();limit_1_4();}elseif(a ==1){
cout <<"Please input the count of the student who you want to manage."<< endl;
cin.getline(account,101);
cout <<"Please tell me which lesson you want to delete. 1 is C++, 2 is Math, 3 is English and 4 is Physics."<< endl;
cin >> judge;getchar();limit_1_4();}
ifstream in(account, ios::in);char array[10][10], ch, p[10];int counter =0;
in >> ch >> p;while(in >> array[counter])
counter++;
in.close();bool temp =false;if(!counter){if(a ==1)
cout <<"Warning! This student haven't chosen any lessons."<< endl;elseif(a ==0)
cout <<"Warning! You haven't chosen any lessons."<< endl;return;}else{
ofstream out(account, ios::out);
out << ch << endl << p << endl;for(int i =0; i < counter; i++){if(strcmp(lessons[judge -'0'], array[i])!=0)
out << array[i]<< endl;else
temp =true;}
out.close();}if(temp)
cout <<"Congratulations! You have succeeded in deleting the lesson."<< endl;else
cout <<"Warning! The lesson dosn't exist."<< endl;}voidshowing_lessons(int a){if(a ==1){
cout <<"Please input the count of the student who you want to manage."<< endl;
cin.getline(account,101);}
ifstream in(account, ios::in);char showlessons[10][10], ch, __[10];int counter =0;
in >> ch >> __;while(in >> showlessons[counter])
counter++;
in.close();if(!counter){if(a ==1)
cout <<"Warning! This student hasn't chosen any lessons."<< endl;elseif(a ==0)
cout <<"Warning! You haven't chosen any lessons."<< endl;}else{if(a ==1)
cout <<"The lessons this student have chosen are ";elseif(a ==0)
cout <<"The lessons you have chosen are ";for(int i =0; i < counter; i++){
cout << showlessons[i];if(i != counter -1)
cout <<", ";else
cout <<"."<< endl;}}}intmain(){while(1){Hello();if(judge =='1')//登陆账号{
cout <<"Please tell me your identity. 1 is teacher and 0 is student."<< endl;
cin >> judge;getchar();limit_0_1();if(judge =='1')//教师登陆{
cout <<"Please input your account."<< endl;
cin.getline(account,101);
cout <<"Please input your password."<< endl;
cin.getline(password_input,101);
ifstream in(account, ios::in);char ch;
in >> ch >> password_real;if(ch !='1'){
cout <<"Warning! You have loged in illegally! The programming has been automatically end!"<< endl;return0;}while(strcmp(password_input, password_real)!=0){
cout <<"Your password is incorrect, you can input it again or quit. 1/0?"<< endl;
cin >> judge;getchar();limit_0_1();if(judge =='1'){
cout <<"Please input your password."<< endl;
cin.getline(password_input,101);}elseif(judge =='0')break;}if(strcmp(password_input, password_real)==0);{while(1){
cout <<"Welcome back! Please tell me what do you want to do? 1 is adding lesson, 2 is deleting lesson, 3 is showing lessons and 4 is quiting."<< endl;
cin >> judge;getchar();limit_1_4();if(judge =='1')adding_lesson(1);elseif(judge =='2')deleting_lesson(1);elseif(judge =='3')showing_lessons(1);elseif(judge =='4')break;}}}else//学生登陆{
cout <<"Please input your account."<< endl;
cin.getline(account,101);
cout <<"Please input your password."<< endl;
cin.getline(password_input,101);
ifstream in(account, ios::in);char ch;
in >> ch >> password_real;if(ch !='0'){
cout <<"Warning! You have loged in illegally! The programming has been automatically end!"<< endl;return0;}while(strcmp(password_input, password_real)!=0){
cout <<"Your password is incorrect, you can input it again or quit. 1/0?"<< endl;
cin >> judge;getchar();limit_0_1();if(judge =='1')
cin.getline(password_input,101);elseif(judge =='0')break;}if(strcmp(password_input, password_real)==0);{while(1){
cout <<"Welcome back! Please tell me what do you want to do? 1 is adding lesson, 2 is deleting lesson, 3 is showing lessons and 4 is quiting."<< endl;
cin >> judge;getchar();limit_1_4();if(judge =='1')adding_lesson(0);elseif(judge =='2')deleting_lesson(0);elseif(judge =='3')showing_lessons(0);elseif(judge =='4')break;}}}}else//注册账号{
cout <<"Please tell me you identity. 1 is teacher and 0 is student"<< endl;
cin >> judge;getchar();limit_0_1();if(judge =='1')//教师注册sign_in(judge);else//学生注册sign_in(judge);}
cout <<"Please tell me what do you want to do? 1 is continuing and 0 is quiting."<< endl;
cin >> judge;getchar();limit_0_1();if(judge =='0'){
cout <<"Thanks for your usage.";break;}}return0;}