Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**PLEASE READ THIS: NO BUILT IN FUNCTIONS !!!! **********CAN ONLY USE < IOSTREAM>!!!!******* You may not use any header files other than iostream or any

**PLEASE READ THIS: NO BUILT IN FUNCTIONS !!!! **********CAN ONLY USE< IOSTREAM>!!!!******* You may not use any header files other than iostream or any built-in functions.

**MUST BE IN C++ LANGUAGE.**

For this assignment you are to use the Time class implemented in the last assignment to implement a program that will sort a collection of up to 100 Time values, outputting the results in ascending sorted order.

The program should begin by asking the user how many values are to be processed. If the user inputs an incorrect value (not in the range of 0 to 100) the user should be reprompted to enter a new value until a valid value has been entered.

Once a valid value has been entered, the program should then prompt the user, one prompt at a time, to input the specified number of values.

The program should then output the values in the specified order.

The main() function of your implementation should consist of, except as specified, the following code segment:

int main() { //here you should define the data needed to complete this //function

ReadData(tList, tCount); SortData(tlist, tCount); WriteData(tlist, tCount); Return 0; }

The ReadData() function retrieves from the user a list of time values that are passed back in the array specified by the first parameter. The second parameter is used to pass back to the calling function, in this case main(), the number of time values contained in the array specified by the first parameter.

The SortData() function sorts time values contained in the array passed in by the first parameter. On return, this parameter should contain the sorted time values. The second parameter is used to specify to the SortData() function the number of values contained in the first parameter.

The WriteData() function outputs, one per line, the elements in the array specified by the first parameter. The second parameter specifies the number of elements in the array that are to be output, starting from the first array element.

Your program must include the use of the 3 function calls as shown above, and they perform only the specified tasks. These statements may not be altered in any way. However your main() function may, and should, include additional statements to define the data to be used that is consistent with the given function calls.

You will also have to include the declaration/definitions of each of the functions called in main();

Here is my Time class implemented, last assignment code: #include

using namespace std;

class Time { private: int hour; int min; int sec; public: Time(): hour (0), min (0),sec (0) {} Time (int h,int m,int s): hour (h), min (m), sec (s) {} int getHours() {return hour;} int getMins() {return min;} int getSecs() {return sec;} bool LessThan(Time t); bool GreaterThan(Time t); bool EqualTo(Time t); void setHours(int h){ hour=h; } void setMintues(int m){ min=m; } void setSeconds(int s){ sec=s; } void setTime(int h, int m, int s){ hour=h; min=m; sec=s; } void Read(); void Write(); };

void Time::Read() { cin>>hour>>min>>sec; } void Time::Write() { cout<

bool Time::LessThan(Time t) { if ((hour < t.hour) || ((hour == t.hour) && (min < t.min)) || ((hour == t.hour) && (min == t.min) && (sec < t.sec))) return true; return false; }

bool Time::GreaterThan(Time t) { if ((hour > t.hour) || ((hour == t.hour) && (min > t.min)) || ((hour == t.hour) && (min == t.min) && (sec > t.sec))) return true; return false; } bool Time::EqualTo(Time t) { return (hour==t.hour) && (min==t.min) && (sec==t.sec); }

int main() { Time t1, t2(12, 45, 35); cout<<"t1 = "; t1.Write(); cout << " t2 = "; t2.Write(); cout << " Please enter a time in the format hh:mm:ss "; t1.Read(); cout << " Enter another value in the same format "; t2.Read(); cout << " The 2 time values that you entered are, in ascending order "; if (t1.LessThan(t2)) { t1.Write(); cout << ' '; t2.Write(); } else { t2.Write(); cout << ' '; t1.Write(); } cout << " "; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions