📄 pro_stu.cpp
字号:
#include <iostream>
#include <string.h>
using namespace std;
typedef struct STNode{
int data;
char name[14];
char num[10];
char Class[15];
char speciality[15];
int Knum;
struct STNode *next;
}STNode, *Lp;
STNode *InitINput(STNode *head, int i)
{cout<<"这是个空表,请输入:"<<endl;
int j=1;
STNode *head1,*p;
while(j<=i)
{p=(STNode *)malloc(sizeof(STNode));//(int *)malloc(sizeof(int));
if(j==1)
{ head->next=p;
p->next=NULL;
head1=p;
cout<<"请输入第1个学生相关信息:"<<endl;
cout<<endl<<"输入姓名:";
cin>>p->name;
cout<<endl<<"输入学号:";
cin>>p->num;
cout<<endl<<"输入年级:";
cin>>p->Class;
cout<<endl<<"输入专业:";
cin>>p->speciality;
cout<<endl<<"输入旷课次数:";
cin>>p->Knum;
p->data=1;
j++;
}
else
{
head1->next=p;
p->next=NULL;
head1=p;
p->data=j;
cout<<"请输入第"<<p->data<<"个学生相关信息:"<<endl;
cout<<endl<<"输入姓名:";
cin>>p->name;
cout<<endl<<"输入学号:";
cin>>p->num;
cout<<endl<<"输入年级:";
cin>>p->Class;
cout<<endl<<"输入专业:";
cin>>p->speciality;
cout<<endl<<"输入旷课次数:";
cin>>p->Knum;
j++;
}
}
return head;
}
STNode *Insert(STNode *head)
{STNode *head1,*p;
cout<<"添加学生信息:"<<endl;
if(head->next==NULL)
cout<<"这是一个空表"<<endl;
else
{
head1=head->next;
if(head1->next!=NULL)
head1=head1->next;
else
{p=(STNode *)malloc(sizeof(STNode));
head1->next=p;
p->next=NULL;
cout<<"请输入新插入学生相关信息:"<<endl;
cout<<endl<<"输入姓名:";
cin>>p->name;
cout<<endl<<"输入学号:";
cin>>p->num;
cout<<endl<<"输入年级:";
cin>>p->Class;
cout<<endl<<"输入专业:";
cin>>p->speciality;
cout<<endl<<"输入旷课次数:";
cin>>p->Knum;
p->data=head1->data+1;
}
}
return head;
}
STNode *GetElem(STNode *head)
{char *num1 =new char[10]; //int *p=new int;
char *num2 =new char[10]; //int *p[10]=new int [10];
cout<<"查询某个同学的情况:"<<endl;
cout<<"请输入学号:"<<endl;
cin>>*num1 ;
STNode *p1;
if(head==NULL)//若调用次函数以前的头指针head为空
{
cout<<" 这是一个空表,请先输入考生成绩.\n";
return(head);
}
else
{
p1=head;//否则将头指针赋给p1
num2 =p1->num;
while((strcmp(num1 ,num2 )!=0)&&p1->next!=NULL)
//寻找结点当p1所指的学生证号不是输入的学生证号并且p1所指的next指针不为空
{
p1=p1->next;
}//p2指向原p1指向的结点p1后移一个结点
if((strcmp(num1 ,num2 )==0))
{cout<<"姓 名:"<<p1->name;
cout<<"学 号:"<<p1->num;
cout<<"年 级:"<<p1->Class;
cout<<"专 业:"<<p1->speciality;
cout<<"旷课次数:"<<p1->Knum;
}
}
return(head);
}
void main()
{
int i=2;
STNode *head;
head=(STNode *)malloc(sizeof(STNode));
head->next=NULL;
head=InitINput(head, i);
Insert( head);
GetElem(head);
system ("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -