高手救命啊!!真心求得一50行左右的简单的C++程序,要求:有基类,派生类,包含构造函数。

来源:百度知道 编辑:UC知道 时间:2024/06/23 22:52:50

#include <iostream>
using namespace std;
struct Exam{
Exam(int m):mark(m){ };
int mark;
virtual ~Exam(){ };//基类要有虚析构函数
}
struct Chinese:public Exam{
Chinese(int q,int r):Exam(q+r),reading(q),writing(r){ }
int reading;
int writing;
void report(){
cout<<"语文考试成绩为:阅读卷"<<reading<<",作文卷"<<writing<<"分,共"<<mark<<"分";
}
}
int main(){
Chinese Zhangsan(63,84);
Zhangsan.report();
cin.get();
}
这是一个关于语文考试的程序,用构造函数填成绩,用成员函数输出,另外也用到了基类要有虚析构函数的知识,不到25行,应该很经典了。有基类、派生类、构造函数、析构函数、成员函数、虚函数、继承层次,完全符合要求!

// Test7.1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<stdio.h>
#include <iostream>
using namespace std;;

class test //基类
{
public:
int a,b;
test()//构造函数
{
a = 20;
b = 9;
}
~test()//析构函数