Access Millions of academic & study documents

4) In your C++ test program, add another segment of code that will h

Content type
User Generated
Showing Page:
1/3
4) In your C++ test program, add another segment of code
that will help you decipher the day of the week codes used
in the college schedule. Your program should ask the user
to enter a single character representing the day of the
week, either M, T, W, R, or F. Your program should accept
the single character, and display the full day name as
output. Accept both upper and lower case letters. Display
an error if a character other than MTWRF is entered. You
must use an if/else structure in your program. When this
code works, use this question response to identify any
difficulties or errors you made when writing this code
segment. How did you correct these errors? Once your
code for question #4 works, add another segment of code
to it that will print the day of the week again, this time
using a switch structure. Your program should work as it
did before, except that youll see the results twice. Again,
once you\'ve gotten this code to work, use this question to
identify any errors you had when adding this section of
code, and explain how you corrected them.
Solution
#include <iostream>
using namespace std;
void printDayOfTheWeek()
{
char day;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
cout<<\"Enter character that represents day of the
week:\";
cin>>day;
if(toupper(day)==\'M\')
{
cout<<\"Day: Monday\";
cout<<\"\ Day of the week: 1\";
}
else
if(toupper(day)==\'T\')
{
cout<<\"Day: Tuesday\";
cout<<\"\ Day of the week: 2\";
}
else
if(toupper(day)==\'W\')
{
cout<<\"Day: Wednesday\";
cout<<\"\ Day of the week: 3\";
}
else
if(toupper(day)==\'R\')
{
cout<<\"Day: Thursday\";
cout<<\"\ Day of the week: 4\";

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
4) In your C++ test program, add another segment of code that will help you decipher the day of the week codes used in the college schedule. Your program should ask the user to enter a single character representing the day of the week, either M, T, W, R, or F. Your program should accept the single character, and display the full day name as output. Accept both upper and lower case letters. Display an error if a character other than MTWRF is entered. You must use an if/else structure in your program. Whe n this code works, use this question response to identify any difficulties or errors you made when writing this code segment. How did you correct these errors? Once your code for question #4 works, add another segment of code to it that will print the day of the week again, this time using a switch structure. Your program should work as it did before, except that you’ll see the results ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4