Question

In: Computer Science

C++ Define a base class called Person. The class should have two data members to hold...

C++

Define a base class called Person. The class should have two data members
to hold the first name and last name of a person, both of type string. The
Person class will have a default constructor to initialize both data members
to empty strings, a constructor to accept two string parameters and use them
to initialize the first and last name, and a copy constructor. Also include
appropriate accessor and mutator member functions. Overload the operators ==
and != such that two objects of class Person are considered equal if and only
if both first and last names are equal. Also overload operators >>, <<, and =.
Define a class called Doctor derived from the Person class. The class
should have a data member to hold the doctor's hourly rate (of type double), a
default constructor to initialize the rate to 0, and a constructor that takes
a double and a reference to an object of type Person and initializes the data
members to their appropriate values. Also include an accessor and mutator
member functions for the doctor's hourly rate. In Doctor class, redefine the
operator = such that it not only copies the first and last name, but also
copies the hourly rate.
Define another class called Patient derived from the Person class. This
class should have a data member to hold the patient's primary physician (of
class Doctor). Include a default constructor that would call the default
constructors of class Doctor and Person to initialize the object; also include
a constructor that accepts a reference to an object of class Doctor and Person
and initializes the Patient object's data members to their respective values.
Add accessor and mutator member functions to access or set the primary
physician.
Finally, define a class called Billing that would hold information about
medical bills. This class should have the following data members: an object of
type Doctor to hold the doctor to whom the money is paid, an object of type
Patient to hold the patient who pays the money, and a variable of type double
to hold the amount due. The Billing class will have a default constructor that
initializes amount due to 0.0 and calls the default constructors for Patient
and Doctor objects and a constructor that accepts references to Doctor and
Patient objects and the amount of hours (type int). The latter constructor
will calculate the amount due in the following fashion:

* if the doctor involved in the bill is the patient's primary physician,
then the amount due is hours multiplied by the doctor's hourly rate;

* if the doctor involved is not the patient's primary physician, then
the amount due is hours times doctor's hourly rate times 1.25.

Write a main function that would prompt the user to enter the patient's
name, their primary physician's name and rate, another doctor's name and rate,
and the amount of hours spent in the doctor's office. Then the program will
calculate and output the amount patient owes for doctor's services.

Note: two doctors are considered the same if and only if their names match
(i.e. you can assume no doctors with the same name and different rates exist).

SAMPLE RUN Interactive Session:

Enter:John Smith
 the patient's name: Enter:David Merrow 125.0
 primary physician's name and their rate: Enter:David Merrow 125.0
 a doctor's name and their hourly rate: Enter:2
 amount of hours: You owe: 250 dollars.

SAMPLE RUN Standart Input:

Max Hatfield
Gregory Beller 140.0
Sam Brubeck 100.0
1

SAMPLE RUN Standart Output:

Enter: the patient's name: Enter: primary physician's name and their rate: Enter: a doctor's name and their hourly rate: Enter: amount of hours: You owe: 125 dollars.

Solutions

Expert Solution

Solution:

Givendata:

Define a base class called Person. The class should have two data members
to hold the first name and last name of a person, both of type string. The
Person class will have a default constructor to initialize both data members
to empty strings, a constructor to accept two string parameters and use them
to initialize the first and last name, and a copy constructor. Also include
appropriate accessor and mutator member functions.

Answer:

#include <iostream>
#include <string>

using namespace std;

class Person {
   public:
       Person();
       Person(string f, string l);
       Person(const Person& p);
       string getFirst() const;
       string getLast() const;
       void setFirst(string f);
       void setLast(string l);
       bool operator ==(Person& p) const;
       bool operator !=(Person& p) const;
   private:
       string first;
       string last;
};

Person::Person() : first(""), last("") {}

Person::Person(string f, string l) : first(f), last(l) {}

Person::Person(const Person& p) {
   first = p.first;
   last = p.last;
}

string Person::getFirst() const {
   return first;
}

string Person::getLast() const {
   return last;
}

void Person::setFirst(string f) {
   first = f;
}

void Person::setLast(string l) {
   last = l;
}

bool Person::operator ==(Person& p) const {
   return this->getFirst() == p.getFirst() && this->getLast() == p.getLast();
}

