12th Week Task 2 (define teacher (teacher) class and Cadre (Cadre) class respectively, adopt multiple inheritance method to derive new class Teacher_cadre (teacher and cadre) by these two classes

Source: Internet
Author: User
Tags inheritance
/* (Start of program header comment) * Copyright and version declaration of the program part * Copyright (c) 2011, Yantai University School of Computer Students * All rights reserved. * File Name: * Author: Shangpeng * Completion Date: May 8, 2012 * Version number: * Yes Description of task and solution method * Input Description: * Problem Description: Define teacher (Teacher) class and Cadre (cadre) category respectively, and adopt multiple inheritance method to derive new class Teacher_cadre (teacher and cadre) from these two classes. 
Requirements: (1) in two base classes include name, age, gender, address, telephone and other data members. 
(2) The teacher class also contains the data member title (title), which also contains the data member post (title) in the Cadre class, and the data member wages (payroll) in the Teacher_cadre class. 
(3) The name, age, gender, address, telephone and other data members in the two base classes are given the same name, specifying the scope when referencing the data members. 
(4) Declare member functions in the class body, and define member functions outside the class.
(5) In the member function of the derived class Teacher_cadre, call the display function in the teacher class, output name, age, gender, title, address, phone, and then use the cout statement to output the job and salary.  

* Program Output: * Note End of program header */#include <iostream> #include <string> using namespace std;  
	Class Teacher {Public:teacher (string n, int A, char s, string add, Long int te, string ti);  
void display ();  
	Protected:string name;  
	int age;  
	char sex;  
	string address;  
	long int Tel;  string title;  

Title}; Class Cadre {Public:cadre (string n, int A, char s, string add, Long int T, string p);  
void display ();  
	Protected:string name;  
	int age;  
	char sex;  
	string address;  
	long int Tel;  String post;  

Duties}; Class Teacher_cadre:public Teacher, public cadre//declaring multiple inheritance of the Teacher_cadre class {Public:teacher_cadre (string n, int a, C  
	Har s, string add, Long int t, string ti, String p,double w);  
void Show ();  
Protected:double wages;  

};  
	Teacher::teacher (string n, int A, char s, string add, Long int te, string ti) {name = N;  
	age = A;   
	sex = s;  
	address = add;  
	tel = te;  
title = Ti;  
	} cadre::cadre (string n, int A, char s, string add, Long int T, string p) {name = N;  
	age = A;   
	sex = s;  
	address = add;  
	tel = t;  
Post = P;  
	} void Teacher::d isplay () {cout << "name:" << name << Endl;  
	cout << ' Age: ' << age << Endl;  
	cout << "Sex:" << sex << Endl; cout << "Address:" << address <<Endl  
	cout << "Tel:" << Tel << endl;  
cout << "title:" << title << Endl;  
	} void Cadre::d isplay () {cout << "name:" << name << Endl;  
	cout << ' Age: ' << age << Endl;  
	cout << "Sex:" << sex << Endl;  
	cout << "Address:" << address << Endl;  
	cout << "Tel:" << Tel << endl;  
cout << "Post:" << post << Endl;  
	} void Teacher_cadre::show ()//In the member function of the derived class Teacher_cadre called the display function in the Teacher class {Teacher::d isplay ();  cout << "Post:" << cadre::p ost << Endl;  
For data members in two base classes, specify the scope cout << wages: << wages << Endl When referencing these data members with the same name. } teacher_cadre::teacher_cadre (string n, int A, char s, string add, Long int t, string ti, String p,double w): Teacher (n  
, a, S, add, T, TI), cadre (n, a, S, add, T, p) {wages = W; } int main () {Teacher_cadre ct1 ("Yong Gang", ",", ' m ', "shAndong ", 152999111," director "," technical worker ", 10000);  

	Ct1.show ();  

	cout << Endl;  

	System ("PAUSE");  
return 0;  }


Accumulated experience:

This knowledge point need to read many times, very good understanding but very easy to make mistakes, to read more textbooks, especially when the number of data members, will be very messy, to carefully write

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.