注册 登录
编程论坛 C++教室

请找出错误

rogergao123 发布于 2007-09-19 08:43, 387 次点击
#include<iostream>
#include<string>
using namespace std;
struct Student{
int num;
string name;
char sex;
float score;
}
void main()
{

cout<<"num is"<<endl;
cout<<"name is"<<endl;
cout<<"sex is"<<endl;
cout<<"score is"<<endl;
Student stu;
Student *p=&stu;
cin>>(*p).num>>(*p).name>>(*p).sex>>(*p).score;
cout<<(*p).num<<" "<<(*P).name<<" "<<(*p).sex<<" "<<(*p).score<<endl;




#define NULL 0
#include<iostream>
using namespace std;
struct Student{

long num;
float score;
struct Student *next;
}
int main()
{
Student a,b,c,*head,*p;
a.num=31001;a.score=39.5;
b.num=31003;b.score=90;
c.num=31007;c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do
{cout<<p->num<<" "<<p->score<<endl;}
p=p->next;
while
p!=NULL;
return 0;
}
}

我是菜鸟,请问这两则程序哪里错了
1 回复
#2
踏魔狼2007-09-19 12:15

#include <iostream>
#include <string.h>

using namespace std;

typedef struct Student{
int num;
string name;
char sex[12];
float score;
} Student;

int main()
{
Student stu;
cout<<"num is ";
cin>>stu.num;
cout<<"name is ";
char str[256];
cin>>str;
stu.name=str;
cout<<"sex is ";
cin>>stu.sex;
cout<<"score is ";
cin>>stu.score;

cout<<stu.num<<"\t"<<stu.name.c_str()<<"\t"<<stu.sex<<"\t"<<stu.score<<endl;
return 0;
}


#define NULL 0
#include<iostream>
using namespace std;

typedef struct Student
{
long num;
float score;
Student *next;
} Student;

int main()
{
Student a,b,c,*head,*p;
a.num=31001;a.score=39.5;
b.num=31003;b.score=90;
c.num=31007;c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do
{
cout<<p->num<<" "<<p->score<<endl;
}
while ((p=p->next) != NULL);

return 0;
}

1