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

📄 add.cpp

📁 程序类型:学校人员管理系统 功能:具有查找、增、删、修改等功能。
💻 CPP
字号:
//添加数据
#include<iostream.h>
#include"main.h"
#include"classes.h"
void add()
{
	int choice;
	student*p=new student;
//	long num;
	//f.seekp(0,ios::end);		//读指针移到文件末尾
	//long posEnd=f.tellp();		//记录文件尾位置
	cout<<"添加数据\n";
	while(1)
	{
		cout<<"请键入操作选择\n"
			<<"1:学生类\t"
			<<"2:研究生类\t"
			<<"3:教师类\t"
			<<"4:教授类\t"
			<<"0:退出\n";
		cin>>choice;
		switch(choice)
		{
		case 1:	//追加学生类
			{
				fstream iof("student.dat",ios::binary|ios::in|ios::out);
				//if(iof){ofstream outfile;outfile.open("student.dat",ios::out);}
				fstream f;
			

	    		student stu;
 /*	            char temp[1000];
				int i=0,n=0;
				char t;
				cout<<"请输入代号(0~999999999999)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=12)
				{
					cout<<"请输入正确的代号!(0~999999999999)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<13;n++)
						stu.number[n]=temp[n];;
				};


				temp[1000];
				i=0,n=0;

				cout<<"请输入身份证号码"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=18)
				{
					cout<<"请输入正确的身份证号码!"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<19;n++)
						stu.idcard[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入姓名!"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=22)
				{
					cout<<"请输入姓名!"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.name[n]=temp[n];
				};


				temp[1000];
				i=0,n=0;

				cout<<"请输入性别(男按1、女按2)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(temp[0]!='1'&&temp[0]!='2'&&i>=2)
				{
					cout<<"请输入正确的性别(男按1、女按2)!"<<endl;
					t=getchar();
					while(t!='\n')
					{temp[i]=t;
					t=getchar();
					};
					for(n=0;n<2;n++)
						stu.sex[n]=temp[n];
				};
				if(stu.sex[0]='1')stu.sex={'男'};
					else stu.sex={'女'};


					temp[1000];
				i=0,n=0;

				cout<<"请输入出生日期"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=8)
				{
					cout<<"请输入正确的出生日期!"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					}
					for(n=0;n<9;n++)
						stu.birthday[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入政治面貌(党员按1、共青团员按2、群众按3、民主党派人士按4)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(temp[0]!='1'&&temp[0]!='2'&&temp[0]!='3'&&temp[0]!='4'&&i>=2)
				{
					cout<<"请输入政治面貌(党员按1、共青团员按2、群众按3、民主党派人士按4)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<2;n++)
						stu.politics[n]=temp[n];
				};
				if(stu.politics[0]='1'){stu.politics!={'党员'};}
				else if(stu.politics[0]='2'){stu.politics!={'共青团员'};}
				else if(stu.politics[0]='3'){stu.politics!={'群众'};}
				else {stu.politics!={'民主党派人士按'};}



				temp[1000];
				i=0,n=0;

				cout<<"请输入婚姻状况(未婚按1、已婚按2)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(temp[0]!='1'&&temp[0]!='2'&&i>=2)
				{
					cout<<"请输入婚姻状况(未婚按1、已婚按2)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					}
					for(n=0;n<5;n++)
						stu.marriage[n]=temp[n];
				};
				if(stu.marriage[0]='1')stu.marriage={'未婚'};
					else stu.marriage={'已婚'};



					temp[1000];
				i=0,n=0;

				cout<<"请输入学历"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=23-1)
				{
					cout<<"请输入学历"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.knowledge[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入职务"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=23-1)
				{
					cout<<"请输入职务"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.job[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入任职时间(年月日8位)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=22)
				{
					cout<<"请输入正确任职时间(年月日8位"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.worktime[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入状态(在校按1、离校按2)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(temp[0]!='1'&&temp[0]!='2'&&i>=1)
				{
					cout<<"请输入状态(在校按1、离校按2)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<2;n++)
						stu.state[n]=temp[n];
				};
				if(stu.state[0]='1')stu.state={'在校'};
					else stu.state={'离校'};



					temp[1000];
				i=0,n=0;

				cout<<"请输入入学时间(年月日8位)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=22)
				{
					cout<<"请输入正确的入学时间(年月日8位"<<endl;
					t=getchar();
					while(t!='\n')
					{temp[i]=t;
					t=getchar();
					};
					for(n=0;n<;n++)
						stu.wentertime[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入学制(年)"<<endl;
				t=getchar();


				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=1)
				{
					cout<<"请输入正确的学制(年)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.educationalsystem[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;

				cout<<"请输入所在学院"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=23-1)
				{
					cout<<"请输入所在学院"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.institute[n]=temp[n];
				};


				temp[1000];
				i=0,n=0;

				cout<<"请输入所在专业"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=23-1)
				{
					cout<<"请输入所在专业"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.grade[n]=temp[n];
				};



				temp[1000];
				i=0,n=0;


				cout<<"请输入年级(大一按1、大二按2、大三按3、大四按4、大五按5)"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(temp[0]!='1'&&temp[0]!='2'&&temp[0]!='3'&&temp[0]!='4'&&temp[0]!='5'&&i>=1)
				{
					cout<<"请输入年级(大一按1、大二按2、大三按3、大四按4、大五按5)"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<2;n++)
						stu.grade[n]=temp[n];
				};
				if(stu.grade[0]='1'){stu.grade!={'大一'};}
				else if(stu.grade[0]='2'){stu.grade!={'大二'};}
				else if(stu.grade[0]='3'){stu.grade!={'大三'};}
				else if(stu.grade[0]='3'){stu.grade!={'大四'};}
				else {stu.grade[0]={'大五'};}



				temp[1000];
				i=0,n=0;
				cout<<"请输入自然班!"<<endl;
				t=getchar();
				while(t!='\n')		
				{
					temp[i]=t;++i;
					t=getchar();
				};
				while(i>=2)
				{
					cout<<"请输入自然班!"<<endl;
					t=getchar();
					while(t!='\n')
					{
						temp[i]=t;
						t=getchar();
					};
					for(n=0;n<;n++)
						stu.theclass[n]=temp[n];
				};
				

*/				

				f.write((char*)&stu,sizeof(250));	//写入文件
				iof.close();
				break;
			};						
				
				


		case 2:	//追加研究生类
			{
				fstream iof("graduatestudent.dat",ios::binary|ios::in|ios::out);
				//if(iof){ofstream outfile;outfile.open("graduatestudent.dat",ios::out);}
				fstream f;
				graduatestudent gadd;
				//输入

				
				
				
				
				
				
				
				

				f.write((char*)&gadd,sizeof(290));	//写入文件
				iof.close();
				break;
			};
		case 3:	//追加教师类
			{
				fstream iof("teacher.dat",ios::binary|ios::in|ios::out);
				//if(iof){ofstream outfile;outfile.open("teacher.dat",ios::out);}
				fstream f;
				teacher tadd;
				//输入

				
				
				
				
				
				
				
				

				f.write((char*)&tadd,sizeof(240));	//写入文件
				iof.close();
				break;
			};
		case 4:	//追加教授类
			{
				fstream iof("doctor.dat",ios::binary|ios::in|ios::out);
				//if(iof){ofstream outfile;outfile.open("doctor.dat",ios::out);}
				fstream f;
				doctor dadd;
				//输入

				
				
				
				
				
				
				
				

				f.write((char*)&dadd,sizeof(270));	//写入文件
				iof.close();
				break;
			};
		case 0:return;
		}
}
}



⌨️ 快捷键说明

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