当前位置:编程学习 > C/C++ >>

求一用c++编的程序

定义一过学生类,有姓名,性别,年龄,再定义一过计算机类,有专业,年级,由两个类产生软件类有英语,数学,计算机成绩,编程输出软件专业每个学生的基本情况及英语,数学,计算机成绩,总分,平均分,要用运算符重载,输入输出,且程序通用
答案:
#include<iostream.h>


class Student
{
public:
char name[100];
char 易做图[100];
int old;
};
class Computer
{
public:
char subject[100];
char grade[100];
};

class Soft:public Student,public Computer
{
public:
int eng;
int math;
int computer;
public:
friend ostream& operator <<(ostream&,Soft&);
friend istream& operator >>(istream&,Soft&);

};

ostream& operator << (ostream& output,Soft& a)
{
output<<"姓名是:"<<a.name<<endl;
output<<"性别是:"<<a.易做图<<endl;
output<<"年龄是:"<<a.old<<endl;
output<<"专业是:"<<a.subject<<endl;
output<<"年级是:"<<a.grade<<endl;
output<<"英语成绩是:"<<a.eng<<endl;
output<<"数学成绩是:"<<a.math<<endl;
output<<"计算机成绩是:"<<a.computer<<endl;
return output;
}
istream& operator >> (istream& input,Soft& a)
{
input>>a.name>>a.易做图>>a.old>>a.subject>>a.grade>>a.eng>>a.math >>a.computer;
return input;
}

int main()
{
int i,n;
Soft a[10];
cout<<"学生个数:";
cin>>n;//输入学生个数;
cout<<"姓名性别 年龄 专业 年级 英语 数学 计算机(每输入一个回车) "<<endl;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n;i++) cout<<a[i]<<endl;
return 0;
}
#include <iostream.h>
#include <string.h>
class Cstudent
{

public:
Cstudent(char*n,char *s,int a)
{
name=new char[strlen(n)+5];
strcpy(name,n);

易做图=new char[strlen(s)+2];
strcpy(易做图,s);

age=a;

}
void display()
{

cout<<"学生基本信息:"<<endl;
cout<<" 姓名:"<<name<<endl;
cout<<" 性别:"<<易做图<<endl;
cout<<" 年龄:"<<age<<endl;


}
char *getName()
{ return name; }

char *getSex()
{return 易做图;}

int getAge()
{return age;}

~Cstudent()
{delete [] name;delete[] 易做图;}


protected:
char *name;
char *易做图;
int age;


};

class Ccomputer
{

public:
Ccomputer(char* p,int g)
{

professional=new char[strlen(p)+1];
strcpy(professional,p);

grade=g;



}




void display()
{

cout<<"系别:计算机科学系"<<endl;
cout<<"专业:"<<professional<<endl;
cout<<"年级:"<<grade<<endl;



}

char* getP()
{return professional;}
int getG()
{return grade;}



~Ccomputer()
{delete [] professional;}

protected:

int grade;
char *professional;

};

上一个:帮我做下C++的卷子
下一个:关于C++的一个题目,急求!!!

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,