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).
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
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...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter payroll information Employee name and create variable for scanner Hours worked Hourly pay rate Federal tax rate State tax rate Declare variable doubles for gross pay, federal, state and total deduction Display payroll statement example: Name of employee Hours worked Hourly pay rate Gross pay which is equal hours worked multiply hourly pay rate Federal withholding which is equal of gross pay multiply federal...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT