wa3soln - ECE 462 Written Assignment 3 Due: 8:30AM, October...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 462 Written Assignment 3 Due: 8:30AM, October 31, 2011 Name: PUID: 1 C++ Multiple Inheritance The program intends to express the concept A teaching assistant is a graduate student and teacher. using multiple inheritance in C++. Draw the UML class hierarchy of this program, including all attributes. You do not have to draw the methods (namely, the member func- tions). Unfortunately, the program has some problems at compilation. Change the program so that it successfully compiles and does what it originally appears to have been designed to do (i.e. dont make it compile by deleting everything.) What is the output of this program? It will be most useful if you do this without just running the program. #include <iostream> #include <string> using namespace std; class Person { public: Person(string n, int a): name(n), age(a) { } void print() { cout << "Person::print" << endl; cout << " name: " << name << endl; cout << " age: " << age << endl; } 1 virtual Person() { } private: const string name; int age; }; class Teacher: public Person { public: Teacher(string n, int a, string s): Person(n, a), subject(s) { } private: void print() { cout << "Teacher::print" << endl; Person::print(); cout << " subject: " << subject << endl; } string subject; }; class Student: public Person { public: Student(string n, int a, string d): Person(n, a), department(d) { } void print() { cout << "Student::print" << endl; Person::print(); cout << " department: " << department << endl; } private: string department; }; class GradStudent: public Student { 2 public: GradStudent(string n, int a, string d, string v): Person(n, a), Student(n, a, d), adviser(v) { } void print() { cout << "GradStudent::print" << endl; Student::print(); cout << " adviser: " << adviser << endl; } private: string adviser; }; class TeachingAssistant: public GradStudent, public Teacher { public: TeachingAssistant(string n, int a, string s, string d, string v, int y): Person(n, a), GradStudent(n, a, d, v), Teacher(n, a, s), salary(y) { } void print() { cout << "TeachingAssistant::print" << endl; GradStudent::print(); Teacher::print(); cout << " salary: " << salary << endl; } private: int salary; }; int main(int argc, char * argv) { Person * ta = new TeachingAssistant("Smith", 25, "Java", "ECE", "Johnson", 2000); ta -> print(); / * ATTENTION: should print ALL attributes * / 3 delete ta; return 0; } Answer: # i n c l u d e < i o s t r e a m > # i n c l u d e...
View Full Document

Page1 / 13

wa3soln - ECE 462 Written Assignment 3 Due: 8:30AM, October...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online