Question

In: Computer Science

Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the...

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.

Solutions

Expert Solution

#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


Related Solutions

Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter....
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter. You can assume that the the length of this message will be less than 100 characters. You will then parae this message, character by character, converting them to lower case, and find corresponding characters in the words found in the key text word array. Once a character match is found, you will write the index of the word and the index of the character...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT