WEEK 1 Project 1: Understand the access qualifier of the members in the base class and the Inheritance Method of the derived class

Source: Internet
Author: User
/** Copyright and version declaration section of the Program * Copyright (c) 2012, student * All rightsreserved from computer College of Yantai University. * Author: Li Yang * Completion Date: July 15, May 24, 2013 * version: v1.0 * input Description: none * Problem description: none * program output: none */# include <iostream> using namespace std; class StudentA // (1) modify the access qualifier of each data member and member function in the studentA class, and observe the phenomenon {public: StudentA (int n, string nam, char s); void showA ();~ StudentA () {} private: int num; string name; char sex;}; StudentA: StudentA (int n, string nam, char s) {num = n; name = nam; sex = s;} void StudentA: showA () {cout <"num:" <num <endl; cout <"name: "<name <endl; cout <" sex: "<sex <endl;} class StudentB: private StudentA // (2) modify the inheritance method, and observe the phenomenon {public: StudentB (int n, string nam, char s, int a, string ad); void showB ();~ StudentB () {} private: int age; string addr;}; StudentB: StudentB (int n, string nam, char s, int a, string ad): StudentA (n, nam, s) {age = a; addr = ad;} void StudentB: showB () {showA (); cout <"age:" <age <endl; cout <"address:" <addr <endl;} int main () // (3) Think about the change of access Qualifier and inheritance method, what will happen and explain {StudentB stud1 (10010, "Wang-li", 'F', 19, "115 Beijing Road, Shanghai "); studentB stud2 (10011, "Zhang-fun", 'M', 21, "213 Shanghai Road, Beijing"); StudentA stud3 (20010, "He-xin ", 'M'); stud1.showB (); stud2.showB (); stud3.showA (); return 0 ;}

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.