11th Week Reading Procedure (supplement)----(2)

Source: Internet
Author: User
Tags gety

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.