Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Work Schedule Project Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at

Work Schedule Project

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 (using military time). 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

(3) Your program should read list of schedules from a csv file named schedules.csv (a) schedules.csv must contain a schedule per line (day,start-time,end-time,activity) for example Mon,10:30:0,12:15:30,Swimming lesson (the enclosed CSVReader contains a method getCellAsIntArray(':') that returns an array like [hour,min,sec] which you can use to get the time part of the csv) (b) schedules.csv must contain at least two schedules per day of the week (Mon - Sun) (c) YOU MAY NOT DIRECTLY USE MY SCHEDULES.CSV FOR SUBMISSION - YOU MUST PROVIDE YOUR OWN - USING MINE WILL RESULT IN DEDUCTION OF 5 POINTS

(4) Create the struct Time and class Schedule in a file named schedule.h which you must include in main.cpp

(5) Your program must be able to search for schedule given (a) day of the week (not case sensitive, ie entering MON or Mon or mon or mOn should mean the same thing) (b) activity type (not case sensitive) (c) I have included a file called stringutils.h which contains functions for comparing strings which may be of use to you - feel free to use it

(6) Your program should produce EXACTLY the same output as the enclosed program (run sample.exe to see the output). Feel free to customize my Scheduler program provided for version 2 of this project

(7) The project name is SCHEDULER3

(8) Use AssignmentZipper or winrar to package your assignment into one .zip folder

Below is the csvreader2.h file that must be used

and a picture of a sample of the run output.

csvreader2.h file

#ifndef CSVREADER_H #define CSVREADER_H

using namespace std; #include #include //for reading from file #include //used to store lines from file and tokenize a line read #include

// trim from left. This is not part of the class, just a utility function inline std::string& ltrim(std::string& s, const char* t = " \t \f\v") { s.erase(0, s.find_first_not_of(t)); return s; }

// trim from right. This is not part of the class, just a utility function inline std::string& rtrim(std::string& s, const char* t = " \t \f\v") { s.erase(s.find_last_not_of(t) + 1); return s; }

// trim from left & right. This is not part of the class, just a utility function inline std::string& trim(std::string& s, const char* t = " \t \f\v") { return ltrim(rtrim(s, t), t); }

////Split a given string using given delimiter. This is not part of the class, just a utility function vector split( string s, const char del) { vector tokens; string token; istringstream tokenStream(s); while (std::getline(tokenStream, token, del)) { if(token != "") tokens.push_back(trim(token)); } return tokens; };

class CSVReader { public: CSVReader(string filepath,char del=','); vector getRow(int row) const;//returns a row of the CSV string getCellAsString(int row, int col) const;//returns element at row, col char getCellAsChar(int row, int col) const;//returns element at row, col as char int getCellAsInt(int row, int col) const;//returns element at row, col as int vector getCellAsIntVector(int row, int col,char del) const;//returns element at row, col as vector double getCellAsDouble(int row, int col) const;//returns element at row, col as double int getRowsCount() const{ return Rows.size();}; //returns how many rows were read in int getColsCount() const{ return ColsLength;};//returns how many cols in the csv void printRow(int row) const;//prints the content of a given row private: vectorRows;//contains the rows of data in the csv char del;//delimiter used to separate csv int ColsLength;/umber of columns };

//implementation of the functions CSVReader::CSVReader(string filepath,char del) { ColsLength=0; this->del=del; //declare the file ifstream csvfile; csvfile.open(filepath); if(csvfile.good()) { string line; while ( getline(csvfile, line) ){ if (line.find(del) != std::string::npos) //make sure the delimiter is in the line we are reading { Rows.push_back(trim(line)); //set the number of columns if necessary if(ColsLength==0) ColsLength = (split(line,del)).size(); } }//end of while } else cout I had trouble opening the file["

///get an entire row as vector vector CSVReader::getRow(int row) const { if(row>=0 && row v; return v; };

///get content in location (row, col) string CSVReader::getCellAsString(int row, int col) const { vector v = getRow(row); return v[col]; };

///get content in location (row, col) as char char CSVReader::getCellAsChar(int row, int col) const { vector v = getRow(row); return v[col][0]; //only interested in the first character };

///get content in location (row, col) as int int CSVReader::getCellAsInt(int row, int col) const { vector v = getRow(row); return stoi(v[col]); }; ///get content in location (row, col) as double double CSVReader::getCellAsDouble(int row, int col) const { vector v = getRow(row); return stod(v[col]); };

///get content in location (row, col) as vector vector CSVReader::getCellAsIntVector(int row, int col,char del) const { vector v = getRow(row); //split the col using del vector cols =split(v[col],del); vector res; for(int i=0;i vrow= getRow(row); cout

#endif

image text in transcribed

CSVReader2.h stringutil.h main.cpp Time and Schedule program , 2/9/19 #pragma once #include #include #include ionanP> >Hour cout23) wrong hour. I am setting to def Hour 85 36 37 38 39 cout>Minute; cout59) couttError wrong 8 minute. I an setting to de 41 Minute - cout>Second; coutcendl 43 CSVReader2.h stringutil.h main.cpp Time and Schedule program , 2/9/19 #pragma once #include #include #include ionanP> >Hour cout23) wrong hour. I am setting to def Hour 85 36 37 38 39 cout>Minute; cout59) couttError wrong 8 minute. I an setting to de 41 Minute - cout>Second; coutcendl 43

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions