沪江小d在线翻译日语:有人会C++和C吗

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 11:22:39
# include<iostream.h>
# include<stdio.h>
struct list
{
char name[10];
char sex[5];
int age;
int room_num;
list *next;
};
list *head;
list *insert()
{
list *s,*p,*q;
s=new list;
cout<<"Please input your name!"<<endl;
gets(s->name);
cout<<"Please input your sex!"<<endl;
gets(s->sex);
cout<<"Please input your age!"<<endl;
cin>>s->age;
cout<<"Please input your room_num!"<<endl;
cin>>s->room_num;
s->next=NULL;
if (head==NULL)
{
head=s;
return(head);
}
if (head->room_num>s->room_num
{
s->next=head;
head=s;
return(head);
}
for(q=head, p=head->next;p;q=p,p=p->next)
{
if(p->room_num>s->room_num)
{
s->next=p;
q->next=s;
return(head);
}
if(q->room_num<s->room_num)
{
q->next=s;
return(head);
}
}
return(head);
}
void showlist(const list *head)
{
cout<<"Now the peoplt of the list are:"<<endl;
while(head)
{
cout<<"Name:"<<head->name<<"\t"<<"Sex:"<<head->sex<<"\t";
cout<<"Age:"<<head->age<<"\t"<<"room_num:"<<head->room_num<<endl;
head=head->next;
}
cout<<endl;
}
void main()
{ char key;
double a;
head=NULL;
cout<<"Would you like to input the information of a person?(Y/N)"<<endl;
cin>>key;
while(key=='y'||key=='Y')
{
head=insert();
cout<<"Would you like to input the information of a person?(Y/N)"<<endl;
cin>>key;
}
if(head)
{
showlist(head);
}
cin>>a}

帮我把这个C++转成C

/*里面还有两个语法错误,也帮你改正了*/

//# include<iostream.h>
#include<stdio.h>
#include<malloc.h> /*用于VC6环境*/

struct list
{
char name[10];
char sex[5];
int age;
int room_num;
struct list *next;
};

struct list *head;

struct list *insert()
{
struct list *s,*p,*q;
s=malloc(sizeof(struct list));
printf("Please input your name!\n");
scanf("%s",s->name);
printf("Please input your sex!\n");
scanf("%s",s->sex);
printf("Please input your age!\n");
scanf("%s",s->age);
printf("Please input your room_num!\n");
scanf("%s",s->room_num);

s->next=NULL;
if (head==NULL)
{
head=s;
return(head);
}
if (head->room_num>s->room_num) /*原句缺一个括号*/
{
s->next=head;
head=s;
return(head);
}
for(q=head, p=head->next;p;q=p,p=p->next)
{
if(p->room_num>s->room_num)
{
s->next=p;
q->next=s;
return(head);
}
if(q->room_num<s->room_num)
{
q->next=s;
return(head);
}
}
return(head);
}

void showlist(struct list *head)
{
printf("Now the peoplt of the list are:");

while(head)
{
printf("Name: %s\t Sex: %s \t",head->name, head->sex);
printf("Age: %d\t room_num: %d",head->age,head->room_num);
head=head->next;
}
printf("\n");
}
void main()
{ char key;
double a;
head=NULL;
printf("Would you like to input the information of a person?(Y/N)\n");
scanf("%c",&key);
while(key=='y'||key=='Y')
{
head=insert();
printf("Would you like to input the information of a person?(Y/N)\n");
scanf("%c",&key);
}
if(head)
{
showlist(head);
}
scanf("%f",a); /*原语句缺分号*/
}

不会吧```

我看得懂就不错了```

还要给你翻译???呀呀

晕,C++和C怎么转换?。。。

它们之间的语法是一样的。

但是C++面向对象,而C不面向对象。

所以C++的有些语句在C里根本无法实现。

#include<stdio.h>

struct list
{
char name[10];
char sex[5];
int age;
int room_num;
list *next;
};
list *head;
list *insert()
{
list *s,*p,*q;
s=(struct list*)malloc(sizoeof(list));
//s=new list;
printf("Please input your name!\n");
gets(s->name);
printf("Please input your sex!\n");
gets(s->sex);
printf("Please input your age!\n");
scanf("%d",&s->age);
printf("Please input your room_num!\n");
scanf("%d",&s->room_num);
s->next=NULL;
if (head==NULL)
{
head=s;
return(head);
}
if (head->room_num>s->room_num)
{
s->next=head;
head=s;
return(head);
}
for(q=head, p=head->next;p;q=p,p=p->next)
{
if(p->room_num>s->room_num)
{
s->next=p;
q->next=s;
return(head);
}
if(q->room_num<s->room_num)
{
q->next=s;
return(head);
}
}
return(head);
}

void showlist(list *head)
{
printf("Now the peoplt of the list are:\n");
while(head)
{
//cout<<"Name:"<<head->name<<"\t"<<"Sex:"<<head->sex<<"\t";
printf("Name:%s\tSex:%s\t",head->name,head->sex);
//cout<<"Age:"<<head->age<<"\t"<<"room_num:"<<head->room_num<<endl;
printf("Age:%d\troom_num:%d\n",head->age,head->room_num);
head=head->next;
}
//cout<<endl;
printf("\n");
}
void main()
{ char key;
flaot a;
head=NULL;
printf("Would you like to input the information of a person?(Y/N)\n");
//cin>>key;
scanf("%c",&key);
while(key=='y'||key=='Y')
{
head=insert();
printf("Would you like to input the information of a person?(Y/N)\n");
//cin>>key;
scanf("%c",&key);
}
if(head)
{
showlist(head);
}
//cin>>a
scanf("%f",&a);
}