下面的
程序的主要的
代码都在
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;
}