12th Week Item-1

Source: Internet
Author: User

The teacher (teacher) class and the Cadre (Cadre) class are defined separately, and the new class Teacher_cadre (teacher and cadre) are derived from these two classes by multiple inheritance methods. Requirements:
(1) in two base classes, they contain data members such as name, age, gender, address, telephone, and so on.
(2) in the teacher class also contains the data member title (title), in the Cadre class also contains the data member post (title),
// Data member wages (payroll) is also included 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) The display function in the teacher class is called in the member function show of the derived class Teacher_cadre.
// Export your name, age, gender, title, address, phone, and then use the cout statement to export your job title and salary.
#include <iostream>
#include <string>
using namespace Std;
Class Teacher
{
Public
void display ();
Teacher (string n, int a, int s, string ad, String t,string ti)
{
name = N; age = A; sex = s; add = AD; tel = t; title = Ti;
}
Protected
String name;
int age;
int Sex;//1-man 0-women
string add;
String Tel;
string title;
};
void Teacher::d isplay ()
{
cout << "Name:" << name << "Age:" << ages << "Gender:";
if (age = = 0)
cout << "Women";
Else
cout << "man";
cout << "Address:" << add << "Phone:" << tel << endl << "title:" << title << End L
}
Class Cadre
{
Public
void display ();
Cadre (string n, int a, int s, string ad, string t,string p)
{
name = N; age = A; sex = s; add = AD; tel = t; Post = P;
}
Protected
String name;
int age;
int Sex;//1-man 0-women
string add;
String Tel;
String post;
};
/*void cadre::d isplay ()
{
cout << "Name:" << name << "Age:" << ages << "Gender:";
if (age = = 0)
cout << "Women";
Else
cout << "man";
cout << "Address:" << add << "Phone:" << Tel << "title:" << post;
}*/
Class Teacher_cadre:public Teacher,public Cadre
{
Public
void Show ();
Teacher_cadre (string n, int a, int s, string ad, String t, String Ti, String p,float w):
Teacher (n, a, S, ad, T, TI), cadre (n, a, S, AD, T, p)
{
Wages = W;
}
Private
float wages;
};
void Teacher_cadre::show ()
{
Teacher::d isplay ();
cout << "title:" << cadre::p ost << Endl << "Salary:" << wages;
}
int main ()
{
Teacher_cadre A ("Zhang San", 1, "Xiaobude", "10010", "Wage earners", "workers", 10000);
A.show ();








while (1);
}

12th Week Item-1

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.