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

📄 smsystem.c

📁 Linux环境下用C语言实现的学生管理系统
💻 C
📖 第 1 页 / 共 2 页
字号:
			if(record_pos>0){				pos=record_pos-cur_pos;				cur_pos--;				record_pos--;				setGUI(str,pos);			}			else if(record_pos==0){				record_pos=record_sum-1;				cur_pos=scr_sum-1;				setGUI(str,record_sum-scr_sum);			}										}	}	}void down(char * str){ //reaction to the down key	int i,pos;	//the sum of record less than the num of one screen can show	if(record_sum==0){		mvprintw(20,25,"Have no record!");	}	//when the sum of the record less than the sum of one screen can show				else if(record_sum<=scr_sum){		record_pos=(record_pos+1)%record_sum;		cur_pos=record_pos;		setGUI(str,0);	}	//when the sum of the record more than the sum of one screen can show				else{						if(cur_pos==scr_sum-1){//cursor is on the bottom			if(record_pos<record_sum-1){				record_pos++;				setGUI(str,record_pos-cur_pos);			}			else if(record_pos==record_sum-1){//point to the end of the record				record_pos=0;				cur_pos=0;				setGUI(str,record_pos);			}								}		else{//cursor is not on the bottom			if(record_pos<record_sum-1){				pos=record_pos-cur_pos;				record_pos++;				cur_pos++;				setGUI(str,pos);			}			//when the record pointer point to the last record			else if(record_pos==record_sum-1){				record_pos=0;				cur_pos=0;				setGUI(str,0);			}		}	}}void searchStudentInfo(){  //query student information	int pos;	readStudentRecord();	record_pos=0;	cur_pos=0;	//create framework	setGUI("Search Student Infomation",0);	char ch;	//reaction to the keyboard 	if(record_sum>0){	do{		ch=getch(); //read from keyboard		switch(ch){		case 'u':  //upper key			up("Search Student Infomation");			break;		case 'd': //down key			down("Search Student Infomation");			break;		}	}while(ch!=27);//press esc key to exit	}	else{		attrset(COLOR_PAIR(6));		mvprintw(22,30,"Have no record!");		getch();		refresh();	}}void delStudentInfo(){//delete the select student record		readStudentRecord();//read all the student record from the stored file	record_pos=0;	cur_pos=0;	int pos,i;	FILE *fp;	//create framework	setGUI("Delete Student Infomation",0);	char ch,sure;	//reaction to the keyboard 	do{	ch=getch(); //read from keyboard	if(record_sum>0){		switch(ch){		case 'u':  //upper key			up("Delete Student Infomation");			break;		case 'd': //down key			down("Delete Student Infomation");			break;		case '\r':  //press enter key,show the student information 			attrset(COLOR_PAIR(6));			mvprintw(22,23,"Are you sure to delete student %ld(y/n):",student[record_pos].sno);			echo();			scanw("%c",&sure);			noecho();			if(sure=='y'||sure=='Y') //delete one record			{						if(record_sum==1){// if the sum of the record is one					record_sum=0;					record_pos=0;					cur_pos=0;					setGUI("Have none student info!",0);				}				//if the sum of the record less than amount that one screen can show				else if(record_sum<7){ 					record_sum--;					//when the current position is on the end of the record					if(record_pos==record_sum){						record_pos--;						cur_pos--;					}					else{						//move record						for(i=record_pos;i<record_sum;i++)							student[i]=student[i+1];					}					setGUI("Del Student Info!",0);				}			//when the sum of the record more than the amount that on screen can show				else{					record_sum--;					//when the current position is at the head of the record					if(record_pos==0){						for(i=record_pos;i<record_sum;i++)							student[i]=student[i+1];						setGUI("Del Student Info",0);					}					else if(record_pos>0&&record_pos<record_sum){						for(i=record_pos;i<record_sum;i++)							student[i]=student[i+1];				//when the last record is showing on the bottom of the screen						if(record_pos-cur_pos+scr_sum-1==record_sum){							cur_pos++;							setGUI("Del Student Info",record_sum-scr_sum);						}						else							setGUI("Del Student Info",record_pos-cur_pos);					}					else{						record_pos--;						cur_pos=scr_sum-1;						setGUI("Del Student Info",record_sum-scr_sum);					}				}				//write to the file				fp=fopen("student.dat","w");				fwrite(student,sizeof(STUDENT),record_sum,fp);				fclose(fp);			}			break;		default: 			break;		}	}	else{		attrset(COLOR_PAIR(6));		mvprintw(22,30,"Have no record!");		refresh();	}	}while(ch!=27);//press esc key ,quit}void modifyStudentInfo(){  //amend the student info	readStudentRecord();	int pos,i;	STUDENT ptr;	FILE *fp;	char ch;	record_pos=0;	cur_pos=0;	//create framework	setGUI("Modify Student Infomation",0);	//reaction to the keyboard 	if(record_sum>0){ //when the sum of record more than 0	do{		int flag=0;					ch=getch(); //read from keyboard		ptr=student[record_pos];		switch(ch){		case 'u':  //upper key			up("Modify Student Infomation");			break;		case 'd': //down key			down("Modify Student Infomation");			break;		case '\r'://press enter key to ensure			do{				echo();				attrset(COLOR_PAIR(4));				move(22,22);				clrtoeol();				mvaddch(22,79,'*');				// give a tip to show how to operate				mvprintw(22,23,"Press z,n,a,s,c,e or m (esc to quit):");				refresh();							char change;				change=getch();				if(change==27)//press the key esc to exit					break;				else{				move(22,22);				clrtoeol();				mvaddch(22,79,'*');							switch(change){				case 'z': //amend the student's NO.					//attrset(COLOR_PAIR(6));					mvprintw(22,30,"Modify sno");					move(9,34+3);					refresh();					while(!scanw("%ld",&ptr.sno)){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(9,34+3);						refresh();					}					flag=1;					break;				case 'n': //amend the student's name					mvprintw(22,30,"Modify name");					move(11,37+strlen(student[record_pos].name));					refresh();					scanw("%s",ptr.name);						flag=1;					break;				case 'a': //amend the age of the student					mvprintw(22,30,"Modify age");					move(13,37);					refresh();					while(!scanw("%d",&ptr.age)){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(13,37);						refresh();					}					flag=1;					break;				case 's': //amend the sex of the student					mvprintw(22,30,"Modify sex");					move(15,42);					refresh();					scanw("%c",&ptr.sex);					while(ptr.sex!='f'&&ptr.sex!='m'){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(15,42);						refresh();						scanw("%c",&ptr.sex);					}					flag=1;					break;				case 'c': //amend the chinese score					mvprintw(22,30,"Modify chinese score");					move(17,48);					refresh();					while(!scanw("%d",&ptr.lesson.chinese_score)){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(17,48);						refresh();					}					flag=1;					break;				case 'e': //amend the english score					mvprintw(22,30,"Modify english score");					move(18,48);					refresh();					while(!scanw("%d",&ptr.lesson.english_score)){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(18,48);						refresh();					}					flag=1;					break;				case 'm': //amend the math score					mvprintw(22,30,"Modify math score");					move(19,46);					refresh();					while(!scanw("%d",&ptr.lesson.math_score)){						move(22,20);						clrtoeol();						mvaddch(22,79,'*');						mvprintw(22,28,"Input data format error!");						move(19,46);						refresh();					}					flag=1; //if somethig changed ,set the flag					break;				defaule:					break;				}				}				noecho();			}while(1);			char sure;			if(flag){//have something changed				move(22,22);				clrtoeol();				mvaddch(22,79,'*');				// make a sure				mvprintw(22,25,"Are you sure to change?(y/n)");				echo();				scanw("%c",&sure);				noecho();				if(sure=='y'||sure=='Y'){					student[record_pos]=ptr;					//store the change record to the file					fp=fopen("student.dat","w");					fwrite(student,sizeof(STUDENT),record_sum,fp);					fclose(fp);					move(22,22);					clrtoeol();					mvaddch(22,79,'*');					mvprintw(22,25,"Modify Successful!");				}			}			break;		default:			break;		}		setGUI("Modify Student Info",record_pos-cur_pos);	}while(ch!=27);//press esc key ,quit	}	else{//the sum of record is 0		attrset(COLOR_PAIR(6));		mvprintw(22,30,"Have no record!");		getch();		refresh();	}}int main(){	int choice;	student=(STUDENT *)malloc(20*sizeof(STUDENT));	while(1)	{		choice=mainGUI();		switch(choice){		case 0: //add a new student information			createStudentInfo();			break;		case 1: //delete the selected student information			delStudentInfo();						break;		case 2: //amend the selected student information			modifyStudentInfo();			break;		case 3: //see about the selected student information			searchStudentInfo();			break;		case 4: // exit the system			touchwin(stdscr);			endwin();			exit(0);		}	}	printf("Done!\n");	}

⌨️ 快捷键说明

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