【发布时间】:2018-10-18 11:30:35
【问题描述】:
请帮助解决这个问题。 这是一个简单的数据结构程序 在这个程序中,用户首先输入他想输入多少条记录,然后输入记录。输入记录后,他输入搜索和搜索数据。现在我只为搜索 No2 输入一个。在那之后,我会做其他人。 当我运行它并到达搜索功能时,它停止工作并因 Windows 错误而关闭。
其次,第一次输入数据时,循环第一次运行时不输入名称,而不是输入名称。
请帮助提前谢谢。
#include<conio.h>
#include<iostream>
#include<fstream>
#include<Windows.h>
#include<dos.h>
#include<cctype>
#include<sstream>
#include<string>
using namespace std;
bool check = true;
struct node //structure of node //
{
char name[20];
char ccode[20];
int marks;
float cgpa;
node *next;
}*head,*lastptr;
void add() //Adds record of student//
{
node *p;
p=new node;
cout<<"Enter name of student:"<<endl;
gets(p->name);
fflush(stdin);
cout<<"Enter cource code:"<<endl;
gets(p->ccode);
fflush(stdin);
cout<<"Enter Marks of student:"<<endl;
cin>>p->marks;
fflush(stdin);
cout<<"Enter CGPA of student:"<<endl;
cin>>p->cgpa;
fflush(stdin);
p->next=NULL;
if(check)
{
head = p;
lastptr = p;
check = false;
}
else
{
lastptr->next=p;
lastptr=p;
}
cout<<endl<<"Student's information saved Successfully";
getch();
}
void search() //searches record of student//
{
node *prev=NULL;
node *current=NULL;
char c_code[20];
cout<<"Enter Roll Number to search:"<<endl;
//c_code=getch();
gets(c_code);
fflush(stdin);
cout<<"hkjhk"<<c_code;
prev=head;
current=head;
while(current->ccode!=c_code)
{
prev=current;
current=current->next;
}
cout<<"\nname: ";
puts(current->name);
cout<<"\n Cource Code:";
cout<<current->ccode;
cout<<"\nMarks:";
cout<<current->marks;
cout<<"\nCGPA:";
cout<<current->cgpa;
getch();
}
int main()
{
int x;
system("cls");
cout<<"How many students you want to enter"<<endl;
cin>>x;
while(x>0){
add();
x--;
}
cout<<"\nwhat type of search you want to search select choice 1 ,2 3 \n";
int choice;
cout<<"1 search all student by cource code \n";
cout<<"2 search all student by marks \n";
cout<<"3 search all student by cgpa \n";
cin>>choice;
if(choice==1)
{
system("cls");
add();
}
else if(choice==2)
{
cout<<"fhghgf";
system("cls");
search();
}
else
{
}
getch();
}
【问题讨论】:
-
在调试器中运行,找出崩溃的地方。
-
可能是未捕获的异常或空指针。您可能可以从应用程序数据文件夹中挖掘崩溃报告,但我同意最好的办法是在调试器下运行。 (我猜你没有安装它,因为它没有在“停止工作”对话框中为你提供调试选项?你可以例如免费获得 Visual Studio Community。)
-
如何在调试器上运行
-
我正在使用 dev c++ 编辑器,但不了解调试器,请帮助我
-
您为什么要混合使用
cin和getch和fflush之类的输入法?你在学习 C++ 吗?这是别人教你的吗?
标签: c++ c data-structures linked-list