Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Present in C++ pls Write a program to ask the user to input the first letter of

ID: 3842692 • Letter: P

Question

Present in C++ pls

Write a program to ask the user to input the first letter of the day of the week (example: M or T etc). The program will then print the name of the day. The actual determination of the name of the week should take place inside a function called Day. If the user enters “S” then the program should also request for the second letter of the name. This should be done inside the function. Only pass the first letter into the function. The name of the day is printed from inside the function.

Explanation / Answer

#include <iostream>

using namespace std;
void Day(char ch){
char second;
switch(ch){
case 'm':
case 'M': cout<<"Monday"<<endl;break;
  
case 'T':
case 't': cout<<"Enter the second letter of the day of the week: ";
cin >> second;
switch(second){
case 'u':
case 'U': cout<<"Tuesday"<<endl;break;
  
case 'h':
case 'H': cout<<"Thursday"<<endl;break;
default: cout<<"Invalid input"<<endl;
}
break;
  
case 'w':
case 'W': cout<<"Wednesday"<<endl;break;
  
case 'f':
case 'F': cout<<"Friday"<<endl;break;
  
case 's':
case 'S': cout<<"Enter the second letter of the day of the week: ";
cin >> second;
switch(second){
case 'a':
case 'A': cout<<"Saturday"<<endl;break;
  
case 'u':
case 'U': cout<<"Sunday"<<endl;break;
default: cout<<"Invalid input"<<endl;
}
break;
default:
cout<<"Invalid Input"<<endl;
  
}
}
int main()
{
char ch;
cout << "Enter the first letter of the day of the week: ";
cin >> ch;
Day(ch);
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the first letter of the day of the week: w                                                                                                                                                                                                                       

Wednesday                                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the first letter of the day of the week: s                                                                                                                                                                                                                       

Enter the second letter of the day of the week: u                                                                                                                                                                                                                      

Sunday

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote