Question

Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c) ReadSchedule to read schedule from user (2b) Your program must check that only appropriate numbers are entered for Time in ReadSchedule (default value for hour/minute and second is 0) (2c) Your program should indicate error when end_time < start_time. (3) You should store the schedules in a vector (4) Create the struct Time and class Schedule in a file named schedule.h which you must include in main.cpp (5) Your program should produce EXACTLY the same output as the enclosed program (run sample.exe to see the output). Feel free to use the skeletal program I have provided in the enclosed zip file.

Below are the extracted files for main.cpp and schedule.h that i need to work them.

main.cpp

void DisplaySchedule(vector<Schedule> schs)
{
   cout<<"-----------------------------CURRENT SCHEDULE----------------------------------------------------\n\n";
   for(int i=0;i<schs.size();i++)
   {
       cout<<"----------------------------------------------------------------------------------\n";
       cout<<(i+1)<<".";
       schs[i].Display();      
   }  
   cout<<endl;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
//FILL IN THE CODES
   return 0;
}

schedule.h

#pragma once
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

struct Time
{
   int Hour;
   int Minute;
   int Second;
  
   Time():Time(0,0,0){   } //default constructor - "calls" constructor with parameters
  
   Time(int hr, int min, int sec) //constructor with parameters
   {
       Hour = hr;
       Minute = min;
       Second = sec;
   };
  
   //read time from user
   void ReadTime()
   {
      
   }
   //show time
   void Show()
   {
       cout<<Hour<<":"<<Minute<<":"<<Second;
   }
};

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

Schedule.cpp

#include<iostream>
#include<string>

using namespace std;

struct time {
   int hour;
   int minute;
   int second;
};

struct time *duration(struct time *end, struct time*start) { // returns duration between start and end in a time form
   struct time *t = new struct time();
   t->second = end->second-start->second;
   int minute_borrow = 0;
   if(t->second < 0) {
       t->second+=60;
       minute_borrow=1;
   }
   int hour_borrow=0;
   t->minute = end->minute-minute_borrow-start->minute;
   if(t->minute<0) {
       t->minute +=60;
       hour_borrow=1;
   }
   t->hour=end->hour-hour_borrow-start->hour;
}

string tostring(struct time * t) {
   return to_string(t->hour)+ ":"+to_string(t->minute)+ ":"+to_string(t->second);
}

class Schedule {
   private:
   int day_of_week; // 0=sunday & 6=saturday
   struct time* start_time;
   struct time* end_time;
   string activity;
   public:
   Schedule(int dweek,struct time* start,struct time* end,string act) {
       day_of_week=dweek;
       start_time=start;
       end_time=end;
       activity=act;
   }
   void Display() {
       string weekdayname;
       switch(day_of_week) {
           case 0:
           weekdayname="Sunday";
           break;
           case 1:
           weekdayname="Monday";
           break;
           case 2:
           weekdayname="Tuesday";
           break;
           case 3:
           weekdayname="Wednesday";
           break;
           case 4:
           weekdayname="Thursday";
           break;
           case 5:
           weekdayname="Friday";
           break;
           case 6:
           weekdayname="Saturday";
           break;
       }
       cout<<weekdayname<<" "<<tostring(start_time)<<" "<<tostring(end_time)<<" "<<activity<<endl;
   }
   struct time *Length() {
       return duration(end_time, start_time);
   }
   static Schedule *ReadSchedule() {
       int dweek; // 0=sunday & 6=saturday
       struct time* start= new struct time();
       struct time* end= new struct time();
       string act;
       cout<<"Enter a schedule entry:"<<endl;
       // prompt for "day of week"
       cout<<"Enter day of week[0=sunday, 6=saturday]: ";
       cin>>dweek;
      
       // prompt for start time
       cout<<"Enter start time:"<<endl;
       cout<<"hour: ";
       cin>>start->hour;
       cout<<"minute: ";
       cin>>start->minute;
       cout<<"second: ";
       cin>>start->second;
      
       // prompt for end time
       cout<<"Enter end time:"<<endl;
       cout<<"hour: ";
       cin>>end->hour;
       cout<<"minute: ";
       cin>>end->minute;
       cout<<"second: ";
       cin>>end->second;
      
       // prompt for activity
       cout<<"Enter activity: ";
       cin>>act;
       return new Schedule(dweek, start, end, act);
   }
};
int main() {
   Schedule *s = Schedule::ReadSchedule(); // reading a schedule from console
   s->Display(); // displying the schedule
   cout<<"Duration is "<<tostring(s->Length());// displaing the schedule length
   return 0;
}
  

output

Enter a schedule entry:
Enter day of week[0=sunday, 6=saturday]: 1
Enter start time:
hour: 10
minute: 30
second: 35
Enter end time:
hour: 11
minute: 5
second: 25
Enter activity: test
Monday 10:30:35 11:5:25 test
Duration is 0:34:50

Explanation

How to calculate duration:

IF we want duration in second instead of time format the formula will be

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...
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 in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • 2. In the following program an employee of a company is represented by an object of...

    2. In the following program an employee of a company is represented by an object of type employee consisting of a name, employee id, employee salary and the workday starting time. The starting time is a class time 24 object. Implement the class employee. Declaration of Employee and Time Classes /* File : employeetime.h Hlustrates composition of classes */ #ifndef EMPLOYEETIME.H #define EMPLOYEETIME.H #include <iostream> #include <string> using namespace std; class time 24 { private : int hour; int minute...

  • C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...

    C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...

  • Write a C++ program that simulates coin tossing. For each toss of the coin the program...

    Write a C++ program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. The program should toss a coin 100 times. Count the number of times each side of the coin appears and print the results at the end of the 100 tosses.   The program should have the following functions as a minimum: void toss() - called from main() and will randomly toss the coin and set a variable equal to the...

  • Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include &lt...

    Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include <iostream> using namespace std; #include "money.h" /**************************************************************** * Function: main * Purpose: Test the money class ****************************************************************/ int main() {    int dollars;    int cents;    cout << "Dollar amount: ";    cin >> dollars;    cout << "Cents amount: ";    cin >> cents;    Money m1;    Money m2(dollars);    Money m3(dollars, cents);    cout << "Default constructor: ";    m1.display();    cout << endl;    cout << "Non-default constructor 1: ";    m2.display();    cout << endl;   ...

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

  • please help! i dont know why there are bugs and how to fix this.. (in C++)...

    please help! i dont know why there are bugs and how to fix this.. (in C++) please help! the problem: my code: Create a class called clockType for a clock type with fields hr, min, and sec. Your code should support the following set of statements 1 clockType c1; 2 clockType c2 (10,59); 3 clockType c3(5,10,20); 4 int sec = 10; 5 cout << c1; cout << c1+c2; In c2, you only set hr and min fields. Note that the...

  • HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the...

    HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

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