| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1832 人关注过本帖
标题:动态数组 但是函数进不去
只看楼主 加入收藏
愿o圆o安
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2017-3-13
结帖率:25%
收藏
 问题点数:0 回复次数:2 
动态数组 但是函数进不去
#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();
}
搜索更多相关主题的帖子: teacher private include public income 
2017-03-30 21:35
愿o圆o安
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2017-3-13
收藏
得分:0 
void Grade::input()
{
    int i,flag=1;
    i=1;
    cout<<"please enter student xinxi:\n";
    while(flag==1&&length<10)
    {
        s[length].input();
        length++;
        cout<<"please if or not (1/0)ernter:";
        cin>>flag;
    }
}


红色的改成while语句之后就可以运行了   求解
2017-03-30 21:46
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:0 
for的第二个参数为真时,继续执行循环,为假时退出循环。
2017-03-31 21:08
快速回复:动态数组 但是函数进不去
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014947 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved