论坛首页· 友情链接申请·申请版主· 广告投放· 道具中心· 设为首页· 收藏本站
发新话题
打印

c++的一道题目~~~~~~~~

c++的一道题目~~~~~~~~

下面的程序的主要的代码都在int main下面,请帮我下把main里的东西弄到上面来。就是把那些功能封装在类中。
如下面改成:
int main()
{
student a;
  welcome();
  int choic;
  int n;
  int i;
  while(choic!=0)
  {
      cin>>choic;
      switch(choic)
    {        
    case 1:
a.Creat();
        break;
case 2:
a.Output
    break;
    default :cout < <"您的输入有误,请重试!\n";
    }
  }
  return 0;
}
复制内容到剪贴板
代码:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#define MIN 1

class student
{
    long num;
    string name;
    char sex;
    float math;
    float english;
    float sport;
    float Cplus;
    float sum;
    float ave;

public:
    static int total;
public:
    void Creat();
    void Output();
};

int student::total=0;
void student::Creat()
{
    cout < <"欢迎进入学生的信息建立系统!" < <endl;
    cout < <"学号" < <"\t" < <"姓名" < <"\t" < <"性别" < <"\t" < <"高等数学" < <"\t" < <"英语" < <"\t" < <"大学体育" < <"\t" < <"C++面向程序设计" < <endl;
    cin>>num>>name>>sex>>math>>english>>sport>>Cplus;
    student::total++;
}

void student::Output()
{
cout < <"学号" < <"\t" < <"姓名" < <"\t" < <"性别" < <"\t" < <"高等数学" < <"\t" < <"英语" < <"\t" < <"大学体育" < <"\t" < <"C++面向程序设计" < <endl;
cout < <num < <"\t" < <name < <"\t" < <sex < <"\t" < <math < <"\t" < <"\t" < <english < <"\t" < <sport < <"\t" < <"\t" < <Cplus < <endl;
}

void welcome()
{
    cout < <"\t        设计:                " < <endl;
    cout < <"\t***************************************************" < <endl;
    cout < <"\t*            欢迎进入学生成绩管理系统            *" < <endl;
    cout < <"\t*                                                  *" < <endl;
    cout < <"\t*    1:输入            2:输出                      *" < <endl;
    cout < <"\t*                                                  *" < <endl;
    cout < <"\t*                                                  *" < <endl;
    cout < <"\t****************************************************" < <endl;
    cout < <endl;
    cout < <"请选择你需要的选项:";
}
  

int main()
{
  student *stu=new student[MIN];
  welcome();
  int choic;
  int n;
  int i;
  while(choic!=0)
  {
      cin>>choic;
      switch(choic)
    {        
    case 1:
        cout < <"你想输入多少个学生的基本信息?" < <endl;
        cin>>n;
        for(i=0;i <n;i++)
    {
            if(student::total + 1>MIN)
        {
            student *stuTemp = new student[student::total+1];
            for(int j = 0; j < student::total; j++)
            {
            stuTemp[j] = stu[j];
            }
            delete [] stu;
            stu = stuTemp;
   
        }

            stu[student::total].Creat();
        }
        break;      
      case 2:
        for (i=0;i <student::total;i++)
        stu[i].Output();
        break;
case 3:
    break;
case 4:
    break;
case 5:
    break;
case 6:
    break;
case 7:
    break;
case 8:
    break;
case 9:
    default :cout < <"您的输入有误,请重试!\n";
    }
  }
  return 0;
}

TOP

自己先改,哪里不会再问好吗?
因为梦想而努力,因为有你而精彩!
mail: qianzongming@gmail.com

TOP

发新话题