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

6. Write a program to ask the user to input the first letter of the day of the w

ID: 3725409 • Letter: 6

Question

6. 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. 7. Modify problem #6 to return the name of the function to the main and print out the name. Previous Next

Explanation / Answer

6)Here we are printing in the function itself which is the sixth part

#include "iostream"
using namespace std;
void determine_name(char c){
char temp;
if(c=='m'){cout<<"monday ";}
else if(c=='w'){cout<<"wednesday ";}
else if(c=='f'){cout<<"friday ";}
else if(c=='t'){
cout<<"Please give the second letter of the day name in small letters:";
cin>>temp;
if(temp=='u') cout<<"tuesday ";|
else cout<<"thursday ";
}
else if(c=='s'){
cout<<"Please give the second letter of the day name in small letters:";
cin>>temp;
if(temp=='a') cout<<"saturday ";
else cout<<"sunday ";}
else cout<<"Incorrect Input ";
}
int main(){
char c;
cout<<"Give the first letter of the day name in small letters:";
cin>>c;
determine_name(c);
}

7)Here we are returning and printing as part7

#include "iostream"
using namespace std;
char* determine_name(char c){
char temp;
char *day;
if(c=='m'){day="monday";}
else if(c=='w'){day="wednesday";}
else if(c=='f'){day="friday";}
else if(c=='t'){
cout<<"Please give the second letter of the day name in small letters:";
cin>>temp;
if(temp=='u') day="tuesday";
else day="thursday";
}
else if(c=='s'){
cout<<"Please give the second letter of the day name in small letters:";
cin>>temp;
if(temp=='a') day="saturday";
else day="sunday";
}
else day="Incorrect Input";
return day;
}
int main(){
char c;
cout<<"Give the first letter of the day name in small letters:";
cin>>c;
cout<<determine_name(c)<<endl;
}