Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am really struggling with getting my code to run properly. I am not sure what all needs to be put in the main method

I am really struggling with getting my code to run properly. I am not sure what all needs to be put in the main method in order to get the output to execute correctly. Like the clocks and the menu options to display. Can you look through my code and let me know what I am doing wrong? I'll paste my code below along with what the output should look like.image text in transcribed

#include #include

using namespace std;

// Function declarations void setHour(int h); void setMinute(int m); void setSecond(int s); int getHour(); int getMinute(); int getSecond(); string twoDigitString(unsigned int num); string nCharString(size_t n, char c); string formatTime24(unsigned int h, unsigned int m, unsigned int s); string formatTime12(unsigned int h, unsigned int m, unsigned int s); void printMenu(char* strings[], unsigned int numStrings, unsigned char width); unsigned int getMenuChoice(unsigned int maxChoice); void displayClocks(unsigned int h, unsigned int m, unsigned int s); void mainMenu(); void addOneHour(); void addOneMinute(); void addOneSecond();

int h; int m; int s; size_t n; char c; char strings[]; unsigned int numStrings; unsigned char width;

// Mutators and accessors to set and get hours, minutes, and seconds void setHour(int hour) { h = hour; }

void setMinute(int minute) { m = minute; }

void setSecond(int second) { s = second; }

int getHour() { return h; }

int getMinute() { return m; }

int getSecond() { return s; }

// Return the two digit string representation of a number string twoDigitString(unsigned int num) { string newDigitString = ""; // initializing empty string

/* If the number to format is less than 10, add a leading 0. Otherwise, convert the number to a string. Assign the num value to the newDigitString variable. */ if (num

// Returns a string of length n, each character a c. string nCharString(size_t n, char c) { string newCharString = ""; //initiliazing empty string

/* For loop that iterates through the length of string n to form the output string. Adds a character to the string variable. Returns the n character string */ for (size_t i = 0; i

return newCharString; }

// Formats the time in military format. string formatTime24(unsigned int h, unsigned int m, unsigned int s) { string format24HrString = ""; // initializing empty string

/* Formats time so there is a colon between hours and minutes and between minutes and seconds Returns time as hh:mm:ss. */ format24HrString += twoDigitString(h) + ":" + twoDigitString(m) + ":" + twoDigitString(s); return format24HrString; }

/* * Formats the time in am/pm format * Returns hh:mm:ss A M or hh:mm:ss P M where hh is between 01 and 12, inclusive. */ string formatTime12(unsigned int h, unsigned int m, unsigned int s) { string format12HrString = ""; // initializing empty string

/* Conditional to check to check the hour. Adds 12 if hour is equal to 0. Assigns hour to format12HrString variable if less than or equal to 12. Otherwise, subtracts 12 from hour if greater than 12. */ if (h == 0) { format12HrString += "12:"; } else if (h

// Adds minutues and seconds format12HrString += twoDigitString(m) + ":"; format12HrString += twoDigitString(s);

/* Conditional to check for the time of day. Assigns A M if hour is less than 12 and P M if hour is greater than 12. */ if (h

// Returns hh:mm:ss A M or hh:mm:ss P M. return format12HrString; }

// Prints menu void printMenu(char* strings[], unsigned int numStrings, unsigned char width) { // Prints a width of *'s followed by an endl. cout

/** Next, for each string s in the array: * cout a star, a space, the item Number a space a hyphen another space, s, * and enough spaces to get to a length of width - 1 (enough will depend on the length of the current menu item). * Close the line with a star and an endl. The goal is that the stars on the right align with each other and each line * has the same width, passed in as a parameter. * (Hint: calculate the needed number of spaces and use nCharString to produce them) * Skip a line after each line except the last line

* For loop that iterates through the strings array and prints each menu option. */

for (unsigned int i = 0; i

// Prints another width of *s followed by an endl outside of the loop. cout

return; }

// Gets menu choice 1 through maxChoice, inclusive unsigned int getMenuChoice(unsigned int maxChoice) { unsigned int menuChoice = 0; // initializing choice variable

/* * While loop to check if user input is within range. * Exits the loop once input is within range. * Returns the value. */ while (menuChoice maxChoice) { // while choice is not between 1 and maxChoice, inclusive cout > menuChoice; }

return menuChoice; }

// Display the clocks void displayClocks(unsigned int h, unsigned int m, unsigned int s) { // cout 27 stars + 3 spaces + 27 stars + endl cout

// cout 1 star + 6 spaces + 12-HOUR CLOCK + 6 spaces + 1 star + 3 spaces cout

// cout 1 star + 6 spaces + 24-HOUR CLOCK + 6 spaces + 1 star + endl cout

// cout an endl for a blank line cout

// cout 1 star + 6 spaces + formatTime12(h, m, s) + 7 spaces + 1 star + 3 spaces cout

// cout 1 star + 8 spaces + formatTime24(h, m, s) + 9 spaces + 1 star + endl cout

// cout 27 stars + 3 spaces + 27 stars + endl cout

// Repeats getting the user's choice and taking the appropriate action until the user chooses 4 for exit. void mainMenu() { unsigned int menuChoice = 0; // initializing choice variable

/* While loop that continues to execute as long as menu choice is not 4. * Switch statement that takes action based on the menu choice selected. * Returns nothing, just calls the appropriate methods. */ while (menuChoice != 4) { menuChoice = getMenuChoice(4); switch (menuChoice) { case 1: addOneHour(); break; case 2: addOneMinute(); break; case 3: addOneSecond(); break; case 4: cout

// Adds one minute void addOneMinute() { /* *If conditional that checks if minutes is between 0 and 58 inclusive, then adds 1 and sets minutes. * Otherwise, if minute is 59, sets the minutes to 0 and calls the addOneHour(). * Returns nothing, just setMinute to the appropriate value and use addOneHour if needed. */ if (getMinute()

// Adds one second void addOneSecond() { /* * If conditional that checks if seconds is between 0 and 58 inclusive, then adds 1 and sets seconds. * Otherwise, if seconds is 59, set seconds to 0 and calls the addOneMinute(). * Nothing to return, just call setSecond() with the right value and addOneMinute() when needed. */ if (getSecond()

int main() { displayClocks(h,m,s); printMenu(); mainMenu(); }

[CI-1AA TE Chada Tech Clocks Functional Requirements Problem Statement Chada Tech has domestic and international clients. To meet international standard ISO 8601, Chada Tech wants their clients to be able to view a 12- and a 24-hour clock on their website rather than just the standard 12-hour clock. Functional Requirements 1. Clock12: Time should be displayed in 12-hour format where the clock does not exceed 12:59:59. 2. Clock24: Time should be displayed in 24-hour format where the clock does not exceed 23:59:59. 3. Both clocks should display on the screen with the current time in the proper format. For example: 4. Your solution should allow the user to exit the program as well as add one hour, minute, or second to both clocks from a user menu as follows: * 1 - Add One Hour * 2 - Add One Minute * 3 - Add One Second * 4 - Exit Program 5. Once a selection is made from the user menu, the program should take action based on that choice. Both clocks must display on the screen simultaneously in the proper format next to each other. Below is a sample of the expected output if the user selects option 3 from the menu

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

Students also viewed these Databases questions