C + + toward ocean--46 (teacher and cadre class, multiple inheritance, derivation)

Source: Internet
Author: User

* * Copyright (c) 2016, School of Computer and Control engineering, Yantai University * All rights reserved. * File name: Text.cpp * Changxuan * Public Number: Worldhello * Completion Date: May 8, 2016 * version number: V1.0 * Problem Description: According to class diagram, write out program * Program input: NO * program output: See operating results */#include <stri  Ng> #include <iostream> using namespace std;      Class Teacher {public:teacher (string nam,int a,char s,string tit,string ad,string t);  void display ();      Protected:string name;      int age;      char sex;      string title;      String addr;  String Tel;    }; Teacher::teacher (String nam,int a,char s,string tit,string ad,string t): Name (NAM), age (a), sex (s), title (tit), addr (AD),      Tel (t) {} void Teacher::d isplay () {cout<< "name:" <<name<<endl;      cout<< "Age" <<age<<endl;      cout<< "Sex:" <<sex<<endl;      cout<< "title:" <<title<<endl;      cout<< "Address:" <<addr<<endl;  cout<< "Tel:" <<tel<<endl; } class Cadre {Public:cadre (string nam,int A,char s,string p,string ad,string t);  void display ();      Protected:string name;      int age;      char sex;      String post;      String addr;  String Tel;    };     Cadre::cadre (String nam,int a,char s,string p,string ad,string t): Name (NAM), age (a), sex (s), post (p), addr (AD), tel (t) {}      void cadre::d isplay () {cout<< "name:" <<name<<endl;      cout<< "Age:" <<age<<endl;      cout<< "Sex:" <<sex<<endl;      cout<< "Post:" <<post<<endl;      cout<< "Address:" <<addr<<endl;  cout<< "Tel:" <<tel<<endl; } class Teacher_cadre:public Teacher,public cadre {public:teacher_cadre (string nam,int a,char s,string tit,str      ing p,string ad,string t,float W);  void Show ();  Private:float wage;    }; Teacher_cadre::teacher_cadre (String nam,int a,char s,string t,string p,string ad,string tel,float W): Teacher (nam,a,s , T,ad,tel), cadre (Nam,a,s,p,ad,tel), wage (W) {}   void Teacher_cadre::show () {Teacher::d isplay ();      cout<< "Post:" <<cadre::p ost<<endl;  cout<< "Wages:" <<wage<<endl; } int main () {Teacher_cadre Te_ca ("Wang-li", "F", "Prof.", "President", "135 Beijing Road,shanghai", "(021) 612345      67 ", 1534.5);      Te_ca.show ();  return 0;   }



Operation Result:


C + + toward ocean--46 (teacher and cadre class, multiple inheritance, derivation)

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.