
c++程序里有一条cin语句在运行时没有输入端口
#include<iostream>usingnamespacestd;#include<string.h>#include<malloc.h>typedefcharNa...
#include<iostream>
using namespace std;
#include<string.h>
#include<malloc.h>
typedef char Name;
typedef int Num;
typedef float Score;
typedef struct LNode
{
Name data1[10];
Num data2;
Score data3,data4;
struct LNode *next;
}LinkList;
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d);
void LocateElem(LinkList *L,Num a);
int main()
{
LinkList *h,*p,*s;
h=(LinkList *)malloc(sizeof(LinkList));
p=h;
cout<<"the number of students?"<<endl;
Num n,i;
Name a[10];
Num b;
Score c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList *)malloc(sizeof(LinkList));
cout<<"please input the message of the"<<i+1<<"student!"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"score1"<<" "<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
p->next=s;
p=s;
}
cout<<"please input the message of the one want to insert!,location,name,number,score1,score2"<<endl;
Name m[10];
Num z,g;
Score y,o;
cin>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please input the school number you want to search!";
int k;
cin>>k;
LocateElem(p,k);
return 0;
}
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d)
{
Num j=0;
LinkList *p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can not find the location!"<<endl;
else
{
s=(LinkList *)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert successfully!"<<endl;
}
}
void LocateElem(LinkList *L,Num a)
{
LinkList *p=L->next;
Num n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the one want to know is not exsit!"<<endl;
else
{
cout<<"the student is locate on "<<n<<endl;
}
}
运行看看就会发现问题了,在运行函数locateElem时,k无法输入,我们老师也没看出来,高手,看看吧,不胜感谢啊 展开
using namespace std;
#include<string.h>
#include<malloc.h>
typedef char Name;
typedef int Num;
typedef float Score;
typedef struct LNode
{
Name data1[10];
Num data2;
Score data3,data4;
struct LNode *next;
}LinkList;
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d);
void LocateElem(LinkList *L,Num a);
int main()
{
LinkList *h,*p,*s;
h=(LinkList *)malloc(sizeof(LinkList));
p=h;
cout<<"the number of students?"<<endl;
Num n,i;
Name a[10];
Num b;
Score c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList *)malloc(sizeof(LinkList));
cout<<"please input the message of the"<<i+1<<"student!"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"score1"<<" "<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
p->next=s;
p=s;
}
cout<<"please input the message of the one want to insert!,location,name,number,score1,score2"<<endl;
Name m[10];
Num z,g;
Score y,o;
cin>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please input the school number you want to search!";
int k;
cin>>k;
LocateElem(p,k);
return 0;
}
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d)
{
Num j=0;
LinkList *p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can not find the location!"<<endl;
else
{
s=(LinkList *)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert successfully!"<<endl;
}
}
void LocateElem(LinkList *L,Num a)
{
LinkList *p=L->next;
Num n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the one want to know is not exsit!"<<endl;
else
{
cout<<"the student is locate on "<<n<<endl;
}
}
运行看看就会发现问题了,在运行函数locateElem时,k无法输入,我们老师也没看出来,高手,看看吧,不胜感谢啊 展开
展开全部
程序出错了 改了好多 你自己对着看吧
主要问题是插入元素时指针指得不好
#include<iostream>
using namespace std;
#include<string.h>
#include<malloc.h>
typedef char Name;
typedef int Num;
typedef float Score;
typedef struct LNode
{
Name data1[10];
Num data2;
Score data3,data4;
struct LNode *next;
}LinkList;
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d);
void LocateElem(LinkList *L,Num a);
int main()
{
LinkList *h,*p,*s;
h=(LinkList *)malloc(sizeof(LinkList));
p=h;
p->next=NULL;
cout<<"the number of students?"<<endl;
Num n,i;
Name a[10];
Num b;
Score c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList *)malloc(sizeof(LinkList));
cout<<"please input the message of the"<<i+1<<"student!"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"score1"<<" "<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
}
cout<<"please input the message of the one want to insert!\nlocation,name,number,score1,score2"<<endl;
Name m[10];
Num z,g;
Score y,o;
cin>>g>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please input the school number you want to search!";
int k;
cin>>k;
LocateElem(p,k);
return 0;
}
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d)
{
Num j=0;
LinkList *p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can not find the location!"<<endl;
else
{
s=(LinkList *)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert successfully!"<<endl;
}
}
void LocateElem(LinkList *L,Num a)
{
LinkList *p=L->next;
Num n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the one want to know is not exsit!"<<endl;
else
{
cout<<"the student is locate on "<<n<<endl;
}
}
ps:你的程序风格不好 最好多加点注释 并且注意代码缩进和空格
主要问题是插入元素时指针指得不好
#include<iostream>
using namespace std;
#include<string.h>
#include<malloc.h>
typedef char Name;
typedef int Num;
typedef float Score;
typedef struct LNode
{
Name data1[10];
Num data2;
Score data3,data4;
struct LNode *next;
}LinkList;
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d);
void LocateElem(LinkList *L,Num a);
int main()
{
LinkList *h,*p,*s;
h=(LinkList *)malloc(sizeof(LinkList));
p=h;
p->next=NULL;
cout<<"the number of students?"<<endl;
Num n,i;
Name a[10];
Num b;
Score c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList *)malloc(sizeof(LinkList));
cout<<"please input the message of the"<<i+1<<"student!"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"score1"<<" "<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
}
cout<<"please input the message of the one want to insert!\nlocation,name,number,score1,score2"<<endl;
Name m[10];
Num z,g;
Score y,o;
cin>>g>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please input the school number you want to search!";
int k;
cin>>k;
LocateElem(p,k);
return 0;
}
void ListInsert(LinkList *&L,Num i,Name a[],Num b,Score c,Score d)
{
Num j=0;
LinkList *p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can not find the location!"<<endl;
else
{
s=(LinkList *)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert successfully!"<<endl;
}
}
void LocateElem(LinkList *L,Num a)
{
LinkList *p=L->next;
Num n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the one want to know is not exsit!"<<endl;
else
{
cout<<"the student is locate on "<<n<<endl;
}
}
ps:你的程序风格不好 最好多加点注释 并且注意代码缩进和空格
展开全部
程序出错了
改了好多
你自己对着看吧
主要问题是插入元素时指针指得不好
#include<iostream>
using
namespace
std;
#include<string.h>
#include<malloc.h>
typedef
char
Name;
typedef
int
Num;
typedef
float
Score;
typedef
struct
LNode
{
Name
data1[10];
Num
data2;
Score
data3,data4;
struct
LNode
*next;
}LinkList;
void
ListInsert(LinkList
*&L,Num
i,Name
a[],Num
b,Score
c,Score
d);
void
LocateElem(LinkList
*L,Num
a);
int
main()
{
LinkList
*h,*p,*s;
h=(LinkList
*)malloc(sizeof(LinkList));
p=h;
p->next=NULL;
cout<<"the
number
of
students?"<<endl;
Num
n,i;
Name
a[10];
Num
b;
Score
c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList
*)malloc(sizeof(LinkList));
cout<<"please
input
the
message
of
the"<<i+1<<"student!"<<endl;
cout<<"num"<<"
"<<"name"<<"
"<<"score1"<<"
"<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
}
cout<<"please
input
the
message
of
the
one
want
to
insert!\nlocation,name,number,score1,score2"<<endl;
Name
m[10];
Num
z,g;
Score
y,o;
cin>>g>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please
input
the
school
number
you
want
to
search!";
int
k;
cin>>k;
LocateElem(p,k);
return
0;
}
void
ListInsert(LinkList
*&L,Num
i,Name
a[],Num
b,Score
c,Score
d)
{
Num
j=0;
LinkList
*p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can
not
find
the
location!"<<endl;
else
{
s=(LinkList
*)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert
successfully!"<<endl;
}
}
void
LocateElem(LinkList
*L,Num
a)
{
LinkList
*p=L->next;
Num
n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the
one
want
to
know
is
not
exsit!"<<endl;
else
{
cout<<"the
student
is
locate
on
"<<n<<endl;
}
}
ps:你的程序风格不好
最好多加点注释
并且注意代码缩进和空格
改了好多
你自己对着看吧
主要问题是插入元素时指针指得不好
#include<iostream>
using
namespace
std;
#include<string.h>
#include<malloc.h>
typedef
char
Name;
typedef
int
Num;
typedef
float
Score;
typedef
struct
LNode
{
Name
data1[10];
Num
data2;
Score
data3,data4;
struct
LNode
*next;
}LinkList;
void
ListInsert(LinkList
*&L,Num
i,Name
a[],Num
b,Score
c,Score
d);
void
LocateElem(LinkList
*L,Num
a);
int
main()
{
LinkList
*h,*p,*s;
h=(LinkList
*)malloc(sizeof(LinkList));
p=h;
p->next=NULL;
cout<<"the
number
of
students?"<<endl;
Num
n,i;
Name
a[10];
Num
b;
Score
c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList
*)malloc(sizeof(LinkList));
cout<<"please
input
the
message
of
the"<<i+1<<"student!"<<endl;
cout<<"num"<<"
"<<"name"<<"
"<<"score1"<<"
"<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
}
cout<<"please
input
the
message
of
the
one
want
to
insert!\nlocation,name,number,score1,score2"<<endl;
Name
m[10];
Num
z,g;
Score
y,o;
cin>>g>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please
input
the
school
number
you
want
to
search!";
int
k;
cin>>k;
LocateElem(p,k);
return
0;
}
void
ListInsert(LinkList
*&L,Num
i,Name
a[],Num
b,Score
c,Score
d)
{
Num
j=0;
LinkList
*p=L,*s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can
not
find
the
location!"<<endl;
else
{
s=(LinkList
*)malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert
successfully!"<<endl;
}
}
void
LocateElem(LinkList
*L,Num
a)
{
LinkList
*p=L->next;
Num
n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the
one
want
to
know
is
not
exsit!"<<endl;
else
{
cout<<"the
student
is
locate
on
"<<n<<endl;
}
}
ps:你的程序风格不好
最好多加点注释
并且注意代码缩进和空格
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询