In: Computer Science
Create in C++
Prompt the user to enter a 3-letter abbreviation or a
day of the week and display the full name of the day of the week.
Use an enumerated data type to solve this
problem.
Enumerate the days of the week in a data type.
Start with Monday and end with Friday.
Set all of the characters of the user input to lower case.
Set an enumerated value based on the user input.
Create a function that displays the name of the day
Based on the value passed from main(), the function should display the corresponding full name of the day of the week.
If the user entered a correct 3-digit abbreviation for a day of the week in step 4, then call the function your created in step 5.
If the user did not enter a correct 3-digit abbreviation for a day of the week, then display an error message.
#include <iostream>
#include <string.h>
using namespace std;
void display(string ); // function prototype
int main()
{
enum week{Mon=1, Tue=2, Wed=3, Thu=4, Fri=5}; //Enumerating the
days of the week in a data type. starting with monday and ending
with friday.setting enum values.
char day[10];
int choice;
cout<<"Enter a 3-letter abbreviation of day of the
week,(example Mon,Tue,Wed,Thu,Fri)\n"; //Promting user for an
input
cin>>day; // user input
strlwr(day);//converting all of the characters of the user input to
lower case using string lower string function.
display(day); // calling display function with user input as
argument.
return 0;
}
void display(string day) //function that displays the name of the
day
{
if(day=="mon")
{cout<<"Monday \n";}
else if(day=="tue")
{cout<<"Tuesday \n";}
else if(day=="wed")
{cout<<"Wednesday \n";}
else if(day=="thu")
{cout<<"Thursday \n";}
else if(day=="fri")
{cout<<"Friday \n";}
else cout<<"Invalid Input \n"; // if user
did not enter a correct 3-digit abbreviation for a day of the week,
then displaying an error message.
}
---------------------------------------------------------------------------------------x-----------------------------------------------------------------
for reference adding screenshots