Skip to content

Instantly share code, notes, and snippets.

@Cee
Created April 23, 2014 06:55
Show Gist options
  • Save Cee/11205054 to your computer and use it in GitHub Desktop.
Save Cee/11205054 to your computer and use it in GitHub Desktop.
Zht‘s C++ Homework
//
// main.cpp
// Test
//
// Created by CirnoCee on 4/23/14.
// Copyright (c) 2014 CirnoCee. All rights reserved.
//
#include <iostream>
#include <string.h>
using namespace std;
class Data {
public:
string name;
void print();
};
class Teacher : public Data {
public:
double sal;
void print() {
cout << "This is a teacher" << endl;
cout << name << endl;
cout << sal << endl;
}
};
class Student: public Data {
public:
string id;
void print() {
cout << "This is a student" << endl;
cout << name << endl;
cout << id << endl;
}
};
class Postgrad: public Student {
public:
string dn;
void print() {
cout << "This is a postgraduate" << endl;
cout << name << endl;
cout << dn << endl;
}
};
class Tpost: public Teacher, public Postgrad {
public:
void print() {
cout << "This is a tpost" << endl;
cout << Teacher::name << endl;
cout << dn << endl;
cout << sal << endl;
}
};
int main(int argc, const char * argv[])
{
Teacher t;
t.name = "Teacher A";
t.sal = 100;
t.print();
Student s;
s.name = "Student B";
s.id = "123456789";
s.print();
Postgrad p;
p.name = "Postgrad C";
p.dn = "Chinese";
p.print();
Tpost tp;
tp.Teacher::name = "Tpost D";
tp.dn = "Math";
tp.sal = 20;
tp.print();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment