Question

Use a Switch statement.A switch statement is just another way of writing an IF statement. The...

Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior.

Use character data type for c++. Then you can say something like:

char level ='f';

level=toupper(level);

You would need a loop for 1 to 5, to test for f, s, j, r and also an illegal grade level. Use a "z" for the illegal grade level

Convert the input to upper case so you won't have a case in your switch for both lower and upper case letters.

Remember, a switch statement is just another way of writing an if statement.

Then inside the switch statement print out if they were a freshman, sophomore, etc. spelled all the way out.

So the input for freshmen is a "f", but the output is "Freshmen".

So you have an outer loop from 1 to 5, then inside the loop

you enter a letter

change the letter to upper case

have a switch statement to check what was entered from the keyboard and print the appropriate grade level spelled out as in "Senior".

Don't forget your breaks in the switch statement.

In C++, please us visual studios and show output

Homework Answers

Answer #1

#include <iostream>
using namespace std;
int main()
{
char gradelevel,level;
for(int i=0;i<5;i++)
{
cout<<"Enter character f,s,j,r or any other : ";
cin>>gradelevel;
level=toupper(gradelevel);
switch(level)
{
case 'F': cout<<"Freshman"<<endl;
break;
case 'S': cout<<"Sophomore"<<endl;
break;
case 'J':cout<<"Junior"<<endl;
break;
case 'R':cout<<"Senior"<<endl;
break;
default:cout<<"Invalid option";
}//end switch
}//end for loop
return 0;
}//end main

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question Rewrite the following C program using switch-case statement. and give me an output please use...
Question Rewrite the following C program using switch-case statement. and give me an output please use printf and scanf #include<stdio.h> int main(void) {      int semester;           printf("What is your Studying Level (1-8)?> ");      scanf("%d" , &semester);      if(semester == 1 || semester == 2)           printf("Your are a freshman!\n ");      else if(semester == 3 || semester == 4)           printf("Your are sophomore!\n ");      else if(semester == 5 || semester == 6)           printf("Your are...
At a school rally, a group of sophomore students organized a free raffle for prizes. They...
At a school rally, a group of sophomore students organized a free raffle for prizes. They claim that they put the names of all the students in the school in the basket and they randomly drew 36 names out of the basket. Of the prize winners, 6 were freshmen, 14 were sophomores, 9 were juniors and 7 were seniors. The results do not seem that random to you. You think it is a little fishy that sophomores organized the raffle...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that will provide the same function. Char grade; String tstmsg; if (grade == ‘A’) {   tstmsg = “Excellent”; } else if (grade == ‘B’) {   tstmsg = “Good”; } else if (grade == ‘C’) {   tstmsg = “OK”; } else {   tstmsg = “Study More”; } 2.Write the following for statement as a while statement. for (k = 0; k < 3; k++) {   System.out.println...
use repl.it intro to C-programing no advance code also put good comment that i can know...
use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you use repl.it intro to C-programing no advance code also put good comment that i can know whats this code use for  thank you program for a game of hangman. Store the word to be guessed as individual characters of an array called word. The player must guess the letters belonging to word. If the user enters a valid letter,...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use of relational and logical operators to check numeric ranges User friendly Use of user friendly user prompt and simple input validation Use of meaningful output labels and format Use of output manipulators Working with string type Use of getline() Project Description There are two main systems for measuring distance, weight and temperature, the Imperial System of Measurement and the Metric System of Measurement. Most...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
4) Write a java program where you will use while loop, where if condition is equal...
4) Write a java program where you will use while loop, where if condition is equal to 2 (or any other choice of your number) then it will break the while condition. Steps: 1) Declare variable int (any name) which is equal to zero 2) Declare while condition which variable int is less then equal to 10 3) Declare print out where the value of variable is the same name that you declared in step 1 4) Declare condition if...
Description: The purpose of this assignment is to practice writing code that calls functions, and contains...
Description: The purpose of this assignment is to practice writing code that calls functions, and contains loops and branches. You will create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. General Comments: Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement an...
Python Programming Assignment 3 For this assignment you have been given a starting file to use...
Python Programming Assignment 3 For this assignment you have been given a starting file to use for the assignment. Some code is already in this file, and it provides functionality you’ll be using to complete this assignment. Your code needs to go in a specific place, marked #### Your Code Here You code must go under this comment, and you should not modify the other parts of the file, except to add a block comment at the top with your...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m. The Lab08 function will take in a string as input and will return an integer n as output. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'. Please note that...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT