SlideShare a Scribd company logo
1 of 16
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.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>
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);
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"
#include "Person.h"
TeamPerson::TeamPerson() {}
TeamPerson::TeamPerson(string f, Date d) :fullName(f), dob(d)
{}
void TeamPerson::SetFullName(string firstAndLastName) {
fullName = firstAndLastName;
return;
}
string TeamPerson::GetFullName() const {
return fullName;
}
/*ostream& operator<<(ostream& os, const TeamPerson &p) {
os << "The borrower full name is: " << p.fullName << 'n'
<< "Person DOB: " << 'n'
<< p.dob << endl;
return os;
}*/
New folder/Person.h
#ifndef TEAMPERSON_H
#define TEAMPERSON_H
#include <string>
#include "Date.h"
#include<string>
using namespace std;
class TeamPerson {
public:
TeamPerson();
TeamPerson(string, Date);
friend ostream& operator<<(ostream& os, const TeamPerson
&p);
void SetFullName(string firstAndLastName);
string GetFullName() const;
virtual void print() const
{
cout <<"the patient's birthday is "<< dob << endl;
}
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)
{
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;
}*/
};
class patientType : public TeamPerson
{
private:
double id;
double age;
public:
patientType() {};
patientType(double a, double id) : age(a),id(id){};
void SetId(double id)
{
this->id = id;
return;
}
double GetID()const
{
return id;
}
void SetAge(double a)
{
age = a;
return;
}
double GetAge()const
{
return age;
}
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
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(
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx

More Related Content

Similar to INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx

So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfleolight2
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfanandshingavi23
 
Classes(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docxClasses(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docxbrownliecarmella
 
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfaamousnowov
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfsales87
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfjaipur2
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfankit11134
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfaoneonlinestore1
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdfanokhijew
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfankitmobileshop235
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfMALASADHNANI
 
This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdfaamousnowov
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportMatthew Zackschewski
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docxMichel Valentim
 
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
main-cpp file #include -iostream- #include -vector-   #include -Date-h.docxmain-cpp file #include -iostream- #include -vector-   #include -Date-h.docx
main-cpp file #include -iostream- #include -vector- #include -Date-h.docxEvandWYAlland
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docxajoy21
 

Similar to INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx (20)

So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdf
 
COW
COWCOW
COW
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdf
 
Classes(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docxClasses(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docx
 
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdf
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdf
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
 
This code has nine errors- but I don't know how to solve it- Please g.pdf
This code has nine errors- but I don't know how to solve it-  Please g.pdfThis code has nine errors- but I don't know how to solve it-  Please g.pdf
This code has nine errors- but I don't know how to solve it- Please g.pdf
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End Report
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docx
 
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
main-cpp file #include -iostream- #include -vector-   #include -Date-h.docxmain-cpp file #include -iostream- #include -vector-   #include -Date-h.docx
main-cpp file #include -iostream- #include -vector- #include -Date-h.docx
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 

More from normanibarber20063

Assist with first annotated bibliography.  Assist with f.docx
Assist with first annotated bibliography.  Assist with f.docxAssist with first annotated bibliography.  Assist with f.docx
Assist with first annotated bibliography.  Assist with f.docxnormanibarber20063
 
Assistance needed with SQL commandsI need assistance with the quer.docx
Assistance needed with SQL commandsI need assistance with the quer.docxAssistance needed with SQL commandsI need assistance with the quer.docx
Assistance needed with SQL commandsI need assistance with the quer.docxnormanibarber20063
 
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docx
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docxassingment Assignment Agenda Comparison Grid and Fact Sheet or .docx
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docxnormanibarber20063
 
Assimilate the lessons learned from the dream sequences in Defense o.docx
Assimilate the lessons learned from the dream sequences in Defense o.docxAssimilate the lessons learned from the dream sequences in Defense o.docx
Assimilate the lessons learned from the dream sequences in Defense o.docxnormanibarber20063
 
Assignmnt-500 words with 2 referencesRecognizing the fa.docx
Assignmnt-500 words with 2 referencesRecognizing the fa.docxAssignmnt-500 words with 2 referencesRecognizing the fa.docx
Assignmnt-500 words with 2 referencesRecognizing the fa.docxnormanibarber20063
 
Assignmnt-700 words with 3 referencesToday, there is a crisi.docx
Assignmnt-700 words with 3 referencesToday, there is a crisi.docxAssignmnt-700 words with 3 referencesToday, there is a crisi.docx
Assignmnt-700 words with 3 referencesToday, there is a crisi.docxnormanibarber20063
 
Assignment  For Paper #2, you will pick two poems on a similar th.docx
Assignment  For Paper #2, you will pick two poems on a similar th.docxAssignment  For Paper #2, you will pick two poems on a similar th.docx
Assignment  For Paper #2, you will pick two poems on a similar th.docxnormanibarber20063
 
Assignment Write an essay comparingcontrasting two thingspeople.docx
Assignment Write an essay comparingcontrasting two thingspeople.docxAssignment Write an essay comparingcontrasting two thingspeople.docx
Assignment Write an essay comparingcontrasting two thingspeople.docxnormanibarber20063
 
Assignment Travel Journal to Points of Interest from the Early Midd.docx
Assignment Travel Journal to Points of Interest from the Early Midd.docxAssignment Travel Journal to Points of Interest from the Early Midd.docx
Assignment Travel Journal to Points of Interest from the Early Midd.docxnormanibarber20063
 
Assignment What are the factors that influence the selection of .docx
Assignment What are the factors that influence the selection of .docxAssignment What are the factors that influence the selection of .docx
Assignment What are the factors that influence the selection of .docxnormanibarber20063
 
Assignment Write a research paper that contains the following.docx
Assignment Write a research paper that contains the following.docxAssignment Write a research paper that contains the following.docx
Assignment Write a research paper that contains the following.docxnormanibarber20063
 
Assignment Thinking about Managers and Leaders· Identifya man.docx
Assignment Thinking about Managers and Leaders· Identifya man.docxAssignment Thinking about Managers and Leaders· Identifya man.docx
Assignment Thinking about Managers and Leaders· Identifya man.docxnormanibarber20063
 
Assignment Talk to friends, family, potential beneficiaries abou.docx
Assignment Talk to friends, family, potential beneficiaries abou.docxAssignment Talk to friends, family, potential beneficiaries abou.docx
Assignment Talk to friends, family, potential beneficiaries abou.docxnormanibarber20063
 
Assignment The objective of assignment is to provide a Power .docx
Assignment The objective of assignment is to provide a Power .docxAssignment The objective of assignment is to provide a Power .docx
Assignment The objective of assignment is to provide a Power .docxnormanibarber20063
 
Assignment During the on-ground, residency portion of Skill.docx
Assignment During the on-ground, residency portion of Skill.docxAssignment During the on-ground, residency portion of Skill.docx
Assignment During the on-ground, residency portion of Skill.docxnormanibarber20063
 
Assignment PurposeThe first part of this assignment will assist.docx
Assignment PurposeThe first part of this assignment will assist.docxAssignment PurposeThe first part of this assignment will assist.docx
Assignment PurposeThe first part of this assignment will assist.docxnormanibarber20063
 
Assignment PowerPoint Based on what you have learned so .docx
Assignment PowerPoint Based on what you have learned so .docxAssignment PowerPoint Based on what you have learned so .docx
Assignment PowerPoint Based on what you have learned so .docxnormanibarber20063
 
Assignment In essay format, please answer the following quest.docx
Assignment In essay format, please answer the following quest.docxAssignment In essay format, please answer the following quest.docx
Assignment In essay format, please answer the following quest.docxnormanibarber20063
 
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docx
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docxAssignment NameUnit 2 Discussion BoardDeliverable Length150-.docx
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docxnormanibarber20063
 
Assignment In essay format, please answer the following questions.docx
Assignment In essay format, please answer the following questions.docxAssignment In essay format, please answer the following questions.docx
Assignment In essay format, please answer the following questions.docxnormanibarber20063
 

More from normanibarber20063 (20)

Assist with first annotated bibliography.  Assist with f.docx
Assist with first annotated bibliography.  Assist with f.docxAssist with first annotated bibliography.  Assist with f.docx
Assist with first annotated bibliography.  Assist with f.docx
 
Assistance needed with SQL commandsI need assistance with the quer.docx
Assistance needed with SQL commandsI need assistance with the quer.docxAssistance needed with SQL commandsI need assistance with the quer.docx
Assistance needed with SQL commandsI need assistance with the quer.docx
 
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docx
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docxassingment Assignment Agenda Comparison Grid and Fact Sheet or .docx
assingment Assignment Agenda Comparison Grid and Fact Sheet or .docx
 
Assimilate the lessons learned from the dream sequences in Defense o.docx
Assimilate the lessons learned from the dream sequences in Defense o.docxAssimilate the lessons learned from the dream sequences in Defense o.docx
Assimilate the lessons learned from the dream sequences in Defense o.docx
 
Assignmnt-500 words with 2 referencesRecognizing the fa.docx
Assignmnt-500 words with 2 referencesRecognizing the fa.docxAssignmnt-500 words with 2 referencesRecognizing the fa.docx
Assignmnt-500 words with 2 referencesRecognizing the fa.docx
 
Assignmnt-700 words with 3 referencesToday, there is a crisi.docx
Assignmnt-700 words with 3 referencesToday, there is a crisi.docxAssignmnt-700 words with 3 referencesToday, there is a crisi.docx
Assignmnt-700 words with 3 referencesToday, there is a crisi.docx
 
Assignment  For Paper #2, you will pick two poems on a similar th.docx
Assignment  For Paper #2, you will pick two poems on a similar th.docxAssignment  For Paper #2, you will pick two poems on a similar th.docx
Assignment  For Paper #2, you will pick two poems on a similar th.docx
 
Assignment Write an essay comparingcontrasting two thingspeople.docx
Assignment Write an essay comparingcontrasting two thingspeople.docxAssignment Write an essay comparingcontrasting two thingspeople.docx
Assignment Write an essay comparingcontrasting two thingspeople.docx
 
Assignment Travel Journal to Points of Interest from the Early Midd.docx
Assignment Travel Journal to Points of Interest from the Early Midd.docxAssignment Travel Journal to Points of Interest from the Early Midd.docx
Assignment Travel Journal to Points of Interest from the Early Midd.docx
 
Assignment What are the factors that influence the selection of .docx
Assignment What are the factors that influence the selection of .docxAssignment What are the factors that influence the selection of .docx
Assignment What are the factors that influence the selection of .docx
 
Assignment Write a research paper that contains the following.docx
Assignment Write a research paper that contains the following.docxAssignment Write a research paper that contains the following.docx
Assignment Write a research paper that contains the following.docx
 
Assignment Thinking about Managers and Leaders· Identifya man.docx
Assignment Thinking about Managers and Leaders· Identifya man.docxAssignment Thinking about Managers and Leaders· Identifya man.docx
Assignment Thinking about Managers and Leaders· Identifya man.docx
 
Assignment Talk to friends, family, potential beneficiaries abou.docx
Assignment Talk to friends, family, potential beneficiaries abou.docxAssignment Talk to friends, family, potential beneficiaries abou.docx
Assignment Talk to friends, family, potential beneficiaries abou.docx
 
Assignment The objective of assignment is to provide a Power .docx
Assignment The objective of assignment is to provide a Power .docxAssignment The objective of assignment is to provide a Power .docx
Assignment The objective of assignment is to provide a Power .docx
 
Assignment During the on-ground, residency portion of Skill.docx
Assignment During the on-ground, residency portion of Skill.docxAssignment During the on-ground, residency portion of Skill.docx
Assignment During the on-ground, residency portion of Skill.docx
 
Assignment PurposeThe first part of this assignment will assist.docx
Assignment PurposeThe first part of this assignment will assist.docxAssignment PurposeThe first part of this assignment will assist.docx
Assignment PurposeThe first part of this assignment will assist.docx
 
Assignment PowerPoint Based on what you have learned so .docx
Assignment PowerPoint Based on what you have learned so .docxAssignment PowerPoint Based on what you have learned so .docx
Assignment PowerPoint Based on what you have learned so .docx
 
Assignment In essay format, please answer the following quest.docx
Assignment In essay format, please answer the following quest.docxAssignment In essay format, please answer the following quest.docx
Assignment In essay format, please answer the following quest.docx
 
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docx
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docxAssignment NameUnit 2 Discussion BoardDeliverable Length150-.docx
Assignment NameUnit 2 Discussion BoardDeliverable Length150-.docx
 
Assignment In essay format, please answer the following questions.docx
Assignment In essay format, please answer the following questions.docxAssignment In essay format, please answer the following questions.docx
Assignment In essay format, please answer the following questions.docx
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

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"
  • 7. #include "Person.h" TeamPerson::TeamPerson() {} TeamPerson::TeamPerson(string f, Date d) :fullName(f), dob(d) {} void TeamPerson::SetFullName(string firstAndLastName) { fullName = firstAndLastName; return; } string TeamPerson::GetFullName() const { return fullName; }
  • 8. /*ostream& operator<<(ostream& os, const TeamPerson &p) { os << "The borrower full name is: " << p.fullName << 'n' << "Person DOB: " << 'n' << p.dob << endl; return os; }*/ New folder/Person.h #ifndef TEAMPERSON_H #define TEAMPERSON_H #include <string> #include "Date.h" #include<string> using namespace std;
  • 9. class TeamPerson { public: TeamPerson(); TeamPerson(string, Date); friend ostream& operator<<(ostream& os, const TeamPerson &p); void SetFullName(string firstAndLastName); string GetFullName() const; virtual void print() const { cout <<"the patient's birthday is "<< dob << endl; }
  • 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) {
  • 13. this->id = id; return; } double GetID()const { return id; } void SetAge(double a) { age = a; return; } double GetAge()const { return age; }
  • 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(