OJ Brush problem--15th week C + + Exercise object Conversion

Source: Internet
Author: User

Description

Define a teacher (teacher) class (teacher number, name, gender, salary) and a student (student) class (school number, name, gender, score), both of which have part of the data members are the same, num (number), name (name), sex (gender). Write a program that converts a student object (student) to a teacher (teacher) class, porting only 3 of the same data members to the past. It can be conceived as: A student who graduated from college and stayed in school as a teacher, his original part of the data is still useful to the current teacher status, should be retained and become part of their teacher data.

Input

A teacher's information and a student's information

Output

Information about students and the conversion of students to teachers

Sample Input
10001 Li f 1234.520010 Wang m 89.5
Sample Output
student1:num:20010name:wangsex:mscore:89.50teacher2:num:20010name:wangsex:mpay:1500.00
/* All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: June 17, 2015 * Version number: v1.0 * * #include <iostream> #include <iomanip> #include <c    String>using namespace Std;class student{public:int nume;    Char nam[20];    char s;    float sc;public:student (int num,char Name[],char sex,float score); void display ();};    Class Teacher{private:int Nume;    Char nam[20];    char s;    float p;public:teacher (int num,char name[],char sex,float pay);    Teacher (Student &stu);    void display (); void Setpay (double n);};    student::student (int num,char Name[],char sex,float score) {nume=num;    strcpy (Nam,name);    S=sex; Sc=score;}    Teacher::teacher (int num,char name[],char sex,float pay) {nume=num;    strcpy (Nam,name);    S=sex; P=pay;}    Teacher::teacher (student&stu) {nume=stu.nume;    strcpy (Nam,stu.nam); S=stu.s;} void Student::d isplay () {cout<< "num:" <<nume<< "\nname:" <<nam<< "\nsex:" <<s< < "\nscore:" <<sc<< "\ n";} void Teacher::d isplay () {cout<< "num:" <<nume<< "\nname:" <<nam<< "\nsex:" <<s< < "\npay:" <<p<< "\ n";} void Teacher::setpay (double n) {p=n;}    int main () {cout<<setiosflags (ios::fixed);    Cout<<setprecision (2);    int num;    Char name[20];    char sex;    Float score;    float pay;    cin>>num>>name>>sex>>pay;    Teacher Teacher1 (Num,name,sex,pay);    cin>>num>>name>>sex>>score;    Student student1 (Num,name,sex,score);    cout<< "Student1:" <<endl;    Student1.display ();    Teacher Teacher2=teacher (STUDENT1);    Teacher2.setpay (1500);    cout<< "Teacher2:" <<endl;    Teacher2.display (); return 0;}
Learning experience: I want to brush the problem brush, continue efforts!!!

OJ Brush problem--15th week C + + Exercise object Conversion

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.