7_64.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
- #include<iostream.h>
- #include<string.h>
- #include<stdio.h>
- struct std
- {
- char* name;
- bool sex;
- unsigned int age;
- std* next;
- };
- class Student
- {
- public:
- Student(char* a[],bool b[],unsigned int c[],int n);
- ~Student();
- void print();
- private:
- std*num,*head,*p;
- int size;
- };
- Student::Student(char** a,bool* b,unsigned int* c,int n)
- {
- size=n;
- head=new std;
- head->next=NULL;
- num=head;
- for(int i=0;i<size;i++)
- {
- p=new std;
- p->name=*(a+i);
- p->sex=*(b+i);
- p->age=*(c+i);
- p->next=NULL;
- num->next=p;
- num=p;
- }
- }
- Student::~Student()
- {
- p=head->next;
- for(int i=0;i<size;i++)
- {
- num=p->next;
- delete p;
- p=num;
- }
- delete head;
- cout<<"析构函数在这里被自动调用!";
- cout<<endl;
- }
- void Student::print()
- {
- p=head->next;
- cout<<"学生情况如下:(1代表男性,0代表女性)"<<endl;
- cout<<"姓名"<<" "<<"性别"<<" "<<"年龄"<<endl;
- for(int i=0;i<size;i++)
- {
- cout<<p->name<<" "<<p->sex<<" "<<p->age<<endl;
- p=p->next;
- }
- }
- void main()
- {
- const int N=3;
- char* stdn[N];
- bool stds[N];
- unsigned int stda[N];
- int stdsex;
- unsigned int stdage;
- for(int i=0;i<N;i++)
- {
- char* stdname;
- stdname=new char[10];
- cout<<"Please input the student's name of NO."<<i+1<<":";
- cin>>stdname;
- stdn[i]=stdname;
- cout<<"Please input the student's sex of NO."<<i+1<<"(1--male,0--female)"<<":";
- cin>>stdsex;
- if(stdsex)
- stds[i]=true;
- else
- stds[i]=false;
- cout<<"Please input the student's age of NO."<<i+1<<":";
- cin>>stdage;
- stda[i]=stdage;
- }
- Student SA(stdn,stds,stda,N);
- SA.print();
- cout<<endl;
- // SA.Student::~Student(); 错误:析构函数不能被显式调用
- }