リロードタイプ変換の演算子

2791 ワード

/*
*            :
*Copyright(c)2013,           
*All rights reserved.
*    :
*  :   
*    :2014 4 29 
*   :v0.1
*             :
*    : 
*    :    Teacher(  )    Student(  ) ,    ,            。
*    :
*    :
*    :
*    :
*    :
*/

#include <iostream>
#include <cstring>
using namespace std;
class Student
{
private:
    int num;
    char name[20];
    char sex;
    double score;
public:
    Student();
    int get_num()
    {
        return num;
    }
    char *get_name()
    {
        return name;
    }
    char get_sex()
    {
        return sex;
    }
    friend istream &operator>>(istream &,Student &);
    friend ostream &operator<<(ostream &,Student &);
};
class Teacher
{
private:
    int num;
    char name[20];
    char sex;
    int pay;
public:
    Teacher();
    Teacher(Student &);
    friend istream &operator>>(istream &,Teacher &);
    friend ostream &operator<<(ostream &,Teacher &);
};
Student::Student()
{
    int n;
    double sco;
    char nam[20],s;
    num=n;
    strcpy(name,nam);
    sex=s;
    score=sco;
}
istream &operator>>(istream &input,Student &stu)
{
    input>>stu.num>>stu.name>>stu.sex>>stu.score;
    return input;
}
ostream &operator<<(ostream &output,Student &stu)
{
    output<<"num:"<<stu.num<<"
name:"<<stu.name<<"
sex:"<<stu.sex<<"
score:"<<stu.score<<endl; return output; } Teacher::Teacher() { int n,p; char nam[20],s; num=n; strcpy(name,nam); sex=s; pay=p; } Teacher::Teacher(Student &stud) { num=stud.get_num(); strcpy(name,stud.get_name()); sex=stud.get_sex(); pay=20000; } istream &operator>>(istream &input,Teacher &t) { input>>t.num>>t.name>>t.sex>>t.pay; return input; } ostream &operator<<(ostream &output,Teacher &t) { output<<"num:"<<t.num<<"
name:"<<t.name<<"
sex:"<<t.sex<<"
pay:"<<t.pay; return output; } int main() { Teacher t1,t2; Student t3; cout<<" "<<endl; cin>>t1; cout<<" "<<endl; cout<<t1<<endl; cout<<" "<<endl; cin>>t3; cout<<" "<<endl; cout<<t3<<endl; t2=Teacher(t3); cout<<" "<<endl; cout<<t2<<endl; return 0; }

結果:
心得体得:記憶は掌の中の水のようで、あなたが広げても握りしめても、結局指の隙間から一滴がきれいに流れます.