学生管理系统c语言封装,c++封装链表实现-->学生信息管理分析系统

//class.h 头文件

#include 

#include 

#include             //实现setw()宽字节输出

using namespace std;

class stuDate

{

public:

struct student

{

string name;//姓名

string sex;//性别

int id;

float eng,math,chinese,c,sum;

struct student *next;

};

};

class stuList :public stuDate

{

private:

int num;//人数

struct student *head;

public:

stuList();

void _creat();

void _print();

void _sort();

};

stuList::stuList()

{

this->head=NULL;

this->num=0;

}

void stuList::_creat()

{

char res = 'Y';

struct student *p1,*p2;

p1=p2=new struct student;

while(res=='Y' || res == 'y')

{

if(this->head == NULL)

{

this->head=p1;

p1->id=0;

}

else

{

p2->next=p1;

}

cout<

cin>>p1->name;

cout<

cin>>p1->sex;

cout<

cin>>p1->chinese;

cout<

cin>>p1->math;

cout<

cin>>p1->eng;

cout<

cin>>p1->c;

p1->id=this->num+1;

p1->sum=p1->chinese+p1->math+p1->eng+p1->c;

this->num++;

p2=p1;

p1=new struct student;

cout<

cin>>res;

if(res =='N'|| res == 'n')

break;

}

p2->next=NULL;

}

void stuList::_print()

{

struct student *temp;

temp=this->head;

cout<

<

for(int i=0;inum;i++)

{

cout<id<name<sex<chinese<

<math<eng<c<sum<

temp=temp->next;

}

cout<

cout<num;

cout<

}

void stuList::_sort()

{

struct student *first;/*排列后有序链的表头指针*/

struct student *tail;/*排列后有序链的表尾指针*/

struct student *p_max;

struct student *max;

struct student *p;

p=this->head;

if(this->head!=NULL)

{

first=NULL;

while (head != NULL)

{

for (p=this->head,max=this->head; p->next!=NULL; p=p->next)

{

if (p->next->sum > max->sum)//以总分排序

{

p_max=p;

max=p->next;

}

}

if(first==NULL)

{

first=max;

tail=max;

}

else

{

tail->next=max;

tail=max;

}

if(max==this->head)

{

this->head=this->head->next;

}

else

{

p_max->next=max->next;

}

}

if(first!=NULL)

{

tail->next=NULL;

}

cout<

<

for(int i=0;inum;i++)

{

cout<id<name<sex<chinese<

<math<eng<c<sum<

first=first->next;

}

}

}

//stu.cpp    调用class。h

#include "class.h"

int main()

{

stuList A;

A._creat();

A._print();

A._sort();

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值