Question

Hello, Please provide the source code in C++. Must be in 3 different files, please distinguish...

Hello,

Please provide the source code in C++.

Must be in 3 different files, please distinguish by comments.: class definitions (session.h), main program (session_main.cpp), and function definitions (session_defs.cpp).

Define a class called Date with month, day and year as its data. Member functions must include a constructor, destructor, overloading function for < and ==, and for insertion (>>) and extraction (<<) for reading and displaying data.

Also, define a class called Appointment for a consultant (or lawyer) to keep track of her appointments. Include a description (string) and a Date for the appointment date. Include same member functions as for Date.

Let's say now we realize that we need a class called Session for meeting clients. Session, like Appointment, needs a Date and a description, but it also has duration in hours and an hourly charge that can be set for different client types and sessions. Since Session has things in common with Appointment (date and description), instead of developing a new class altogether, we decide to derive it from Appointment and add its additional data and any other member functions it needs, to save on code.

Besides the data it inherits from Appointment, Session would also have client_name, hourly_charge (dollar amount) and hours (number of hours spent in session). Make any required modifications to Appointment class (Hint: to make the inherited data accessible to the derived class, but private from others).

Include for the Session class, a constructor, destructor (even if it has to have an empty body), set() for setting data, read() for reading data from keyboard, print() for displaying the data and get_charge() for computing the charges due for the session (hours * hourly_rate).

Provide a menu in main so the user can:

1) create and add new Sessions to an array of Session pointers at run time and enter data for it,

2) display all added Sessions

3) Search for a client name in the array of Session pointers and display the charge

4) display the total charge for all clients and the average hours spent

5) quit the menu.

Must be in 3 different files, please distinguish by comments.: class definitions (session.h), main program (session_main.cpp), and function definitions (session_defs.cpp).

A sample interaction between the user and the program:

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 1

Enter description: landlord Jones vs tenant Dominguez for non payment of rent

Enter appointment date: 4/1/2019

Enter client name: Mark Jones

Enter hourly charge: $300.00

Enter hours: 2.5

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 1

Enter description: Brown against neighbor Smith

Enter client name: Mike Brown

Enter appointment date: 4/5/2019

Enter hourly charge: $300.00

Enter hours: 3

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 1

Enter description: Bryant vs. Simpson

Enter appointment date: 4/10/2019

Enter client name: Henry Simpson

Enter hourly charge: $300.00

Enter hours: 3.5

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 2

List of scheduled sessions:

landlord Jones vs tenant Dominguez for non payment of rent

Date: 4/1/2019

Client name: Mark Jones

Hourly charge: $300.00

Enter hours: 2.5

Charge: $750.00

Brown against neighbor Smith

Client name: Mike Brown

Date: 4/5/2019

Hourly charge: $300.00

Hours: 3

Charge: $900.00

Bryant vs. Simpson

Date: 4/10/2019

Client name: Henry Simpson

Hourly charge: $300.00

Hours: 3.5

Charge: $1050.00

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 3

Enter client name: Mike Brown

Brown against neighbor Smith

Date: 4/5/2019

Hourly charge: $300.00

Hours: 3

Charge: $900.00

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 4

Total charges: $2700.00

Average hours: 3

Select one of the following actions:

1) Add new Session

2) Display all Sessions

3) Search for a client

4) Display total charges for all clients and the average hours spent

5) Quit the menu

Enter your selection: 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following are the contents of the three program files. File name is written as a comment before the start of each file. The program accepts description and names and strings which can have spaces. It accepts Date in the format [day]/[month]/[year]. The hourly charge is accepted as a decimal number which is interpreted as the cost in dollars.

/*session.h*/

#include <iostream>
using namespace std;

class Date
{
private:
   int month;
   int day;
   int year;

public:
   Date(){}
   Date(int d, int m, int y);
   ~Date(){}
   friend bool operator < (Date d1, Date d2);
   friend bool operator == (Date d1, Date d2);
   friend ostream& operator << (ostream& out, const Date& d);
   friend istream& operator >> (istream& in, Date& d);
};

