⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kesheguanli.cpp

📁 这是我大一暑假的课设作业。。做的通讯录。。。喜欢跟大家交流~~
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

void ret2MainInterface()    //返回主界面
{
	system("cls");
	mainInterface();
}




//--------------------------------------------------------------------------------sqq

bool removeInMemsqq(struct record* arr, int size, char *sno);
void studentInter();
bool checkID(char sno[100]);
bool checkPassword(char pw[8],char sno[100]);
void changeCode(char pw[8],char sno[100]);
void studentInterface();
void loadData();
void printStudent();
void addClass();
void check(int No);
void deleteClass();
void decheck(int No);
void savedata(int time[5][6]);
void savedata();

char id[100];


bool removeInMemsqq(struct record* arr, int size, char *sno)
{
	int i;
	for(i=0; i<size; i++)
	{
		if(strcmp(arr[i].sno, sno)==0)
		{
			//execute remove
				int j;
			    for(j=i+1; j<size; j++)
				{
			    	arr[j-1]=arr[j];
				}
		    	return true;
		}
	}
	return false;
}



void student()
{

	while(1)
	{
    	system("cls");	
		int i;
		cout<<"输入 ID :";

		//check ID, wrong 3 times(back)
    	for(i=0; i<3; i++)
		{
			system("cls");
		    cin>>id;
			if(checkID(id)==1)
			{
				studentInter();
				break;
			}
			else if(i==2)
			{
				cout<<"ID输错3次,返回主界面"<<endl;
		        system("pause");
		        system("cls");
		        mainInterface();
	        	return;
			}
			else cout<<"ID错误,输入ID:";
		}
	}
}


void studentInter()
{
	char *inputPW;	
	system("cls");
	cout<<id<<"请输入密码: "<<endl;
	int i;

	//check code, wrong 3 times(back)
	for(i=0; i<3; i++)
	{
		inputPW=inputPassword();
		if(checkPassword(inputPW,id)==1)
		{
			//change code
			cout<<"登录成功,修改密码吗?(y/n)"<<endl;
			char a;
			cin>>a;
			if(a=='n')
			{
				cout<<"输入任意键进入系统..."<<endl;
	     	    getch();
			    studentInterface();
			}
			else
			{
				char b[100],pass[8];
				do
				{
					system("cls");
					cout<<"输入新密码(8位)";
				    cin>>b;
				}
				while(strlen(b)!=8);
				strcpy(pass,b);

				//save new code
				changeCode(pass,id);

				cout<<"密码更改成功,进入系统(y)还是返回主界面(n)?";
				cin>>a;
				if(a=='y')
				{
				    cout<<"输入任意键进入系统..."<<endl;
	     	        getch();
			        studentInterface();
				}
				else
				{
					system("cls");
					mainInterface();
				}
			}
		}
		system("cls");
		cout<<"密码输入错误,请重新输入:"<<endl;
	}

	if(i==3)
	{
		cout<<"密码输错3次,自动返回主界面"<<endl;
		system("pause");
		system("cls");
		mainInterface();
		return;
	}

}


bool checkPassword(char pw[8],char sno[100])
{
	//load information into the memory
	struct record *arr;
	int amount=loadDate(&arr);

	int i;
	for(i=0; i<amount; i++)
	{
		if(strcmp(arr[i].sno,sno)==0&&strcmp(arr[i].pw,pw)==0)//id and code suit
		{
			break;
		}
	}
	if(i==amount) return 0;
	return 1;
}






bool checkID(char sno[100])
{
	//load information into the memory
	struct record *arr;
	int amount=loadDate(&arr);

	int i;
	for(i=0; i<amount; i++)
	{
		if(strcmp(arr[i].sno, sno)==0)//id and sno suit
		{
			break;
		}
	}
	if(i==amount) return 0;
	return 1;
}

void changeCode(char pw[8],char sno[100])
{
	struct record *arr;
	int amount=loadDate(&arr);
	int i,num=0;

	for(i=0; i<amount; i++)
	{		
		if(strcmp(arr[i].sno, sno)==0)//sno suit
			break;
		num += strlen(arr[i].sno);
	}

	fstream file(FILENAME, ios::out|ios::in);
	int a=10 + 21*i + num + strlen(arr[i].sno) + 1;//seek the place
	file.seekp(a);
	file.write(pw,8);
	file.close();

}




int chooseclass[6]={0};  //save student's class,choosed 1,not 0
int countPeople[6]={0};  //poople's amount for each class
int countClass=0;        //class amount for the student
int time[5][6]={0};      //five day,four class each
char className[6][10]={"",
                       " Computer",
                       "  Maths  ",
					   " Physics ",
					   "   P.E   ",
					   " English "};
int classTime[6][3]={{0,0,0},{22,15,0},{12,43,25},{42,24,0},{22,0,0},{11,0,0}};//time for class




void studentInterface()
{
	loadData();
	int choose=0;
	while(1)
	{		
		printStudent();
		cin>>choose;
		switch(choose)
		{
		case 1:
			addClass();break;
		case 2:
			deleteClass();
			system("pause");
			break;
		case 3:
			savedata();
			if(ofstream)			
				cout<<"存档成功!"<<endl;
			system("pause");
			break;
		case 4:
			ret2MainInterface();
			return;
		}			
	}
}


