建立一个链表,每个节点包括学生的学号、姓名、性别、年龄,学号

要能运行的,发到邮箱992541896@qq.com 谢谢。。

# include"stdio.h"

#include"stdlib.h"

struct data

{

int num;

char name[20];

char sex[4];

int age;

struct data*next;

};

int main()

{

int i,k;

struct data*head,*p,*q,*t;

head=t=p=q=(struct data*)malloc(sizeof(struct data));

printf("输入学号:");

scanf("%d",&p->num);

getchar();

printf("输入姓名:");

gets(p->name);

printf("输入性别:");

gets(p->sex);

        printf("输入年龄:");

scanf("%d",&p->age);

while(p->num!=-1)

{

q->next=p;

q=p;

      p=(struct data*)malloc(sizeof(struct data));

    printf("输入学号:");

scanf("%d",&p->num);

getchar();

if(p->num==-1)  break;

printf("输入姓名:");

gets(p->name);

printf("输入性别:");

gets(p->sex);

printf("输入年龄:");

scanf("%d",&p->age);

}

    q->next=NULL;

free(p);

printf("输出的结果是:\n");

while(t!=NULL) 

{ printf("%-5d%8s%8s%8d",t->num,t->name,t->sex,t->age);

           t=t->next;

   printf("\n");

}

    

printf("请输入你要查找的学生的学生号:");

scanf("%d",&i);

p=head;

while(p!=NULL)

{

        if(i == p->num)

{

printf("\n%-5d%8s%8s%8d\n",p->num,p->name,p->sex,p->age);

                                  

}

p=p->next;

}

return 0;

}

姐姐啊!你要两个学号啊!我给你编了可以查学号的!祝你成功!

我运行的情况!

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-27
# include "iostream"
# include "String.h"
using namespace std;
struct List
{
char name[20];
int NO;
};
template <class List>
struct Node
{
List data;
Node<List> *next;
};
template <class List>
class Student
{
Node<List> *head;
public:
Student(int m);
void Setdata(int n);
void PrintStudent();
int Get(char b[]);
void Delete(int i);
void Insert(int i,List item);
void Change(char a[],int num);
~Student();
};
template <class List>
Student<List>::Student(int m)
{
Node<List> *r,*s;
head = new Node<List>;
r = head;
for (int i = 0;i < m;i++)
{
s = new Node<List>;
r->next = s;
r = s;
}
r->next = NULL;
}
template <class List>
void Student<List>::Setdata(int n)
{
Node<List> *p;
p = head->next;
for(int i = 0;i < n;i++)
{
cout<<"请输入姓名:";
cin>>p->data.name;
cout<<"请输入身份证号码:";
cin>>p->data.NO;
p = p->next;
}
}
template <class List>
void Student<List>::PrintStudent()
{
Node<List> *p;
p = head->next;
while (p)
{
cout<<p->data.name<<","<<p->data.NO<<endl;
p = p->next;
}
}
template <class List>
int Student<List>::Get(char b[])
{
Node<List> *p;
p = head->next;
while(p && strcmp(p->data.name,b) != 0)
{
p = p->next;
}
return p->data.NO;
}
template <class List>
void Student<List>::Delete(int i)
{
Node<List> *p,*q;
p = head;
int j = 0;
while(p && j < i-1)
{
p = p->next;
j++;
}
if(!p || !p->next) {cerr<<"删除位置非法";exit(1);}
else
{
List x;
q = p->next;
x = q->data;
p->next = q->next;
delete q;
cout<<x.name<<","<<x.NO<<endl;
}
}
template <class List>
void Student<List>::Insert(int i,List item)
{
Node<List> *p,*s;
p = head;
int j = 0;
while (p && j < i-1)
{
p = p->next;
j++;
}
if(!p) {cerr<<"插入位置非法";exit(1);}
else
{
s = new Node<List>;
strcpy(s->data.name,item.name);
s->data.NO = item.NO;
s->next = p->next;
p->next = s;
}
}
template <class List>
void Student<List>::Change(char a[],int num)
{
Node<List> *p;
p = head->next;
while (p && strcmp(p->data.name,a) != 0)
{
p = p->next;
}
p->data.NO = num;
}
template <class List>
Student<List>::~Student()
{
Node<List> *p,*q;
p = head;
while (p)
{
q = p;
p = p->next;
delete q;
}
head = NULL;

}
void main()
{
cout<<"请建立学籍系统"<<endl;
int m;
cout<<"请输入总人数:";
cin>>m;
Student<List> stu(m);
int n = m;
stu.Setdata(n);
stu.PrintStudent();
int choice;
do
{
cout<<"********"<<endl;
cout<<"1.查询"<<endl;
cout<<"2.删除"<<endl;
cout<<"3.插入"<<endl;
cout<<"4.修改"<<endl;
cout<<"0.退出"<<endl;
cout<<"********"<<endl;
cout<<"请输入您的选择:";
cin>>choice;
switch(choice)
{
case 1:
{
char b[20];
cout<<"请输入需查询的姓名:";
cin>>b;
cout<<"查询人的学号为:";
cout<<stu.Get(b)<<endl;
}break;
case 2:
{
int i;
cout<<"请输入需删除数据的位置:";
cin>>i;
cout<<"删除的数据为:";
stu.Delete(i);
}break;
case 3:
{
List item;
cout<<"请输入需插入学生的姓名:";
cin>>item.name;
cout<<"请输入需插入学生的学号:";
cin>>item.NO;
int i;
cout<<"请输入需插入的位置:";
cin>>i;
stu.Insert(i,item);
stu.PrintStudent();
}break;
case 4:
{
char a[20];
cout<<"请输入需修改人的姓名:";
cin>>a;
int num;
cout<<"请输入修改的新学号:";
cin>>num;
stu.Change(a,num);
stu.PrintStudent();
}break;
case 0:
{
exit(1);
}break;
default:
{
cout<<"选择项非法,请重新选择";
cout<<endl;
cout<<endl;
}
}

} while(choice);

}
第2个回答  2011-06-09
#include<stdio.h>
#include<malloc.h>