bool Person::operator != (Person& p) const {
   return this->getFirst() != p.getFirst() || this->getLast() != p.getLast();
}

class Doctor : public Person {
   public:
       Doctor();
       Doctor(string f, string l,double r);
       double getRate() const;
       void setRate(double r);
       void operator = (const Doctor& d);
   private:
       double rate;
};

Doctor::Doctor() : Person(), rate(0) {}

Doctor::Doctor(string f, string l,double r) : Person(f,l), rate(r) {}

double Doctor::getRate() const {
   return rate;
}

void Doctor::setRate(double r) {
   rate = r;
}

void Doctor::operator = (const Doctor& d) {
       setFirst(d.getFirst());
       setLast(d.getLast());
       rate = d.rate;
}

class Patient : public Person {
   public:
       Patient();
       Patient(string f, string l, Doctor* d);
       Doctor* getDoctor() const;
       void setDoctor(Doctor* d);
   private:
       Doctor* doctor;
};

Patient::Patient() : Person(), doctor(new Doctor) {}

Patient::Patient(string f, string l, Doctor* d) : Person(f, l), doctor(d) {}

Doctor* Patient::getDoctor() const {
   return doctor;
}

void Patient::setDoctor(Doctor* d) {
   doctor = d;
}

class Billing {
   public:
       Billing();
       Billing(Doctor* d, Patient* p, int h);
       double getBill() const;
   private:
       Doctor* doctor;
       Patient* patient;
       double amount;
};

Billing::Billing() : doctor(new Doctor), patient(new Patient), amount(0) {}

Billing::Billing(Doctor* d, Patient* p, int h) : doctor(d), patient(p) {
   if(doctor == p->getDoctor()) {
       amount = h * double(doctor->getRate());
   } else {
       amount = h * double(doctor->getRate()) * 1.25;
   }
}

double Billing::getBill() const {
   return amount;
}

int main()
{
   double r, total;
   int h;
   string pf,pl,df,dl;
  
   cout << "Enter:";
   cin >> pf >> pl;
  
   cout << " the patient's name: Enter:";
   cin >> df >> dl >> r;
   Doctor primary(df,dl,r);
   Patient patient(pf,pl,&primary);
   cout << " primary physician's name and their rate: Enter:";  
   cin >> df >> dl >> r;
   Doctor doctor(df,dl,r);
   cout << " a doctor's name and their hourly rate: Enter:";
   cin >> h;
  
   Billing billPrimary(&primary, &patient, h);
   if(doctor == primary){
       cout << billPrimary.getBill() << endl;
      
       total = billPrimary.getBill() * 2;      
       cout << total << endl;
   } else {
       Billing billDoctor(&doctor, &patient, h);
       total = billPrimary.getBill() + billDoctor.getBill();
   }
  
   cout << " amount of hours: You owe: " << total << " dollars.\n";
   return 0;
}

PLEASE GIVEME THUMBUP...........


Related Solutions

In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
2. Report Heading Design a class called Heading that has data members to hold the company...
2. Report Heading Design a class called Heading that has data members to hold the company name and the report name. A two-parameter default constructor should allow these to be specified at the time a new Heading object is created. If the user creates a Heading object without passing any arguments, “ABC Industries” should be used as a default value for the company name and “Report” should be used as a default for the report name. The class should have...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y),...
In object C Define a class called XYPoint that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of your new point and retrieve their values. Write an Objective-C program to implement your new class and test it (main section of the file). Your test program needs to create two instances of your class. Make sure your program test prints out the values that you have...
This is in C# on visual Basic Write a base class that has two property members:...
This is in C# on visual Basic Write a base class that has two property members: name and contact and one method member: CalculateFinalGrade(). must be an Abstract class method must be by its child class. (1 point) For example, Student {                 Property: StudentName                 Property: Contact                 Method: CalculateFinalGrade() } Write two child classes and , both of which inherit and implement any abstract member. needs a property for Quiz score and implements CalculateFinalGrade() to calculate final the...
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
Define the exception class called TornadoException. The class should have two constructors including one default constructor....
Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return "Tornado: Take cover immediately!" The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return "Tornado: m miles away; and approaching!" Write a Java program to test the class TornadoException.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT