问题描述
- 求助 输入时程序崩溃 改了N小时还是问题不断
-
学生信息管理学生信息管理应用程序要求能够对学生的信息: StudentID, Name, Sex, Age, Time of Enrollment(入学时间), Gpa(加权平均), PhoneNo, MailingAddress, 等进行管理。
功能要求:
(1)Create a student list;
(2)Sort according to the StudentID;
(3)Insert a student;//(to the sorted array or the sorted linked list )
(4)Delete a student;
(5)Update a student Info;.
(6)Search a student ;
(7)Display all students;
*(8)Save to the file; //选作
*(9)Open the file; //选作
(10)exit设计要求:
(1)设计一个“Welcome Screen”,显示此应用程序的名称、设计人员的名字、设计时间、软件版本等信息;
(2)设计菜单界面,可以选择上述功能;
(3)每项功能完成后,返回菜单界面;
(4)用户可以退出;#include
#include
#include
#include
#define LEN sizeof(Student)
#includetypedef struct SIS { //结构体的声明
long StudentID; //学号
char Name[20]; //姓名
char Sex[10];//性别
int Age[10];//年龄
int TOE[30] ;//Time of Enrollment入学日期
float GPA[15];//(加权平均)
int PhoneNo[100]; //电话号码
char MailingAddress[100];//邮箱
struct SIS *next;//指向下一个结构体的指针
} Student;Student *head;
/////////////////////声明函数///////////////////////
void wellcome();//欢迎界面
void start();//开始界面
int menu();//菜单
int input();//输入/插入
int del();//删除
int search ();//查找
int ALL();//显示全部
///////////////////////////////////////////////////void wellcome() { //欢迎界面
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );printf("*************************************************n"); printf("*tt学生信息管理系统tt*n"); printf("*tttttt*n"); printf("*tttLAB 8ttt*n"); printf("*tttttt*n"); printf("*t 莱茵出品tt *n"); printf("*tttttt*n"); printf("*tttt2.33.vert*n"); printf("*tttttt*n"); printf("*tttttt*n"); printf("*************************************************n"); printf("%s", asctime (timeinfo)); printf("Please Press Enter to continue……");
}
void start() { //开始界面
int a=0;
int b=0;
int A=15080121;
getchar();
system("cls");
printf("nnn");
printf("tt学生信息管理系统nnn");
printf("ttt2.33.Vernnn");
getchar();
system("cls");
/* printf("tt请输入用户名和密码,按下Enter继续nnn");
printf("tAdmin:");
scanf("%d",&a);
printf("n");
printf("tPassword:");
scanf("%d",&b);
if(a==A&&b==A) {
getchar();
system("cls");
} else {
printf("ttt您没有足够的权限!!!!!nPlease Press Enter to EXIT……");
getchar();
exit(0);
}*/
}int menu() {//菜单
int shuru=0;
printf("nnn");
printf("tt (1)Create a student listn");
printf("tt (2)Insert a studentn");//(to the sorted array or the sorted linked list )
printf("tt (3)Delete a studentn");
printf("tt (4)Search a studentn");
printf("tt (5)Display all studentsn");
printf("tt (6)exitn");
printf("tt请选择功能:");
scanf("%d",&shuru);
return shuru;}
int input() {//输入、插入
Student *p1,*p2;
Student *student;
char a = 'y';
head = p2 = p1 ;system("cls"); student = (Student*) malloc (LEN); printf("t请按照要求输入n"); while(a=='y'||a=='Y') { p2=p1=head; printf("tStudentID:"); scanf("%d",student->StudentID); printf("t"); printf("Name:"); scanf("%s",student->Name); printf("t"); printf("Sex:"); scanf("%s",student->Sex); printf("t"); printf("Age:"); scanf("%d",student->Age); printf("t"); printf("TOE:"); scanf("%d",student->TOE); printf("t"); printf("GPA:"); scanf("%f",student->GPA); printf("t"); printf("PhoneNo:"); scanf("%d",student->PhoneNo); printf("t"); printf("MailingAddress:"); scanf("%s",student->MailingAddress); printf("nnnn"); student->next=NULL; fflush(stdin); if(head==NULL)head=student; else { while(p1->StudentID<student->StudentID&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(p1->StudentID>student->StudentID) if(p1==head) { student->next=head; head=student; } else { p2->next=student; student->next=p1; } else p1->next=student; } student = (Student *) malloc (LEN); printf("是否继续添加,输入'y'或'Y'继续n"); a=getchar(); fflush(stdin); } printf("ttt录入成功!n"); free(student); return 0;
}
int del() { //删除学生信息
Student *p1,*p2;
Student *student;
int tage = 0;
long StudentID;p1 = head; system("cls"); if (head == NULL) { printf("tt无学生信息!!!nPlease Press Enter to Return……"); return 0; } printf("tt请输入要删除的学生的学号: "); while(p1!=NULL) { if(p1->StudentID==StudentID) { tage=1; if(p1==head)head=head->next; else p2->next=p1->next; free(p1); break; } p1=p2; p2=p2->next; } if(tage==0) { printf("ttt信息不存在!n"); } tage=0; printf("ttt成功删除息n"); fflush(stdin); return 0;
}
int search () { //查询
Student *p1;
Student *student;
int tage = 0;
long StudentID;system("cls"); printf("请输入要查询的学生学号:"); scanf("%d",&StudentID); p1=head; if(head==NULL) { printf("无学生信息!n"); return 0; } else while(p1!=NULL) if(p1->StudentID==StudentID) { tage=1; printf("你查找的学生信息如下:n"); printf("ttStudentID:%dn",p1->StudentID); printf("ttName:%sn",p1->Name); printf("ttSex:%sn",p1->Sex); printf("ttAge:%dn",p1->Age); printf("ttTOE:%dn",p1->TOE); printf("ttGPA:%fn",p1->GPA); printf("ttPhonrNo:%dn",p1->PhoneNo); printf("ttMailingAddress:%sn/n/n",p1->MailingAddress); break; } else p1=p1->next; if(tage==0)printf("ttt无该学生信息!n"); tage=0; fflush(stdin); return 0;
}
int ALL() { //显示全部信息
Student *p1;
p1 = head;
system("cls");
if(head==NULL) {
printf("无学生信息!n");
return 0;
}
while(p1!=NULL) {
printf("ttStudentID:%dn",p1->StudentID);
printf("ttName:%sn",p1->Name);
printf("ttSex:%sn",p1->Sex);
printf("ttAge:%dn",p1->Age);
printf("ttTOE:%dn",p1->TOE);
printf("ttGPA:%fn",p1->GPA);
printf("ttPhonrNo:%dn",p1->PhoneNo);
printf("ttMailingAddress:%sn/n/n",p1->MailingAddress);
p1=p1->next;
}
return 0;
}main() {
int choose;
int x=1;
head=NULL;wellcome(); start(); while(x) { choose=menu(); switch(choose) { case 1: { input(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 2: { input(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 3: { del(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 4: { search(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 5: { ALL(); system("pause"); printf("Please Press Enter to Return……"); getchar(); system("cls"); break; } case 6: { exit(1); } default: { system("cls"); printf("nnnttt无此功能nnnn"); break; } } }
}
解决方案
你的结构体定义就有错误,输入时注意格式要对应:
long 对应%ld
字符数组对应%s
typedef struct SIS { //结构体的声明
long StudentID; //学号
char Name[20]; //姓名
char Sex[10];//性别
int Age;//年龄--------------年龄不应该定义int 数组
char TOE[30] ;//Time of Enrollment入学日期 ---------------定义为字符数组更好些?
float GPA[15];//(加权平均)----------------------这个也不该是数组吧?有15个?
char PhoneNo[100]; //电话号码---------------------改为char
char MailingAddress[100];//邮箱
struct SIS *next;//指向下一个结构体的指针
} Student;