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