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

📄 学生选课系统.cpp

📁 这是一个很小的学生成绩管理系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}
	fout.close();
}
//*********************************************************************
void CLand::Writef1(char *fp)
{
	ofstream fout(fp,ios::app);
	if (!fout)
	{
		cout<<"文件不能打开"<<endl;
	}
	else
	{
		fout<<endl;
		fout<<teacher.m_ctno<<setw(20)<<m_ctcode;
	}
	fout.close();
}
//*********************************************************************
void CLand::Writef2(char *fp)
{
	ofstream fout(fp);
	if (!fout)
	{
		cout<<"文件不能打开"<<endl;
	}
	else
	{
		fout<<endl;
		fout<<m_cadmin<<setw(20)<<m_cadmincode;
	}
	fout.close();
}
//*********************************************************************
void CLand::Readf(char *fp)
{
	ifstream fin(fp);
	if (!fin)
	{
		cout<<"文件不能打开"<<endl;
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>stu.m_csno>>m_cscode;
	} 
	fin.close();    
}
//*********************************************************
void CLand::Readf1(char *fp)
{
	ifstream fin(fp);
	if (!fin)
	{
		cout<<"文件不能打开"<<endl;
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>teacher.m_ctno>>m_ctcode;
	} 
	fin.close();    
}
//*********************************************************************
void CLand::Readf2(char *fp)
{
	ifstream fin(fp);
	if (!fin)
	{
		cout<<"文件不能打开"<<endl;
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>m_cadmin>>m_cadmincode;
	} 
	fin.close();    
}
//*********************************************************************
char* CLand::Queryf(char *fp)
{
	int c=0,d=0,_f=0,n=0,flag=0;
	char _e[20],sno[20],scode[20];
    ifstream fin(fp);    
	while(c<=2)
	{
		strcpy(sno,Setsno());
	    fin.close();
		fin.clear();
		fin.open("student.txt");
        if (!fin)
		{
		  cout<<"\n\n\n\n\t\t你的用户名不存在!"<<endl;
		  cout<<"\t\t你可能是还没有注册,请你先到管理员处注册!"<<endl;
		  cout<<"\t\t请按任意键继续!";
		  getch();
		  system("cls");
		  handle_Memu1();
		}
	    fin.get();
		fin.close();
		fin.clear();
		fin.open("student.txt");
	    while (!fin.eof())
		{
			fin>>stu.m_csno>>stu.m_csname>>stu.m_csex>>stu.m_cbanji>>stu.m_czhuanye
				>>stu.m_imaxcourse>>stu.m_ifactcourse;
			if (strcmp(stu.m_csno,sno)==0)
			{ 
				flag=1;		    	            
				strcpy(_e,sno);
				while(d<=2)
				{
					cout<<"\n\t\t\t你的初始密码为你的学号"<<endl;
					cout<<"\n\t\t\t请你及时修改你的密码"<<endl;
					cout<<"\n\t\t\t请输入你的密码按回车键确认:";
					strcpy(scode,Setscode());
					fin.close();
					fin.clear();
					fin.open("scode.txt");
					if (!fin)
					{
						if(strcmp(_e,scode)==0)
						{
							Writef("scode.txt");
							handle_Memu3();
						}
						system("cls");
						d++;
						cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
						if(d>=3)
						{
							system("cls");
							cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
							exit(0);
						}
						strcpy(scode,Setscode());
					}
					fin.get();
					while (!fin.eof())
					{
						fin>>stu.m_csno>>m_cscode;
						if(strcmp(m_cscode,scode)==0)
						{
							handle_Memu3();
						}
						else
						{
							if(strcmp(_e,scode)==0)
							{
								//Writef("scode.txt");
								handle_Memu3();
							}
						}
					}
					system("cls");
					d++;
					cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
					if(d>=3)
					{
						system("cls");
						cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
						exit(0);
					}
				}
				break;
			}
		}
		if(!flag)
		{
		c++;
		system("cls");
		cout<<"\n\n\n\n\t\t你的用户名输入错误!"<<endl;
		}
    	if(c>=3)
		{
			system("cls");
			cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
	    	exit(0);
		} 
	}
	fin.close();  
    return NULL;
} 
//********************************************************************
char* CLand::Queryf1(char *fp)
{
	int c=0,d=0,_f=0,n=0,flag=0;
	char _g[20],tcode[20],tno[20];
    ifstream fin(fp);    
	while(c<=2)
	{
        strcpy(tno,Settno());
		fin.close();
		fin.clear();
		fin.open("teacher.txt");
        if (!fin)
		{
			cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
			cout<<"\t\t您可能是还没有注册,请您先到管理员处注册!"<<endl;
			cout<<"\t\t请按任意键继续!";
			getch();
			system("cls");
			handle_Memu1();
		}
		fin.get();
		fin.close();
		fin.clear();
		fin.open("teacher.txt");
		while (!fin.eof())
		{
			fin>>teacher.m_ctno>>teacher.m_ctname>>teacher.m_ctxi>>
				teacher.m_ctsex>>teacher.m_ctzhicheng;
			if (strcmp(teacher.m_ctno,tno)==0)
			{ 	
				flag=1;
				strcpy(_g,tno);
				while(d<=2)
				{
					cout<<"\n\t\t\t您的初始密码为您的编号"<<endl;
					cout<<"\n\t\t\t请您及时修改您的密码"<<endl;
					cout<<"\n\t\t\t请输入您的密码按回车键确认:";
					strcpy(tcode,Settcode());
					fin.close();
					fin.clear();
					fin.open("tcode.txt");
					if (!fin)
					{
						if(strcmp(_g,tcode)==0)
						{
							Writef1("tcode.txt");
							handle_Memu4();
						}
						system("cls");
						d++;
						cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
						if(d>=3)
						{
							system("cls");
							cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
							exit(0);
						}
						strcpy(tcode,Settcode());
					}
					fin.get();
					while (!fin.eof())
					{
						fin>>teacher.m_ctno>>m_ctcode;
						if(strcmp(m_ctcode,tcode)==0||strcmp(_g,tcode)==0)
						{
							//Writef1("tcode.txt");
							handle_Memu4();
						}
					}
					system("cls");
					d++;
					cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
					if(d>=3)
					{
						system("cls");
						cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
						exit(0);
					}
				}
				break;
			}
			if(!flag)
			{
				c++;
				system("cls");
				cout<<"\n\n\n\n\t\t您的用户名输入错误!"<<endl;				
			}
			if(c>=3)
			{
				system("cls");
				cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
				exit(0);
			}
		}
		
	}
	fin.close();
	return NULL;
}
//********************************************************************
char* CLand::Queryf2(char *fp)
{
	int c=0,d=0,_f=0,n=0,flag=0;
	char admin[20],admincode[20];
    ifstream fin(fp); 
	fin.close();
	fin.clear();
	fin.open("admin.txt");
    if (!fin)
	{
			system("cls");
			cout<<"\n\n\n\n\t\t\t欢迎您进入课程管理端\n";
			cout<<"\n\t\t\t您的用户名为admin"<<endl;
			while(c<=2)
			{
				strcpy(admin,Setadmin());
				if(strcmp("admin",admin)==0)
				{
					flag=1;
					while(d<=2)
					{
						cout<<"\n\t\t\t您的初始密码为admin"<<endl;
						cout<<"\n\t\t\t请您及时修改您的密码"<<endl;
						cout<<"\n\t\t\t请输入您的密码并按回车键确认:";
						strcpy(admincode,Setadmincode());
						if(strcmp("admin",admincode)==0)
						{
							Writef2("admin.txt");
							handle_Memu5();
						}
						else
						{
							system("cls");
							d++;
							cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
						}
						if(d>=3)
						{
							system("cls");
							cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
							exit(0);
						}
					}
				}
				if(!flag)
				{
					c++;
					system("cls");
					cout<<"\n\n\t\t\t用户名输入错误!请重新输入!\n"<<endl;
				}
				if(c>=3)
				{
					system("cls");
					cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
					exit(0);
				}
			}
	}
	fin.get();
	while(c<=2)
	{
		strcpy(admin,Setadmin());
		fin.close();
	    fin.clear();
	    fin.open("admin.txt");
		while (!fin.eof())
		{
			fin>>m_cadmin>>m_cadmincode;
			if (strcmp(m_cadmin,admin)==0)
			{ 	
				flag=1;
				while(d<=2)
				{
					cout<<"\n\t\t\t您的初始密码为admin"<<endl;
					cout<<"\n\t\t\t请你及时修改你的密码"<<endl;
					cout<<"\n\t\t\t请输入你的密码并按回车键确认:";
					strcpy(admincode,Setadmincode());
					ifstream fin(fp);
					fin.close();
					fin.clear();
					fin.open("admin.txt");
					if (!fin)
					{
						cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
						exit(0);
					}
					fin.get();
					while (!fin.eof())
					{
						fin>>m_cadmin>>m_cadmincode;
						if(strcmp(m_cadmincode,admincode)==0)
						{
							//Writef("admin.txt");
							handle_Memu5();
						}
					}
					system("cls");
					d++;
					cout<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
					if(d>=3)
					{
						system("cls");
						cout<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
						exit(0);
					}
				}
			}
		}
		if(!flag)
		{
			c++;
			system("cls");
			cout<<"\n\n\n\n\t\t您的用户名输入错误!"<<endl;	
		}
		if(c>=3)
		{
			system("cls");
			cout<<"\n\n\t\t\t用户名输入错误超过三次!请按任意键退出.."<<endl;
			exit(0);
		}
	}
	fin.close();
	return NULL;
}
//********************************************************************
void CLand::modifiy(char *fp)
{
	char sno[20];
	int c=0,d=0,_f=0,n=0,flag=0;
	char scode[20];
    cout<<"\n\t\t\t请输入你的用户名按回车键确认:";
    cin>>sno;
	ifstream fin(fp);
	fin.close();
	fin.clear();
	fin.open("student.txt");
    if (!fin)
	{
		cout<<"\n\n\n\n\t\t你的用户名不存在!"<<endl;
		cout<<"\t\t你可能是还没有注册,请你先到管理员处注册!"<<endl;
		cout<<"\t\t请按任意键继续!";
		getch();
		system("cls");
		handle_Memu1();
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>stu.m_csno>>stu.m_csname>>stu.m_csex>>stu.m_cbanji>>stu.m_czhuanye
			>>stu.m_imaxcourse>>stu.m_ifactcourse;
		if(strcmp(stu.m_csno,sno)==0)
		{
			cout<<"\n\t\t\t请输入你的旧密码并按回车键确认:";
			cin>>scode;			
			fin.close();
			fin.clear();
			fin.open("scode.txt");
			if (!fin)
			{
				cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
				exit(0);
			}
			fin.get();
			while (!fin.eof())
			{
				fin>>stu.m_csno>>m_cscode;
				if(strcmp(m_cscode,scode)==0)
				{
					cout<<"\n\t\t\t请输入你的新密码并按回车键确认:";
					strcpy(scode,Setscode());
					cout<<"\n\t\t\t请再次输入你的新密码并按回车键确认:";
					if(strcmp(scode,Setscode())==0)
					{
						Writef("scode.txt");
						cout<<"修改密码成功!";
						return;
					}
					else
						cerr<<"新密码输入不一致!";
				}
				else					
					cerr<<"旧密码输入错误!";				
			}				
		}
		else
			cerr<<"用户名输入错误!";
	}
	fin.close();
}
//********************************************************************
void CLand::modifiy1(char *fp)
{
	char admin[20],admincode[20];
	ifstream fin(fp);
    cout<<"\n\t\t\t请输入你的用户名按回车键确认:";
    cin>>admin;
	fin.close();
	fin.clear();
	fin.open("admin.txt");
	if (!fin)
	{
		cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
		exit(0);
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>m_cadmin>>m_cadmincode;
		if(strcmp(m_cadmin,admin)==0)
		{
			cout<<"\n\t\t\t请输入你的旧密码并按回车键确认:";
			cin>>admincode;			
			fin.close();
			fin.clear();
			fin.open("admin.txt");
			if (!fin)
			{
				cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
				exit(0);
			}
			fin.get();
			while (!fin.eof())
			{
				fin>>m_cadmin>>m_cadmincode;
				if(strcmp(m_cadmincode,admincode)==0)
				{
					cout<<"\n\t\t\t请输入你的新密码并按回车键确认:";
					strcpy(admincode,Setadmincode());
					cout<<"\n\t\t\t请再次输入你的新密码并按回车键确认:";
					if(strcmp(admincode,Setadmincode())==0)
					{
						Writef2("admin.txt");
						cout<<"修改密码成功!";
						return;
					}
					else
						cerr<<"新密码输入不一致!";
				}
				else
					cerr<<"旧密码输入错误!";
			}
		}
		else
			cerr<<"用户名输入错误!";
	}
	fin.close();
}
//********************************************************************
void CLand::modifiy2(char *fp)
{
	char tno[20];
	int c=0,d=0,_f=0,n=0,flag=0;
	char tcode[20];
    cout<<"\n\t\t\t请输入您的用户名按回车键确认:";
    cin>>tno;
	ifstream fin(fp);
	fin.close();
	fin.clear();
	fin.open("teacher.txt");
    if (!fin)
	{
		cout<<"\n\n\n\n\t\t您的用户名不存在!"<<endl;
		cout<<"\t\t您可能是还没有注册,请您先到管理员处注册!"<<endl;
		cout<<"\t\t请按任意键继续!";
		getch();
		system("cls");
		handle_Memu1();
	}
	fin.get();
	while (!fin.eof())
	{
		fin>>teacher.m_ctno>>teacher.m_ctname>>teacher.m_ctxi>>teacher.m_ctsex>>teacher.m_ctzhicheng;
		if(strcmp(teacher.m_ctno,tno)==0)
		{
			cout<<"\n\t\t\t请输入您的旧密码并按回车键确认:";
			cin>>tcode;			
			fin.close();
			fin.clear();
			fin.open("tcode.txt");
			if (!fin)

⌨️ 快捷键说明

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