Questions and codes:
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp * Author: Zhang Weijing * Completion date: May 10, 2016 * Version number: v1.0 * * Problem Description: Read program * Input Description: * Program output: */#include <iostream>using Namespac E std;class a{private:int x;protected:int y;public:int z; A (int a,int b,int c) {x=a; Y=b; Z=c; } int Getx () {return x;} int Gety () {return y;} void ShowA () {cout<< "x=" <<x<< ' \ t '; cout<< "y=" <<y<< ' t '; cout<< "z=" <<z<< ' \ n '; }};class B:public A//modify point (see following reading requirements) {Private:int m,n;public:b (int a,int b,int c,int d,int E): A (a,b,c) { M=d; N=e; } void Show () {cout<< "m=" <<m<< ' \ t ' << "n=" <<n<< ' \ n '; cout<< "x=" <<getx () << ' t '; cout<< "y=" <<y<< ' \ t ' << "z=" <<z<< ' \ n '; } int Sum () {return (Getx () +y+z+m+n); }};int Main () {B B1 (1,2,3,4,5);B1. ShowA (); B1. Show (); cout<< "sum=" <<b1. Sum () << ' \ n '; cout<< "x=" <<b1. Getx () << ' \ t '; cout << "y=" <<b1. Gety () << ' \ t '; cout << "z=" <<b1.z<< ' \ n '; return 0;}
Expected Result:
X=1 y=2 z=3
X=1 y=2 z=3
M=4 n=5
X=1 y=2 z=3
Sum=15
X=1 y=2 z=3
Operation Result:
Process Analysis:
First initialize the object of B B1, assign the variables, then B1.showa (), Output x=1 y=2 z=3, then b1.show () output m=4 n=5 x=1 y=2 z=3, then output sum =15, x=1 y =2 z=3
11th Week Reading Procedure (supplement)----(2)