struct student
{
int num;
char name [20];
int sex;
int age;
struct student*next;
};
struct student *creat(struct student *head)
{
struct student *p1,*p2;
p1=(struct student*) malloc(sizeof(struct student));
p2=head;
head=p1;
p1->next =p2;
printf ("input the student`s date:\n[as: name number sex(1 as male;2 as female) age]\n");
gets(p1->name);
scanf ("%d%d%d",&p1->num,&p1->sex,&p1->age);
while ((p1->sex!=1)&&(p1->sex!=2))
{
printf ("the sex is wrong,please input again:\n(1 as male;2 as female)\n");
scanf ("%d",&p1->sex);
}
return (head);
}

struct student *delete_date (struct student *head)
{
struct student *temp,*p;
int number;
if (head==NULL)
printf ("list is null!\n");
else
{
printf ("please input the delete number:");
scanf ("%d",&number);
temp=head;
while (((temp->num)!=number)&&((temp->next)!=NULL))
{
p=temp;
temp=temp->next;
}
if ((temp->num)==number)
{
if (temp==head)
{
printf ("delete date's number: %d\n ",temp->num);
head=head->next;
}
else
{
p->next=temp->next;
printf ("delete date's number: %d\n ",temp->num);
free (temp);
}
}
else printf ("no find date!\n");
}
return (head);
}

void *output(struct student *head)
{
struct student *temp;
temp=head;
printf ("the all student`s date is :\n[name number age sex]");
{
printf ("%s %d %d",temp->name,temp->num,temp->age);
if (temp->sex==1)
printf ("male");
else printf ("female");
temp=temp->next;
}while (temp->next!=NULL);
}