class Appointment
{
protected:
   string description;
   Date date;

public:
   Appointment(){}
   Appointment(string desc, Date d);
   ~Appointment(){}
   // essentially compares the dates of the two appointments
   friend bool operator < (Appointment a1, Appointment a2);
   friend bool operator == (Appointment a1, Appointment a2);
   friend ostream& operator << (ostream& out, const Appointment& a);
   friend istream& operator >> (istream& in, Appointment& a);
};

class Session : public Appointment
{
private:
   string client_name;
   float hourly_charge;
   float hours;

public:
   Session(){read();}
   Session(string cname, float hcharge, float h, string desc, Date d) :
       Appointment(desc, d),client_name(cname),hourly_charge(hcharge),hours(h){}
   ~Session(){}
   void set(string cname, float hcharge, float h, string desc, Date d);
   string get_name();
   float get_hours();
   void read();
   void print();
   float get_charge();

};

/*session_defs.cpp*/

#include "session.h"
#include <iostream>
using namespace std;
Date::Date(int d, int m, int y)
{
   // validation of the date can be added here
   day = d;
   month = m;
   year = y;
}

bool operator < (Date d1, Date d2)
{
   if(d1.year != d2.year)
   {
       return d1.year < d2.year;
   }
   if(d1.month != d2.month)
   {
       return d1.month < d2.month;
   }
   return d1.day!=d2.day;
}
bool operator == (Date d1, Date d2)
{
   if(d1.year==d2.year && d1.month==d2.month && d1.day==d2.day)
       return true;
   else
       return false;
}
ostream& operator << (ostream& out, const Date& d)
{
   out<<d.day<<"/"<<d.month<<"/"<<d.year;
   return out;
}
istream& operator >> (istream& in, Date& d)
{
   string s;
   in>>s;
   d.day = 0;
   int i = 0;
   while(s[i]!='/')
   {
       d.day = d.day*10+(s[i]-'0');
       i++;
   }
   i++;
   d.month = 0;
   while(s[i]!='/')
   {
       d.month = d.month*10+(s[i]-'0');
       i++;
   }
   i++;
   d.year = 0;
   while(i<s.size())
   {
       d.year = d.year*10 + (s[i]-'0');
       i++;
   }
   return in;
}

Appointment::Appointment(string desc, Date d)
{
   description = desc;
   date = d;
}

bool operator < (Appointment a1, Appointment a2)
{
   return a1.date < a2.date;
}
bool operator == (Appointment a1, Appointment a2)
{
   return a1.date == a2.date;
}
ostream& operator << (ostream& out, const Appointment& a)
{
   out<<"Date of appointment: "<<a.date<<endl;
   out<<a.description;
   return out;
}
istream& operator >> (istream& in, Appointment& a)
{
   cout<<"Description: ";
   cin.ignore();
   getline(in,a.description);
   in>>a.date;
   return in;
}


void Session::set(string cname, float hcharge, float h, string desc, Date d)
{
   client_name = cname;
   hourly_charge = hcharge;
   hours = h;
   description = desc;
   date = d;
}

void Session::read()
{
   cout<<"Enter description: ";
   cin.ignore();
   getline(cin,description);
   cout<<"Enter appointment date: ";
   cin>>date;
   cout<<"Enter client name: ";
   cin.ignore();
   getline(cin,client_name);
   cout<<"Enter hourly charge: ";
   cin>>hourly_charge;
   cout<<"Enter hours: ";
   cin>>hours;
}

void Session::print()
{
   cout<<description<<endl;
   cout<<"Date: ";
   cout<<date<<endl;
   cout<<"Client name: ";
   cout<<client_name<<endl;
   cout<<"Hourly charge: $";
   cout<<hourly_charge<<endl;
   cout<<"Hours: ";
   cout<<hours<<endl;
   cout<<"Charge: $";
   cout<<get_charge()<<endl;

}

string Session::get_name()
{
   return client_name;
}

float Session::get_hours()
{
   return hours;
}
float Session::get_charge()
{
   return hours * hourly_charge;
}

/*session_main.cpp*/

