Hi guys, I need help with this one please! C++ programming Write a program that
ID: 3853133 • Letter: H
Question
Hi guys, I need help with this one please! C++ programming
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.
Explanation / Answer
#include <iostream>
#include<string>
#include<sstream>
using namespace std;
//here i am using long long because return value in second might be result in very big value
long long GetSecondsForYears(int years) {
return years * 365 * 24 * 60 * 60;
}
long long GetSecondsForYears() { //overloaded function if no value passed to function
return -1;
}
string GetDayString(int param) {
if (param == 1)
return "Monday";
else if (param == 2)
return "Tuesday";
else if (param == 3)
return "Wednesday";
else if (param == 4)
return "Thursday";
else if (param == 5)
return "Friday";
else if (param == 6)
return "Saturday";
else if (param == 7)
return "Sunday";
}
string GetDayString() { ////overloaded function if no value passed to function
return "Invalid Day";
}
string GetMonthString(int param) {
if (param == 1)
return "January";
else if (param == 2)
return "February";
else if (param == 3)
return "March";
else if (param == 4)
return "April";
else if (param == 5)
return "May";
else if (param == 6)
return "June";
else if (param == 7)
return "july";
else if (param == 8)
return "August";
else if (param == 9)
return "September";
else if (param == 10)
return "october";
else if (param == 11)
return "November";
else if (param == 1)
return "December";
}
string GetMonthString() { ////overloaded function if no value passed to function
return "Invalid Month";
}
string GetFormattedDate(int month, int day, int year) {
stringstream ss;
ss << GetMonthString(month) << " " << day << ", " << year;
return ss.str();
}
string GetFormattedDate() { //overloaded function if no value passed to function
return "January 1, 1900";
}
//A sample test function
int main() {
cout << GetFormattedDate(6, 1, 2000);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.