⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 111.txt

📁 In c + + written students information management system, the introduction of practical test run, goo
💻 TXT
📖 第 1 页 / 共 2 页
字号:

#include <iostream.h> 
#include <iomanip.h> 
#include <fstream> 
#include <vector> 
#include <malloc.h> 
#include <stdlib.h> 
#include <string> 
#include <process.h> 
#include <stdio.h> 
//#define NULL 0 
int const Q=20; 
#define LEN sizeof(struct student) 
using namespace std; 
int n=0; //定义一个全局变量统计学生人数 
//----------->定义一个学生考试信息的结构体 
struct student 
{ 
char name[Q]; //用来存放姓名的 
char sex; //用来存放性别的 
long int id; //用来存放学号
int age; //用来存放年龄、
long int birthday;//出生年月、
char email[Q]; //E-mail
char phone[Q];// 电话
char address[Q]; //用来存放地址
struct student *next; 
}; 
//student向量容器 
vector <student> stu; 
//-------------->学生类 
class Information 
{ 
public: 
Information() ; //构造函数. 
~Information() ; //析构函数. 
student *creat();//建立链表函数。 
void output(student *head); 
int count(student *head);//定义函数count()统计学生总数 
student *insert(student*head);//指针函数*insert()用来添加学生信息. 
student *cancel(student *head,long int num);//指针函数*cancel()用来删除学生信息. 
student *find(student *head,long int num); //指针函数*find()用来查找学生信息. 
void inorder(student *head);//定义inorder()函数按学生的学号从小到大排列并输出 
void save(student *head);//保存函数 
student *Read();//读取函数 
private: 
student *p1,*p2,*p3,*head,st; 
}; 
Information::Information() 
{ 
cout<<" ******************************************************************************\n"; 
cout<<" ------------------------<<欢迎您使用学生成绩管理系统>>------------------------\n"; 
cout<<" ******************************************************************************\n\n"; 
} 
Information::~Information() 
{ 
cout<<" ******************************************************************************\n"; 
cout<<" ------------------------<<谢谢您使用学生成绩管理系统>>------------------------\n"; 
cout<<" ******************************************************************************\n"; 
} 
student *Information::creat(void) 
{//定义一个指向struct student的结构体指针函数*creat()用来增加考生信息. 
char ch[Q];n=0; //用来存放姓名的 
p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元 
cout<<" -------------<<请建立学生考试信息表,在姓名处键以 ! 结束输入。>>--------------"<<endl; 
cout<<" 姓名:"; 
cin>>ch; 
head=NULL; //给指针head赋初值 
while (strcmp(ch,"!")!=0) 
{//调用字符比较函数strcmp()用来判断是否继续输入 
char str[11]; 
int flag=0; 
char ch1;
p1=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元 
strcpy(p1->name,ch); //将循环结构前面输入的姓名复制到结构体名为p1的数组name中 
cout<<" 性别(w/m):";
do{ 
cin>>ch1;
if(ch1=='w'||ch1=='W'||ch1=='m'||ch1=='M')
{p1->sex=ch1;flag=1;} 
else cout<<"输入有误,请重新输入!!"<<endl; 
}while(flag==0);
flag=0;
cout<<" 学号(8位):"; 
do{ 
cin>>str; 
if(atol(str)>99999999 || atol(str)<1) 
cout<<"对不起,请正确输入!!!\n"; 
else 
{ 
p1->id=atol(str); flag=1; 
} 
}while(flag==0); 

flag=0; 

cout<<"年龄:"; 
do{ 
cin>>str; 
if(atoi(str)>100 || atoi(str)<1) 
cout<<"对不起,请输入正确的年龄!!\n"; 
else 
{ 
p1->age=atoi(str); flag=1; 
} 
}while(flag==0); 

flag=0; 

cout<<"电话:"; 

 cin>>ch;
strcpy(p1->phone,ch);


cout<<"出生年月(XXXXXX):"; 

do{ 
cin>>str; 
if(atoi(str)>999999 || atoi(str)<1) 
cout<<"对不起,请输入正确的出生年月!!\n"; 
else 
{ p1->birthday =atoi(str); flag=1;} 
}while(flag==0); 
flag=0; 

cout<<"E-mail:"; 

do{ 
cin>>str; 
{ strcpy(p1->email,str); flag=1;} 
}while(flag==0); 

flag=0; 

cout<<"地址:";
cin>>ch;
strcpy(p1->address,ch);

if(n==0)head=p1;//如果是输入第一组学生信息就将指针p1赋给指针head 
else p2->next=p1;//否则将p1赋给p2所指结构体的next指针 
p2=p1;//将指针p1赋给指针p2 
n++; //将n的值加1 
cout<<" 姓名:"; 
cin>>ch;//将输入的姓名存放到字符数组ch中 
} 
p2->next=NULL;//将p2所指结构体的next指针重新赋空值 
return (head);//将输入的第一组学生信息返回 
} 
//--------------->定义output()函数将学生的信息从头指针所指内容开始输出 
void Information::output(student *head) 
{ 

if(head==NULL) cout<<" 这是一个空表,请先输入考生成绩.\n"; 
else{ 
cout<<"-------------------------------------------------------------------------------\n"; 
cout<<" *                    学生信息表                                              *\n"; 
cout<<"------------------------------------------------------------------------------- \n"; 
cout<<"  学号    姓名 性别 年龄  出生年月  电话       Email           地址              \n"; 
cout<<"-------------------------------------------------------------------------------\n"; 
p1=head;//将头指针赋给p 
do 
{ 
cout<<setw(5)<<p1->id 
<<setw(9)<<p1->name 
<<setw(3)<<p1->sex 
<<setw(4)<<p1->age   
<<setw(8)<<p1->birthday 
<<setw(15)<<p1->phone 
<<setw(12)<<p1->email 
<<setw(10)<<p1->address <<endl; 
cout<<"-------------------------------------------------------------------------------\n"; 
p1=p1->next;//将下一组考生信息的next指针赋给p 
}while(p1!=NULL);//若指针p非空则继续,目的是把所有的考生信息都传给指针p然后输出. 
} 
} 
//------------>统计学生人数的函数 
int Information::count(struct student *head)//定义函数count()统计考生总数 
{ 
if(head==NULL) 
return(0);//若指针head为空返回值为0 
else return(1+count(head->next));//函数的递归调用 
} 
//----------->插入学生的成绩的函数 
student *Information::insert( student *head) 
//插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加考生信息. 
{ 
char str[11]; 
int flag=0; 
char ch[Q];
char ch1;
cout<<"\t----------------<<请输入新增学生信息>>----------------\n"<<endl; 
p1=(student *)malloc(LEN); //使p1指向插入的新结点 
cout<<" 姓名:"; 
cin>>p1->name; //将输入的姓名存放到结构体名为p1的数组name中 
cout<<" 性别(w/m):";
do{ 
cin>>ch1;
if(ch1=='w'||ch1=='W'||ch1=='m'||ch1=='M')
{p1->sex=ch1;flag=1;} 
else cout<<"输入有误,请重新输入!!"<<endl; 
}while(flag==0);
flag=0;
cout<<" 学号(8位):"; 
do{ 
cin>>str; 
if(atol(str)>99999999 || atol(str)<1) 
cout<<"对不起,请正确输入!!!\n"; 
else 
{p1->id=atol(str); flag=1; } 
}while(flag==0); 

flag=0; 

cout<<"年龄:"; 
do{ 
cin>>str; 
if(atoi(str)>100 || atoi(str)<1) 
cout<<"对不起,请输入正确的年龄!!\n"; 
else 
{ 
p1->age =atoi(str); flag=1; 
} 
}while(flag==0); 

flag=0; 

cout<<"电话:"; 

 cin>>ch;
 strcpy(p1->phone,ch);

 
 cout<<"出生年月(XXXXXX):"; 

do{ 
cin>>str; 
if(atoi(str)>999999 || atoi(str)<1) 
cout<<"对不起,请输入正确的出生年月!!\n"; 
else 
{ p1->birthday =atoi(str); flag=1;} 
}while(flag==0); 
flag=0; 

cout<<"E-mail:"; 

do{ 
cin>>str; 
{ strcpy(p1->email,str); flag=1;} 
}while(flag==0); 

flag=0; 

cout<<"地址:";
cin>>ch;
strcpy(p1->address,ch);

p2=head;//将头指针赋给p2 
if(head==NULL) //若没调用次函数以前的头指针head为空 
{ 
head=p1;p1->next=NULL; 
}//则将p1赋给头指针head并将p1所指结构体成员指针next赋空值 
else 
{ 
while((p1->id>p2->id)&&(p2->next!=NULL)) 
{ 
p3=p2;//p3指向原p2指向的结点 
p2=p2->next; 
}//p2后移一个结点 
if(p1->id<=p2->id) 
{ 
if(head==p2) 
{ 
p1->next=head; 
head=p1; 
} //插入到第一个结点之前 
else 
{ 
p3->next=p1; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -