class.h header file #include <string> #include <iostream> #include <iomanip> //implements SETW () wide-byte output using namespace std;class studate{public:struct student{string name;//name string sex;//sex int id; float eng,math,chinese,c,sum;struct student *next;};}; class stulist :p ublic studate{private:int num;//number 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<< "Name:";cin>>p1->name;cout<< "Sex:";cin>>p1->sex;cout<< "Chinese:"; cin >>p 1->chinese;cout<< "Math:";cin>>p1->math;cout<< "中文版:"; cin>>p1->eng;cout << "C language:"; cin>>p1->c;p1->id=this->num+1;p1->sum=p1->chinese+p1->math+p1->eng+ p1->c;this->num++;p 2=p1;p1=new struct student;cout<< "\ nthe continuation of input (y/n):"; Cin>>res;if ( res == ' N ' | | res == ' n ') break;} P2->next=null;} Void stulist::_print () {struct student *temp;temp=this->head;cout<< "id" <<SETW (5) << "Name" <<SETW (5) << "Sex" <<setw << "Chinese" <<setw (5) << "Math" < <SETW (8) << "中文版" <<SETW (5) << "C" <<SETW (5) << "Sum" <<endl;for (int i= 0;i<this->num;i++) {COUT<<TEMP->ID<<SETW (5) <<TEMP->NAME<<SETW (5) << TEMP->SEX<<SETW (5) <<TEMP->CHINESE<<SETW (5) <<TEMP->MATH<<SETW (5) << TEMP->ENG<<SETW (5) <<TEMP->C<<SETW (5) <<temp->sum<<endl;temp=temp->next;} cout<<endl;cout<< "Total number of------------------------------------------------------------:" <<this- >num;cout<<endl;} Void stulist::_sort () {struct student *first;/* The header pointer of an orderly chain after arranging */struct student *tail;/* The end-of-order pointer */struct student *p_max;struct student *max;struct student *p;p=this-the ordered chain after arranging >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)//sorted by total score {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<< "id" <<SETW (5) << "Name" <<SETW (5) << "Sex" <<SETW (Ten) << "Chinese" < <SETW (5) << "Math" << SETW (8) << "中文版" <<SETW (5) << "C" <<SETW (5) << "Sum" <<endl;for (int i=0;i <this->num;i++) {COUT<<FIRST->ID<<SETW (5) <<FIRST->NAME<<SETW (5) << FIRST->SEX<<SETW (5) <<FIRST->CHINESE<<SETW (5) <<FIRST->MATH<<SETW (5) < <FIRST->ENG<<SETW (5) <<FIRST->C<<SETW (5) <<first->sum<<endl;first= First->next;}}} stu.cpp call class. h#include "Class.h" Int main () {stulist a; A._creat (); A._print (); A._sort (); return 0;}
This article is from the "Creative Pilgrim" blog, so be sure to keep this source http://dearch.blog.51cto.com/10423918/1758724
C + + Package list implementation--Student Information management Analysis system