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

The Questions: Sample Run: What grade did you earn in Programming I ? A YOU PASS

ID: 3567139 • Letter: T

Question

The Questions:

Sample Run: What grade did you earn in Programming I ? A YOU PASSED! an A - excellent work!

The following is the code to be used:

// This program illustrates the use of the Switch statement.

#include <iostream>

using namespace std;

int main()

{

char grade;

cout << "What grade did you earn in Programming I ?" << endl;

cin >> grade;

switch( grade ) // This is where the switch statement begins

{

     case 'A': cout << "an A - excellent work !" << endl;

     break;

     case 'B': cout << "you got a B - good job" << endl;

     break;

     case 'C': cout << "earning a C is satisfactory" << endl;

     break;

     case 'D': cout << "while D is passing, there is a problem" << endl;

     break;            

     case 'F': cout << "you failed - better luck next time" << endl;       

     break;

     default: cout << "You did not enter an A, B, C, D, or F" << endl;

}

return 0;

}

//please highlight changes made and reason for the change to earn the reward to this question. Please answer if you have an answer rating above 80%. I will reward the person who answers correctly and promptly. I will reward as soon as I find out the anwer is correct.

Explanation / Answer

1. If U remove break statements, the control will check every case provided, and if there are more than 1 instance of meeting the condition, it will execute them.

best practise is to use break in switch case.

2.
inlude <iostream>

using namespace std;

int main()

{

char grade;

cout << "What grade did you earn in Programming I ?" << endl;

cin >> grade;

switch( grade ) // This is where the switch statement begins

{

case 'A': cout << "an A - excellent work !" << endl;

break;

case 'B': cout << "you got a B - good job" << endl;

break;

case 'C': cout << "earning a C is satisfactory" << endl;

break;

case 'D': cout << "while D is passing, there is a problem" << endl;

break;

case 'F': cout << "you failed - better luck next time" << endl;   

break;

default: cout << "You did not enter an A, B, C, D, or F" << endl;

}

if (grade == 'A' or grade == 'B'or grade == 'C' or grade == 'D')
cout << "contratulations You Passed";

else
cout<<"Try harder";

return 0;

}

// different version of the program

inlude <iostream>

using namespace std;

int main()

{

char grade;

cout << "What grade did you earn in Programming I ?" << endl;

cin >> grade;

if ( grade== 'A' )

{
   Cout<<"an A - excellent work !" << endl;
   cout<<"Congrats You Passed"
}
elseif (grade == 'B')
{
   cout<<"you got a B - good job" << endl;
   cout<<"Congrats You Passed"
}
elseif (grade == 'C')
{
   cout<<"earning a C is satisfactory" << endl;
   cout<<"Congrats You Passed"
}
elseif (grade == 'D')
{
   cout<<"while D is passing, there is a problem" << endl;
   cout<<"Congrats You Passed"
}
elseif (grade == 'F')
{
   cout<<"you failed - better luck next time" << endl;
}
else
{
   cout<<"You did not enter an A, B, C, D, or F" << endl;
}
return 0;

}

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