C++ Program for Xcode: The Class Doctor represents a human health-care provider.
ID: 3579390 • Letter: C
Question
C++ Program for Xcode:
The Class Doctor represents a human health-care provider. Consider the following diagrams below This instance was created by saying: A Cardiologist named Bill Doctor d( "Bill", "Cardiology"; This instance was created by saying: An Internist named Sam Doctor samC "Sam", "Internist"; Each Doctor is defined by its name and its specialty. For the constructors shown above, here is the class definition (.h) Class Diagram Class Definition (.h file) Doctor class Doctor [ public: Doctor std::string name, std:string specialty ) Doctor (std: :string name, std: :string specialty) std::string getName) const; std::string getSpecialty0 const; virtual void practice(); std: :string getName ) const std: :string getSpecialty) const; std::string myName, mySpecialty; virtual void practice ) private: std::string myName, mySpecialty;Explanation / Answer
doctor.h
#include<bits/stdc++.h>
using namespace std;
class Doctor
{
private:
string myName,mySpecialty;
public:
Doctor();
~Doctor()
{
}
Doctor(string name,string speciality);
string getName() const;
string getSpeciality() const;
virtual void practice();
};
===========================================================
doctor.cpp
#include<bits/stdc++.h>
#include "doctor.h"
using namespace std;
Doctor::Doctor()
{
}
Doctor::Doctor(string name,string specialty)
{
myName=name;
mySpecialty=specialty;
}
string Doctor::getName() const
{
return myName;
}
string Doctor::getSpeciality() const
{
return mySpecialty;
}
void Doctor::practice()
{
cout<<getName()<<"is practicing on a patient!";
cout<<endl;
}
=====================================================================
Surgeon.h
#include<bits/stdc++.h>
using namespace std;
#include "doctor.cpp"
class Surgeon :public Doctor
{
public:
Surgeon();
~Surgeon()
{
}
Surgeon(string s);
void practice();
};
=====================================================================
Surgeon.cpp
#include<bits/stdc++.h>
#include "Surgeon.h"
using namespace std;
Surgeon::Surgeon():Doctor("Tom","surgery")
{
}
Surgeon::Surgeon(string s):Doctor(s,"surgery")
{
}
void Surgeon::practice()
{
cout<<getName()<<" is practicing on a patient!";
cout<<endl;
}
===================================================================
main.cpp
#include<bits/stdc++.h>
#include "Surgeon.cpp"
using namespace std;
int main(int argc, char const *argv[])
{
Surgeon s;
//s.practice();
Surgeon* mary=new Surgeon("Mary");
mary->practice();
return 0;
}
=======================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ g++ main.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Mary is practicing on a patient!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.