Assignment J 30 points Create a CPP program named \"lastname-Asgn]\" to accompli
ID: 3703835 • Letter: A
Question
Assignment J 30 points Create a CPP program named "lastname-Asgn]" to accomplish the following tasks: (I point) Put your name and course and section on the first line as documentation and display your name and Assignment J to the screen. . (I point) Be sure to indent statements for readability based on examples in the book. . (1 point ) The program will have only one variable the day number and it will be entered only one time you must produce a message for what day of the week it is from the day number provided by the user based on the matching message from the list below. The program will display ONLY two messages, one using code that has switch /case statements and one from code using IF logic YOU must generate only ONE cout for each message (one from the IF one from the SWITCH) (This means you must figure out how to do OR's and/or AND's logic in both if and switch syntax and (4 points) use a variable to hold the message to print it later) For this assignment we will assume day 1 is Monday, 2 is Tuesday. etc the following messages should be displayed Friday, Sunday and Saturday Monday and Wednesday Tuesday and Thursday display "weekend have fun" display "Study for C++ Class display "Attend C++ class adjust the Attend/study message to match your class days.. meaning EACH cout may appear only two times in the program, once for IF tests once for Switch tests (3 points) any other value outside the range of 1 to 7 should display "bad day number" A. (8 points) construct the series of switch/case statements to produce the messages. B. (8 points) Construct a series of ifelse/if statements that will produce the same results. Sample output might look like one of these two execution examples-be sure to try several wrong values such as -5 and each of the values to make sure they all work: Assignment J -yourname here please enter a day number between 1 and 7? 3 message from If statements: Attending C++ Class message from Switch statements: Attending C++Class Assignment J - yourname here please enter a day number between 1 and 7215 message from If statements: invalid day number message from Switch statements: invalid day numberExplanation / Answer
#include<iostream>
using namespace std;
int main()
{
int user_in;
cout<< "Assignment j- Thomas here "; // chnage name thomas as per your requirement
cout << "Please enter a number between 1 and 7 ? "; // Displaying message to get user input
cin>> user_in; // taking user input between 1 to 7
switch(user_in)
{
case 1: // for monday
case 3: // for wednesday
cout<<"message from switch statement: ";
cout << "Study for C++ class ";
break;
case 2: // for tuesday
case 4: // for thursday
cout<<"message from switch statement : ";
cout << "Attending C++ class ";
break;
case 5: // friday
case 6: // saturday
case 7: // sunday
cout<<"message from switch statement : ";
cout << "Weekend Have fun ";
break;
default: // invalid input
cout<<"message from switch statement : ";
cout << "Invalid day number ";
}
if(user_in == 1 || user_in == 3) //for monday and wednesday
{
cout<<"message from if statement : ";
cout << "Study for C++ class ";
}
else if(user_in == 2 || user_in == 4) // for thursday and tuesday
{
cout<<"message from if statement : ";
cout << "Attending C++ class ";
}
else if(user_in == 5 || user_in == 6 || user_in == 7) // for friday, saturday and sunday
{
cout<<"message from if statement : ";
cout << "Weekend Have fun ";
}
else // for invalid choice
{
cout<<"message from if statement : ";
cout << "Invalid day number ";
}
}
/*
how to compile in Linux:
c++ filename.cpp
OUTPUT:
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 1
message from switch statement: Study for C++clasee
message from ifstatement : Study for C++ class
mihir@Hunter:~/c_chegg$ ./a.out
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 2
message from switchstatement : Attending C++ classes
message from ifstatement : Attending C++ classes
mihir@Hunter:~/c_chegg$ ./a.out
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 3
message from switch statement: Study for C++ clasee
message from if statement : Study for C++ clasee
mihir@Hunter:~/c_chegg$ ./a.out
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 5
message from switch statement : Weekend Have fun
message from if statement : Weekend Have fun
mihir@Hunter:~/c_chegg$ ./a.out
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 7
message from switch statement : Weekend Have fun
message from if statement : Weekend Have fun
mihir@Hunter:~/c_chegg$ ./a.out
Assignment j- Thomas here
Please enter a number between 1 and 7 ? 50
message from switch statement : Invalid day number
message from if statement : Invalid day number
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.