void loadData()
{
	char sno[100];
	strcpy(sno,id);

	//load information into the memory
	struct record *arr;
	int amount=loadDate(&arr);
	int i,j;

	//initialize
	for(i=0;i<6;i++)
		countPeople[i]=0;
	for(i=0;i<5;i++)
		for(j=0;j<6;j++)
			time[i][j]=0;
	countClass=0;
		
	//count student who choose each class
	for(i=0; i<amount; i++)
	{
		if(strcmp(arr[i].sno, sno)==0)
		{
			for(j=0; j<5; j++)
			{
				chooseclass[j+1]=arr[i].mark[j];
				if(chooseclass[j+1]!=0)
				{
					countPeople[j+1]++;
					countClass++;//student's countClass +1

					//load time
					for(int k=0;k<3&&classTime[j+1][k]!=0;k++)
					{
						int a=classTime[j+1][k];
				        time[a/10][a%10]=j+1;//put classNo in timetable
					}
				}
			}
		}
		else
		{
			for(j=0; j<5; j++)
			{
				chooseclass[j+1]=arr[i].mark[j];
				if(chooseclass[j+1]!=0)
					countPeople[j+1]++;
			}
		}

	}
}



void printStudent()
{
	system("cls");

	cout<<"1.Computer 已选人数:"<<countPeople[1]<<endl
		<<"2.Maths    已选人数:"<<countPeople[2]<<endl
		<<"3.Physics  已选人数:"<<countPeople[3]<<endl
		<<"4.P.E      已选人数:"<<countPeople[4]<<endl
		<<"5.English  已选人数:"<<countPeople[5]<<endl;

	//draw timetable
	cout<<"┏━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━┓"<<endl;
	cout<<"┃时间/星期 ┃    一    ┃    二    ┃    三    ┃    四    ┃    五    ┃"<<endl;

	for (int i=1;i<=4;i++)
	{
		cout<<"┣━━━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━┫"<<endl;
		cout<<"┃"<<setw(4)<<i<<"节"<<setw(6);

		for(int j=1;j<=5;j++)
		{
			if(time[i][j]==0)
				cout<<"┃"<<setw(10)<<"";
			else
				cout<<"┃"<<setw(10)<<className[(time[i][j])];
		}

		cout<<"┃\n";
	}
	cout<<"┗━━━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━┛"<<endl;

	cout<<"1.选课"<<endl;
	cout<<"2.退课"<<endl;
	cout<<"3.保存"<<endl;
	cout<<"4.退出"<<endl;

}

void addClass()
{
	int classNo;
	cout<<"请输入所选课程编号";
	cin>>classNo;
	check(classNo);

}

void check(int No)
{
	int i,flag=0;

	//check timetable
	for(i=0;i<3&&classTime[No][i]!=0;i++)
		{
			int a=classTime[No][i];
			if(time[a/10][a%10]!=0)
				flag=1;
		}

	if(countPeople[No]+1>10)
		cout<<"所选课程人数已满!"<<endl;

	else if(countClass+1>3)
		cout<<"所选课程总数已满!"<<endl;

	else if(flag==1)
		cout<<"所选课程与已选课程时间冲突!"<<endl;

	else 
	{
		chooseclass[No]=1;
		countPeople[No]++;
		countClass++;

		for(int j=0;j<3&&classTime[No][j]!=0;j++)
		{
				int a=classTime[No][j];
				time[a/10][a%10]=No;
		}
	}
	system("pause");
}


void deleteClass()
{
	int classNo;
	cout<<"请输入要删除的课程编号";
	cin>>classNo;
	decheck(classNo);
}

void decheck(int No)
{
	if(chooseclass[No]==0)   
	{
		cout<<"未选过该课程!"<<endl;
	}
	else 
	{
		cout<<"确认删除"<<className[No]<<"吗?(y/n)";
    	char a;
	    cin>>a;
	    if(a=='y')
		{
	    	chooseclass[No]=0;
	    	countPeople[No]--;
	    	countClass--;
			for(int j=0;j<3&&classTime[No][j]!=0;j++)
			{
				int a=classTime[No][j];
				time[a/10][a%10]=0;
			}
		}
	}
}


void savedata()
{
	char sno[100];
	strcpy(sno,id);
	struct record *arr;
	int amount=loadDate(&arr);
	int i,num=0;

	for(i=0; i<amount; i++)
	{		
		if(strcmp(arr[i].sno, sno)==0)//sno suit
			break;
		num += strlen(arr[i].sno);
	}

	fstream file(FILENAME, ios::out|ios::in);
	int a=10 + 21*i + num + strlen(arr[i].sno) + 10;//seek the place
	char c[9];

	for(i=0;i<9;i++)
	{
		if(i%2)c[i]=' ';
		else c[i]=chooseclass[i/2+1]+'0';
	}

	file.seekp(a);
	file.write(c,9);
	file.close();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -