Question

In: Computer Science

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 != 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).

Solutions

Expert Solution

Note I developed Two classes.have to develop the third class. I will do that.Thank u.

__________________

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;

class Person {
private :
string firstname;
string lastname;

public :
   Person() {
this->firstname = "";
this->lastname = "";
}
Person(string firstname, string lastname) {
this->firstname = firstname;
this->lastname = lastname;
}

string getFirstname() {
return firstname;
}

void setFirstname(string firstname) {
this->firstname = firstname;
}

string getLastname() {
return lastname;
}

void setLastname(string lastname) {
this->lastname = lastname;
}

Person(const Person& src)
{
this->firstname=src.firstname;
this->lastname=src.lastname;
}

friend std::ostream & operator <<(std::ostream &dout, const Person& p)
{
    cout<<"FirstName :"<<p.firstname<<" LastName :"<<p.lastname<<endl;
    return dout;
   }
     
   friend istream & operator >> (std::istream & in, Person & right)
{
cout<<"Enter FirstName :";
    in>>right.firstname;
    cout<<"Enter LastName :";
    in>>right.lastname;
    return in;   
}

bool operator== (Person & r)
{
if(firstname.compare(r.firstname)==0 && lastname.compare(r.lastname)==0)
return true;
else
return false;
}
bool operator!= (Person& r)
{
if(firstname.compare(r.firstname)!=0 || lastname.compare(r.lastname)!=0)
return true;
else
return false;
}

Person & operator=(const Person &c)
{
this->firstname=c.firstname;
this->lastname=c.lastname;
return *this;
}

  
};
class Doctor:public Person
{
private :
    double hourly_rate;
public :  
Doctor()
{
    hourly_rate=0;
   }
   Doctor(string firstname, string lastname,double rate):Person(firstname,lastname)
{
    hourly_rate=rate;
   }
   double getHourly_rate()
{
   return hourly_rate;
   }
   void setHourly_rate(double rate)
   {
       this->hourly_rate=rate;
   }
  
   Doctor & operator=(const Doctor &c)
{
setFirstname(c.firstname);
setLastname(c.lastname);
hourly_rate=c.hourly_rate;
return *this;
}
  
     
};

int main()
{



return 0;
}

________________________


Related Solutions

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 !=...
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...
C#. Build a class that will be called “MyDate”. The class should have 3 properties: month,...
C#. Build a class that will be called “MyDate”. The class should have 3 properties: month, day and year. Make month, day and year integers. Write the get and set functions, a display function, and constructors, probably two constructors. (No Database access here.)
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
Refactor the following classes so they are both derived from a base class called Person. Write...
Refactor the following classes so they are both derived from a base class called Person. Write the code for the new base class as well. Try to avoid repeating code as much as possible. Write the classes so that any common methods can be invoked through a pointer or reference to the base class. #include <string> #include <cmath> using namespace std; class Student { private: string name;    int age;    int studyYear; public:    Student(string,int,int); void study();    void...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
Define a class called Goals that has the following requirements in c++: a function called set...
Define a class called Goals that has the following requirements in c++: a function called set that takes 3 int parameters that are goals for "fame", "happiness" and "money". The function returns true and saves the values if they add up to exactly 60, and returns false otherwise (you may assume the parameters are not negative) a functions satisfies that takes 3 int parameters and returns true if each parameter is at least as large as the saved goal, false...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an int field called strength and a char field called type. You may make them either private or protected. The Tool class should also contain the function void setStrength(int), which sets the strength for the Tool. Create 3 more classes called Rock, Paper, and Scissors, which inherit from Tool. Each of these classes will need a default constructor that sets the strength to 1 and...
Write a program in which define a templated class mySort with private data members as a...
Write a program in which define a templated class mySort with private data members as a counter and an array (and anything else if required). Public member functions should include constructor(s), sortAlgorithm() and mySwap() functions (add more functions if you need). Main sorting logic resides in sortAlgorithm() and mySwap() function should be called inside it. Test your program inside main with integer, float and character datatypes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT