第12周项目 程序阅读(5.e)

来源:互联网 发布:恒腾网络股票行情 编辑:程序博客网 时间:2024/06/05 00:45
/**Copyright (c)2015,烟台大学计算机与控制工程学院*All rights reserved.*文件名称:score.cpp*作    者:惠睿*完成日期:2015年5月27日*版 本 号:v1.0**问题描述:阅读程序,写出程序的运行结果并理解。*程序输入:无输入。*程序输出:输出调用函数后的值。*/#include <iostream>using namespace std;class A{protected:    int a,b;public:    A(int aa, int bb):a(aa), b(bb) {}    void printA()    {        cout<<"a: "<<a<<"\tb: "<<b<<endl;    }    int getA()    {        return a;    }};class B: public A{    int c;public:    B(int aa, int bb, int cc):A(aa,bb),c(cc) {}    void printB()    {        cout<<"a: "<<a<<"\tb: "<<b<<"\tc: "<<c<<endl;    }};void f(A x){    cout<<"aaaaah, my a: "<<x.getA()<<endl;}int main(){    A a(1,1);    B b(2,3,4);    f(a);    f(b);    return 0;}


运行结果:

0 0
原创粉丝点击