xsxxgl_vc.txt

来自「1)能够从屏幕上读取一个学生的信息并将信息存入到数据文件中。 2)能够将指定」· 文本 代码 · 共 106 行

TXT
106
字号
#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[Q]; //用来存放性别的 
long int id; //用来存放准考证号的 
int score[4]; //用来存放分数的 
int total; //用来存放总分数的 
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 average( student *head);//求学生成绩的平均分的函数 
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[10]; 
int flag=0; 
p1=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元 
strcpy(p1->name,ch); //将循环结构前面输入的姓名复制到结构体名为p1的数组name中 
cout<<" 性别:"; 
cin>>p1->sex; 

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<<"对不起,请输入1-100之间的数字!!\n"; 
else 
{ 
p1->score[0]=atoi(str); flag=1; 
} 
}while(flag==0); 

flag=0; 

cout<<" 概率统计成绩:"; 
do{ 
cin>>str; 
if(atoi(str)>100 || atoi(str)<1) 
cout<<"对不起,请输入1-100之间的数字!!\n"; 
else 

⌨️ 快捷键说明

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