动态数组 但是函数进不去
#include<stdio.h>#include<iostream>
#include<string>
using namespace std;
#define N 5
class student
{
public:
string num;
string name;
int score[4];
student( );
student(string nu,string na,int a[] );
~student( );
void input( );
void input(string nu,string na,int a[]);
void print( );
};
struct date
{
int year;
int month;
int day;
};
class teacher
{
private:
string num;
string name;
float income;
struct date birthday;
public:
teacher();
teacher(string nu,string na,float in,int sr[]);
~teacher();
void input( );
void input(string nu,string na,float,int sr[]);
void print( );
};
class Grade
{
public:
// void Add();
// void Erase();
// void Change();
// void Search();
// void Sort(); //总分排序
// void GetHigh(); //最高分
// void GetLow(); //最低分
// void GetAverage(); //平均分
// void List();
void input( );
void print( );
Grade();
~Grade();
private:
student *s; //学生
int length; //已经输入成绩的学生人数
int listsize;
};
student::student( )
{
num="";
name="";
for(int j=0;j<3;j++)
{
score[j]=0;
}
}
student::student(string nu,string na,int a[])
{
int j;
num=nu;
name=na;
for(j=0;j<3;j++)
{
score[j]=a[j] ;
}
}
student::~student( )
{
cout<<"student destruct run!"<<endl;
}
void student::input( )
{
int j;
cout<<"please enter student num:";
cin>>num;
cout<<"please enter student name:";
cin>>name;
cout<<"please enter student three score:";
for(j=0;j<3;j++)
{
cin>> score[j] ;
}
}
void student::input(string nu,string na,int a[])
{
num=nu;
name=na;
for(int j=0;j<3;j++)
{
cin>>a[j];
}
}
void student::print( )
{
int j;
cout<<"----------------------------------------\n";
cout<<"\n学号 姓名 成绩1 成绩2 成绩3\n";
cout<<"----------------------------------------\n";
cout<<num<<" "<<name<<" ";
for(j=0;j<3;j++)
cout<< score[j] <<" ";
cout<<"\n----------------------------------------\n";
}
teacher::teacher()
{
num="";
name="";
income=1000;
birthday.year=0;
birthday.month=0;
birthday.day=0;
}
teacher::teacher(string nu,string na,float in,int sr[])
{
num=nu;
name=na;
income=in;
birthday.year=sr[0];;
birthday.month=sr[1];
birthday.day=sr[2];
}
void teacher::input()
{
cout<<"please enter teacher num:";
cin>>num;
cout<<"please enter teacher name:";
cin>>name;
cout<<"please enter teacher income:";
cin>>income;
cout<<"please enter teacher birthday:";
cin>>birthday.year>>birthday.month>>birthday.day;
}
teacher::~teacher()
{
cout<<"destructor called"<<endl;
}
void teacher::input(string nu,string na,float in,int sr[])
{
num=nu;
name=na;
income=in;
birthday.year=sr[0];;
birthday.month=sr[1];
birthday.day=sr[2];
}
void teacher::print( )
{
cout<<"----------------------------------\n";
cout<<"\n工号 姓名 月收入 出生日期\n";
cout<<"----------------------------------\n";
cout<<num<<" "<<name<<" "<<income<<" ";
cout<<birthday.year<<"年"<<birthday.month<<"月"<<birthday.day<<endl;
cout<<"----------------------------------\n";
}
void Grade::input()
{
int i,j,flag=1;
cout<<"please enter student xinxi:\n";
for(i=0;flag==0||i==9;i++)
{
s[i].input();
length++;
cout<<"please if or not (1/0)ernter:";
cin>>flag;
}
}
void Grade::print()
{
for(int i=0;i<length;i++)
s[i].print();
}
Grade::Grade()
{
listsize=10;
s=new student [listsize];
length=0;
cout<<"Grade construct run!"<<endl;
}
Grade::~Grade()
{
delete []s;
cout<<"Grade destruct run!"<<endl;
}
void main()
{
int x[]={60,60,60};
student s1,s2("201601","zhangsan" ,x);
s1.input();
s1.print();
s2.print();
int sr[]={0000,0,0};
teacher t1,t2("201601","zhangsan" ,6000,sr);
t1.input();
t1.print();
t2.print();
Grade wlgc2016;
wlgc2016.input();
wlgc2016.print();
}