html编写输出学生姓名,用C++编写一个学生信息管理系统

#include 

#include 

#include 

#include //输入/输出文件流类

using namespace std;

class Student //定义类

{

private:

int tag; //删除标记 1:已删 0:未删

char name[10]; //姓名

int grade;//成绩

int ID;

public:

Student() {}//构造函数

int gettag() {return tag;} //获取删除标记

char* getname() {return name;} //获取驾驶员编号

int getID(){ return ID; }

int getgrade(){

return grade;

}

void setname(char*na){ strcpy_s(name, na); }

void setgrade(int n){ grade = n; }

void deldrive(){ tag = 1; }//设置删除标记 1:已删 0:未删

void addstudent(char* nname, int ngrade, int nID)//增加

{

tag = 0;

grade = ngrade;

ID = nID;

strcpy_s(name, nname);

}

void show()//显示信息

{

cout <

cout <

cout <

}

};

//学生类库

class Studentlist

{

private:

int top; //记录指针与学号

Student student[100];//记录

public:

Studentlist() //构造函数,将txt读到程序

{

Student s;

top=-1;

fstream file("student.txt",ios::in);//打开一个输入文件

while (1)

{

file.read((char *)&s,sizeof(s));

if (!file)break;

top++;

student[top] = s;//循环逐个读入

}

file.close(); //关闭txt

}

int add(char* nname, int ngrade)//添加时先查找是否存在

{

top++;

student[top].addstudent(nname,ngrade,top);//调用类增加函数

return 1;

}

Student *findname(char*  name)//按姓名查找

{

for (int i=0;i<=top;i++)

if (strcmp(student[i].getname(),name)==0 &&

student[i].gettag() == 0)//判断是否已经存在

{

return &student[i];

}

return NULL;

}

Student *findID(int ID)//按学号查找

{

for (int i = 0; i <= top; i++)

if (student[i].getID()== ID&&

student[i].gettag() == 0)//判断是否已经存在

{

return &student[i];

}

return NULL;

}

void show() //输出所有信息

{

for (int i=0;i<=top;i++)

student[i].show();

}

void tongji(){//统计函数

cout <

cout <

for (int i = 0; i <= top; i++)

if (student[i].getgrade() >= 60)

student[i].show();

cout <

cout <

for (int i = 0; i <= top; i++)

if (student[i].getgrade() >= 80)

student[i].show();

}

void studentlist();//维护

~Studentlist() //析构函数,将写到txt文件中

{

fstream file("student.txt",ios::out);

for (int i=0;i<=top;i++)

if (student[i].gettag() == 0)//循环输出信息到文本中

file.write((char *)&student[i], sizeof(student[i]));

file.close();

}

};

void Studentlist::studentlist()//维护函数实现

{

int choice = 1;//先行定义,避免choice未定义使用

char name[10]; //姓名

int grade;//成绩

int ID;

Student *r;//指针

while (choice != 6)

{

cout <

cin >> choice;

switch (choice)

{

case 1://新增

cout <

cin >> name;

cout <

cin >> grade;

add(name, grade);

cout <

break;

case 2://显示

int a;

while (a){

cout <

cin >> a;

switch (a){

case 1:

cout <

cin >> ID;

r = findID(ID);

if (r == NULL)

{

cout <

system("pause");

break;

}

r->show();

system("pause");

break;

case 2:

cout <

cin >> name;

r = findname(name);

if (r == NULL)

{

cout <

system("pause");

break;

}

r->show();

system("pause");

break;

case 0:break;

default:cout <

}

}; break;

case 3://更改

int b;

while (b){

cout <

switch (b){

case 1:

cout <

cin >> ID;

r = findID(ID);

if (r == NULL)

{

cout <

system("pause");

break;

}

cout <

cin >> grade;

r->setgrade(grade);

system("pause");

break;

case 2:

cout <

cin >> name;

r = findname(name);

if (r == NULL)

{

cout <

system("pause");

break;

}

cout <

cin >> grade;

r->setgrade(grade);

system("pause");

break;

case 0:break;

default:cout <

}

};

break;

case 4://全显

show();

system("pause");

break;

case 5://全删

tongji();

system("pause");

break;

case 6://退出

break;

default:cout <

};

}

}

//main() 函数的实现,程序的主界面的引导

int main(void)

{

Studentlist a;

a.studentlist();

return 0;

}

温馨提示:答案为网友推荐,仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值