INTERMIDIATE PROGRAMMING
CMPSC 122
LAB 9: INHERITANCE AND POLYMORPHISIM
SPRING 2017
Goal
In this assignment students will practice inheritance and polymorphism in C++.Objectives
Class Programming: Given an object-based entity with specific functionality, students should be able to create an equivalent C++ class to represent it.
Problem:
1. Add to class patientType the date when the patient was admitted in the hospital, and the date when the patient was discharged from the hospital (Use the class Date class you wrote in the prelab) to store admit date, discharge date. Modify constructors and add member functions to initialize access, and manipulate the new added data members.
2. In main(), create a vector of pointers to type TeamPerson. Fill it up with at least three objects. One of TeamPerson, one of doctorType and one of patientType.
3. Print all the data of the three objects of the vector. Make sure each object is printed according to its print function.
Rubric
Total: 18 pts
a. Question 1: 8 pts
b. Question 2: 5 pts
c. Question 3: 5 pts
Please follow the program documentation and submission guidelines to earn full credit.
Submission
ZIP YOUR PROJECT (.sln included) in a folder, call it “Lab9” and upload it on Canvas under “Lab 9”. Make sure that your submission was successful. You can upload as many times as you like on Canvas, however only the second submission will be graded. Make sure to read the syllabus for more details about labs submission and late submission.
Honor code
“I pledge on my honor that I have not given or received any unauthorized assistance on this assignment/examination”
New folder/Date.cppNew folder/Date.cpp
#include<iostream>
#include<ostream>
#include"Date.h"
usingnamespace std;
//Overloaded constructor
Date::Date(int nmonth,int nday,int nyear)
{
day = nday;
year = nyear;
month = nmonth;
return;
}
//Function to get the day
intDate::getDay()
{
return day;
}
//Function to get the year
intDate::getYear()
{
return year;
}
//Fucntion to get the Month
intDate::getMonth()
{
return month;
}
//Funtion to set the day
voidDate::setDay(int n)
{
day = n;
return;
}
//fucntion to set the year
voidDate::setYear(int y)
{
year = y;
return;
}
//function to set the month
voidDate::setMonth(int m)
{
month = m;
return;
}
ostream&operator<<(ostream& os,constDate&p){
os <<"Month: "<< p.month <<'\n'
<<"Day: "<< p.day <<'\n'
<<"Year: "<< p.year << endl;
return os;
}
/*the specialty of doctor is NLX
the patient's id is 9527
the patient's age is 21
the patient's birthday is Month: 1
Day: 15
Year : 1997
'\\psbdfilesrvr.psu-erie.bd.psu.edu\student\YVW5455\Private\desktop\prelab\prela
b'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.Defaulting to Windows directory.
Press any key to continue . . .*/
New folder/Date.h
//#pragma once
#ifndef DATE_H
#define DATE_H
#include<ostream>
using namespace std;
//Defi.
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
1. INTERMIDIATE PROGRAMMING
CMPSC 122
LAB 9: INHERITANCE AND POLYMORPHISIM
SPRING 2017
Goal
In this assignment students will practice inheritance and
polymorphism in C++.Objectives
Class Programming: Given an object-based entity with specific
functionality, students should be able to create an equivalent
C++ class to represent it.
Problem:
1. Add to class patientType the date when the patient was
admitted in the hospital, and the date when the patient was
discharged from the hospital (Use the class Date class you
wrote in the prelab) to store admit date, discharge date. Modify
constructors and add member functions to initialize access, and
manipulate the new added data members.
2. In main(), create a vector of pointers to type TeamPerson.
Fill it up with at least three objects. One of TeamPerson, one of
doctorType and one of patientType.
3. Print all the data of the three objects of the vector. Make sure
each object is printed according to its print function.
Rubric
Total: 18 pts
a. Question 1: 8 pts
b. Question 2: 5 pts
c. Question 3: 5 pts
Please follow the program documentation and submission
guidelines to earn full credit.
Submission
2. ZIP YOUR PROJECT (.sln included) in a folder, call it “Lab9”
and upload it on Canvas under “Lab 9”. Make sure that your
submission was successful. You can upload as many times as
you like on Canvas, however only the second submission will be
graded. Make sure to read the syllabus for more details about
labs submission and late submission.
Honor code
“I pledge on my honor that I have not given or received any
unauthorized assistance on this assignment/examination”
New folder/Date.cppNew folder/Date.cpp
#include<iostream>
#include<ostream>
#include"Date.h"
usingnamespace std;
//Overloaded constructor
Date::Date(int nmonth,int nday,int nyear)
{
day = nday;
year = nyear;
month = nmonth;
return;
}
//Function to get the day
intDate::getDay()
{
return day;
3. }
//Function to get the year
intDate::getYear()
{
return year;
}
//Fucntion to get the Month
intDate::getMonth()
{
return month;
}
//Funtion to set the day
voidDate::setDay(int n)
{
day = n;
return;
}
//fucntion to set the year
voidDate::setYear(int y)
{
year = y;
return;
}
//function to set the month
voidDate::setMonth(int m)
{
month = m;
return;
}
4. ostream&operator<<(ostream& os,constDate&p){
os <<"Month: "<< p.month <<'n'
<<"Day: "<< p.day <<'n'
<<"Year: "<< p.year << endl;
return os;
}
/*the specialty of doctor is NLX
the patient's id is 9527
the patient's age is 21
the patient's birthday is Month: 1
Day: 15
Year : 1997
'psbdfilesrvr.psu-
erie.bd.psu.edustudentYVW5455Privatedesktopprelabprela
b'
CMD.EXE was started with the above path as the current dire
ctory.
UNC paths are not supported.Defaulting to Windows director
y.
Press any key to continue . . .*/
New folder/Date.h
//#pragma once
#ifndef DATE_H
#define DATE_H
#include<ostream>
5. using namespace std;
//Define a new class called Date
class Date {
public:
//The constructors of the class
Date() {};
Date(int nmonth, int nday, int nyear);
//The member functions of the class
int getDay();
int getYear();
int getMonth();
void setDay(int n);
void setYear(int y);
void setMonth(int m);
6. friend ostream& operator<<(ostream& os, const Date &p);
private:
//The private data of the class
int day;
int month;
int year;
};
#endif
New folder/Person.cpp
#include <iostream>
#include <string>
using namespace std;
#include "Date.h"
10. friend ostream& operator<<(ostream& os, const TeamPerson
&p);
protected:
string fullName;
Date dob;
};
class doctorType : public TeamPerson
{
private:
string specialty;
public :
doctorType() {};
doctorType(string s) :specialty(s) {};
void Setspecialty(string s)
{
11. specialty = s;
};
string Getspecialty()const
{
return specialty;
};
virtual void print()const
{
cout << " the specialty of doctor is " << specialty << endl;
}
/*friend ostream& operator<<(ostream& os, const TeamPerson
&p)
{
os << " the specialty of doctor is " << p.specialty << " the
doctor's name is " << p.fullName << "the doctor's date of birth
is " << p.dob;
return os;
12. }*/
};
class patientType : public TeamPerson
{
private:
double id;
double age;
public:
patientType() {};
patientType(double a, double id) : age(a),id(id){};
void SetId(double id)
{
14. friend ostream& operator<<(ostream& os, const TeamPerson
&p)
{
os << " the attending physician's nane is " << p.fullName<<
"the doctor's date of birth is " << p.dob;
return os;
}
void print() {
cout << " the patient's id is " << id << endl;
cout << " the patient's age is " << age << endl;
/*cout << "the physician's name is " << fullName << endl;
cout << "the birthday of patient is " << dob << endl;*/
}
};
#endif
New folder/prelab.sln
15. Microsoft Visual Studio
Solution
File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") =
"prelab", "prelabprelab.vcxproj", "{422FEECC-AF24-4231-
A5BE-F273428F5B19}"
EndProject
Global
GlobalSection(