In C++ Write a function that has an integer as a parameter. (Be Original)
The
function will return a string that represents
the
day of the week. If the parameter is a 1,
the
function will return the string “Monday”.
If the parameter is not between 1 and 7 the
function
should return "ERROR"
Write a driver program to test your function.
You
are required to use a switch statement
in
your function. Use the default case to
catch
error conditions.
NOTE: for string variables use:
#include
<string>
using
namespace::std;
int main()
{
string
day; // day is a string variable
…
}
#include <string> #include <iostream> using namespace ::std; string get_weekday_string(int m) { switch (m) { case 1: return "Monday"; case 2: return "Tuesday"; case 3: return "Wednesday"; case 4: return "Thursday"; case 5: return "Friday"; case 6: return "Saturday"; case 7: return "Sunday"; default: return "ERROR"; } } int main() { string day; // day is a string variable int n; cout << "Enter a day value[1-7]: "; cin >> n; day = get_weekday_string(n); cout << day << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.