#include "session.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
   int choice;
   string name;
   vector<Session*> arr;
   Session* s;
   float total_charge;
   float total_hours;
   while(true)
   {
       cout<<"Select one of the following actions: \n";
       cout<<"1. Add new Session\n";
       cout<<"2. Display all Sessions\n";
       cout<<"3. Search for a client\n";
       cout<<"4. Display total charges for all clients and the average hours spent\n";
       cout<<"5. Quit the menu\n";
      
       cout<<"Enter your selection: ";
       cin>>choice;

       switch(choice)
       {
       case 1:
           arr.push_back(new Session());
           break;
       case 2:
           cout<<"List of scheduled sessions: \n";
           for(int i = 0; i<arr.size(); i++)
           {
               arr[i]->print();
           }
           break;
       case 3:
           cout<<"Enter name: ";
           cin.ignore();
           getline(cin,name);
           for(int i = 0; i<arr.size(); i++)
           {
               if(arr[i]->get_name()==name)
               {
                   arr[i]->print();
               }
           }
           break;
       case 4:
           total_charge = 0;
           total_hours = 0;
           for(int i = 0; i<arr.size(); i++)
           {
               total_charge += arr[i]->get_charge();
               total_hours += arr[i]->get_hours();
           }

           cout<<"Total charges: $"<<total_charge<<endl;
           cout<<"Average hours: "<<total_hours/arr.size()<<endl;
           break;
       case 5:
           return 0;
       }
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Hello, Please provide the source code in C++. Must be in 3 different files, please distinguish...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • Java Data Structures

    Programming Instructions:Using      Java Object Oriented Principles, write a program which produces the      code as indicated in the following specifications: Your       program must be a console application that provides a user this exact       menu:Please select one of the following:1: Add Client to Bank2: Display Clients in the Bank3: Set Bank Name4: Search for a Client5: Exit Enter your Selection: <keyboard input here> The       menu must be displayed repeatedly until 5...

  • Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory...

    Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to Co Sci 839 or google: "binary...

  • Please help, provide source code in c++(photos attached) develop a class called Student with the following protected...

    Please help, provide source code in c++(photos attached) develop a class called Student with the following protected data: name (string), id (string), units (int), gpa (double). Public functions include: default constructor, copy constructor, overloaded = operator, destructor, read() to read data into it, print() to print its data, get_name() which returns name and get_gpa() which returns the gpa. Derive a class called StuWorker (for student worker) from Student with the following added data: hours (int for hours assigned per week),...

  • C++ Question Question 3 [43] The Question: You are required to write a program for an...

    C++ Question Question 3 [43] The Question: You are required to write a program for an Online Tutoring Centre to determine the weekly rate depending on the number of sessions the students attend and then to calculate total revenue for the center. The Online Tutoring Centre charges varying weekly rates depending on the on grade of the student and number of sessions per week the student attends as shown in Table 1 below. Grade 8 9 Session 1 75 80...

  • Code a complete Java program for the following payroll application: First, hard code the following data...

    Code a complete Java program for the following payroll application: First, hard code the following data for the object ‘Employee’ into 4 separate arrays: SSN: 478936762, 120981098, 344219081, 390846789, 345618902, 344090917 First name      : Robert, Thomas, Tim, Lee, Young, Ropal Last name       : Donal, Cook, Safrin, Matlo, Wang, Kishal Hourly rate     : 12.75, 29.12, 34.25, 9.45,   20.95, 45.10 Hours worked: 45,        40,        39,       20,      44,        10 These 4 arrays must be declared inside the class and not within any method....

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • C++ : Please include complete source code in answer This program will have names and addresses...

    C++ : Please include complete source code in answer This program will have names and addresses saved in a linked list. In addition, a birthday and anniversary date will be saved with each record. When the program is run, it will search for a birthday or an anniversary using the current date to compare with the saved date. It will then generate the appropriate card message. Because this will be an interactive system, your program should begin by displaying a...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES...

    Programming in C/C++ Submit your source code files (all .h and .cpp files) NO GLOBAL VARIABLES Program: Use operator overloaded functions for a birthday club – Based on Chapter 11 lecture (25 pts) Make a class called Birthday that will have a date of month, day, and year and the name. Need to have overloaded operators to compare values along with regular functions like: Overload operator == that takes a Birthdate, compares against the current date values, and returns a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT