C++ Write a program that implements 4 functions. Function 1: This function shoul
ID: 3853395 • Letter: C
Question
C++ Write a program that implements 4 functions. Function 1: This function should be named "GetSecondsForYears". "GetSecondsForYears" will take as a parameter an integer which is the number of years to be converted to the equivalent number of seconds and return the result (number of seconds). If no value is passed to the function it should return -1.Use the following for your conversions: Function 2: This function should be named "GetDayString". "GetDayString" will take as a parameter an integer which represents the day of the week. As an example if the function is called with an argument of 5 the value returned would be "Friday". If no value is passed to the function it should return "Invalid Day". Function 3: This function should be named "GetMonthString". Similar to "GetDayString", "GetMonthString" will take as a parameter an integer which represents the month. As an example if the function is called with an argument of 6 the value returned would be "June". If no value is passed to the function it should return "Invalid Month". Function 4: This function should be named "GetFormattedDate". "GetFormattedDate" will take as parameters 3 integers representing the month, the day and the year and should return a "formatted" date suitable for printing to the screen. As an example if the function is called with arguments of 6, 1, 2000, the value returned would be "June 1, 2000". If the function is call with no arguments the function should return "January 1, 1900". Your functions will be Unit Tested. Therefore your program does need to define the function "Main()" but it can be empty since it won't be called by any of the tests.
please help nobody can seem to get this right for zybooks!
Explanation / Answer
Below is your program: -
#include<iostream>
#include<sstream>
using namespace std;
long GetSecondsForYears(int x) { // x means number if years say 1,2,3,4
long seconds;
seconds = x * 365 * 24 * 60 * 60; // for months having 31 days
//seconds = seconds + (x * 6 * 30 * 24 * 60 * 60); // for months havig 30 days
//seconds = seconds + (x * 1 * 28 * 24 * 60 * 60); // for Feb. Note I am not considering leap year information here.
return seconds;
}
long GetSecondsForYears() { // if no value passed
return -1;
}
string GetDayString(int x) { // x is integer representing day
if(x == 1) {
return "Monday";
} else if(x == 2) {
return "Tuesday";
} else if(x == 3) {
return "Wednesday";
} else if(x == 4) {
return "Thursday";
} else if(x == 5) {
return "Friday";
} else if(x == 6) {
return "Saturday";
} else if(x == 7) {
return "Sunday";
} else {
return "Invalid Day";
}
}
string GetDayString() { // If no value passed
return "Invalid Day";
}
string GetMonthString() { // if no value passed
return "Invalid Month";
}
string GetMonthString(int x) { //x represents month here.
if(x == 1) {
return "January";
} else if(x == 2) {
return "February";
} else if(x == 3) {
return "March";
} else if(x == 4) {
return "April";
} else if(x == 5) {
return "May";
} else if(x == 6) {
return "June";
} else if(x == 7) {
return "July";
} else if(x == 8) {
return "August";
} else if(x == 9) {
return "September";
} else if(x == 10) {
return "October";
} else if(x == 11) {
return "November";
} else if(x == 12) {
return "December";
} else {
return "Invalid Month";
}
}
string GetFormattedDate() {
return "January 1, 1900";
}
string GetFormattedDate(int x,int y,int z) {
string month = GetMonthString(x);
stringstream day,year;
day << y;
string date = day.str();
year << z;
string year1 = year.str();
if(month != "Invalid Month") {
return month + " "+ date+", "+year1;
} else {
return "Invalid Date";
}
}
int main() {
string date = GetFormattedDate(6,20,2007);
cout<<date;
cout<<endl<<GetSecondsForYears(4);
return 0;
}
Sample Run: -
June 20, 2007
126144000
--------------------------------
Process exited after 0.1551 seconds with return value 0
Press any key to continue . . .
Note: - Please remove lines from main function as per your question...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.