- 论坛徽章:
- 0
|
正在作课程设计,第一次在linux下些程序,出现了点问题:断错误,不明白怎么回事,请高手帮一下
学生成绩管理系统 要求既能按学号排序又能按成绩排序
定义了一个学生类 class student
使用链表来存储学生信息,以学号为顺序
struct studensts mark[100]是按成绩排序
main函数有个选择,选3是添加学生信息,函数如下
//添加学生*********************************************************************
void add() {
int n;
char c, tmp[10];
student temp;
mark1: if(count < 100) {
temp.inputinfo();
if(count == 0) {
head = new (struct students);
head->stu = temp;
head->next = NULL;
mark[0] = head;
}
else {
pt = new (struct students);
pt->stu = temp;
p = head;
while (temp.id_get() < p->stu.id_get()) {
p1 = p;
p = p->next;
if (p == NULL)
break;
}
p1->next = pt;
p2 = p1->next;
p2->next = p;
n = 0;
while(temp.total_get() < mark[n]->stu.total_get()) {
n++;
}
for (int i = count + 1; i > n + 1; i--) {
mark = mark[i-1];
}
mark[n+1] = pt;
}
count++;
}
else {
cout<<"抱歉!只能储存100个学生的记录"<<endl;
return;
}
for(; {
cout<<"1.继续 2.返回"<<endl;
gets(tmp);
c = getchar();
if(c == '1') {
goto mark1;
}
else if(c == '2') {
return;
}
else {
cout<<"哥们呀,睁大你的眼睛好好看看!请选择1~2"<<endl;
}
}
}
运行:
lin@chenglin:~/myproject> gdb ./a.out
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-suse-linux"...
(gdb) r
Starting program: /home/lin/myproject/a.out
******************************************************
学生管理,请选择.........
1.按学号显示 2.按成绩显示 3.添加 4.删除
5.修改 6.从文件读取 7.输出到文件 8.退出
******************************************************
3
学号:0101
姓名:tom
math: 48
English: 93
computer: 89
1.继续 2.返回
1
学号:0102
姓名:john
math: 89
English: 49
computer: 98
Program received signal SIGSEGV, Segmentation fault.
0x0000000000401b22 in add ()
Current language: auto; currently asm
(gdb)
大家帮帮忙 |
|