void main ()
{
struct student *head;
int i=2;
head=NULL;
while (i!=0)
{
int clrscr();
printf ("please chose the number:\n");
printf ("1.add the date;\n");
printf ("2.delete the date;\n");
printf ("3.out put the date;\n");
printf ("0.end the program;\n");
scanf ("%d",&i);
switch (i)
{
case 1:head=creat(head);
case 2:head=delete_date(head);
case 3:output(head);
}
}
}
可以运行,我试过了

建立一个链表,每个节点包括学生的学号、姓名、性别、年龄,学号
printf("输入学号:");scanf("%d",&p->num);getchar();printf("输入姓名:");gets(p->name);printf("输入性别:");gets(p->sex);printf("输入年龄:");scanf("%d",&p->age);while(p->num!=-1){ q->next=p;q=p;p=(struct data*)malloc(sizeof(struct data));printf("输入学号...

建立一个链表,每个节点包括学生的学号、姓名、性别、年龄。先输入5个学...
int age1,m=1;struct student *p1,*p2,*p0;scanf("%d",&age1);p2=p0=head;if(age1==p2->age){ head=p2->next;m=0;} else { do{ p1=p2;p2=p2->next;} while(p2!=NULL&&p2->age!=age1);if(p2!=NULL&&p2->age==age1){ p1->next=p2->next;m=0;} } free(p2);if...

首先建立一个链表,每个节点包括学号、姓名、性别、年龄;然后输入一个...
printf("请输入一个学生,以回车分开\\n");while(1){ p = (struct STU *)malloc(sizeof(struct STU));printf("学号:");scanf("%s", p->number);printf("姓名:");scanf("%s", p->name);printf("性别(女填0,男填1):");scanf("%d", &p->sex);printf("年龄:");scanf("%d...

建立一个动态链表,链表中每一结点包括:学号、姓名、性别、年龄、成绩...
void free_list(struct student *head){ struct student *p=head ;printf("释放链表:\\n");while(p!=NULL){

...要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩_百度...
\/ 用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩 \/ \/\/FileName: stuinfo.c include <stdio.h> include <stdlib.h> include <string.h> define SERIALLEN 20 define COURSENUM 3 typedef struct { char course[SERIALLEN];float score;}...

...程序设计:建立一个学生信息链表,包括学号,姓名,成绩.(实现添加,删...
代码如下:\/*用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,学号,姓名,成绩(实现添加,删除,查询,排序,平均)*\/ include <stdio.h> include <iostream> include <string.h> include <stdlib.h> using namespace std;const int n=5;\/ nodeEntry : 节点数据类型 nodeADT...

如何编程来建立学生表包含姓名、学号、性别、班级、出生日期、籍贯、照...
创建表的SQL语句:create table student(name varchar(20),student_ID number,sex varchar(5),class_id number,birthday date,from_city varchar(50),picture raw(30),resume char(2));由于简历resume作为链接,在Oracle中没有对应的字段类型,在Oracle中只能体现其有无,建议用1代表有,用0代表无。

学生数据库包含如下三个表:student(学号,姓名,性别,年龄,所在系)
course.课号=sc.课号 and student.性别='女' 2select student.姓名,sc.成绩from student,course,sc where student.学号=sc.学号 and course.课号=sc.课号 and student.年龄=22 and course.课程名='英语' 3select 姓名,year(getdate())-年龄 as 出生年份 from student where 性别='男'...

...应用:编写一个完整的C++语言程序,输入信息:学生的学号,姓名...
);PrinfListNode(h);break;case 0:return 0;break;default:printf("ERROR! Please try again");} } return 0;} \/*---建立链表函数实现部分---*\/ ListNode *CreateNode(int n){ ListNode *head;ListNode *pre,*p;

建立一个链表,记录学生的姓名,学号和成绩,
请求援助...建立一个链表,记录学生的姓名,学号和成绩,实现插入和删除过程并且当输入学生的姓名时,可以将该学生所有的信息调出... 请求援助...建立一个链表,记录学生的姓名,学号和成绩,实现插入和删除过程并且当输入学生的姓名时,可以将该学生所有的信息调出. 展开 ...

相似回答