Question

Write a program that prompts the user to enter two characters and displays the major and status represented in the characters.

Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: 

M: Mathematics

C: Computer Science 

T: Testing and Certification

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Plan:

• Declare char, string and bool type variables

• Read 2 character from user.

• Use else if statement to concatenate string in result string variable accordingly. Also reset value of b1 and b2 variable.

• Use another if else if statements to display major and status according to value of bool variable.

Program:

/**********************************************************

* Program to display student major and status *

**********************************************************/

//Header file

#include

#include

using namespace std;

int main()

{

//declare char, string and bool type variables

char first,second;

string result;

bool b1=true,b2=true;

cout<<"Enter two characters: ";

//read two character from user

cin>>first;

cin>>second;

Use else if statement to concatenate string in result string variable accordingly.

//check value of first variable

if(first=='M')

//concatenate value in string variable

result="Mathematics";

else if(first=='C')

result="Computer Science";

else if(first=='I')

result="Information Technology";

else

//reset value of b1 variable

b1=false;

//check value of second variable

if(second=='1')

//concatenate value in string variable

result=result+" Freshman";

else if(second=='2')

result=result+" Sophomore";

else if(second=='3')

result=result+" Junior";

else if(second=='4')

result=result+" Senior";

else

//reset value of b1 variable

b2=false;

Use if else if statement to display major and status according to value of bool variable.

if(b1==false&&b2==false)

cout<<"Invalid major and status code"<<endl;

else if(b1==true&&b2==false)

cout<<"Invalid status code"<<endl;

else if(b1==false&&b2==true)

cout<<"Invalid major code"<<endl;

else

//display major and status code

cout<<result<<endl;

system("pause");

return 0;

}

Sample Output:

Enter a year: 2001

Enter two characters: M9

Invalid status code

Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user to enter two characters and displays the major and status represented in the characters.
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please write psedocodes for all of the questions and an algorithm for 2. no coding is...

    please write psedocodes for all of the questions and an algorithm for 2. no coding is required . FIUJELI 95 PIOL 1. (Geometry: Area of a Pentagon) Write a C# program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing the area of a pentagon is Area = 2 , where s is the length...

  • Write a program that prompts the user for student grades, calculates and displays the average grade...

    Write a program that prompts the user for student grades, calculates and displays the average grade in the class. The user should enter a character to stop providing values.

  • Write a program that prompts the user for student grades and displays the highest and lowest grades in the class.

    Write a program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values.example Enter as many student grades as you like. Enter a character to stop. The highest grade is: 92.0 The lowest grade is: 10.65# in java

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

  • Design a program that prompts the user to enter a string, and displays the character that...

    Design a program that prompts the user to enter a string, and displays the character that appears most frequently in the string. (Please read the problem above carefully. I'm asking this question for the second time because the last answer I received wasn't even paying attention to what the question asked for.) Answer MUST be using Flowgorithm with screenshots. Please attach a screenshot of the program successfully running in flowgorithm as well to confirm proper output. Thanks for understanding!

  • In Java - Write a program that prompts the user to enter two integers and displays...

    In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.

  • IN JAVA 1. Create a program that prompts the user for an integer and then displays...

    IN JAVA 1. Create a program that prompts the user for an integer and then displays a message indicating whether or not the number is a perfect square. This can be determined by finding the square root of a number, truncating it (by casting the double result), and then squaring that result 2. Write a program that prompts the user for two numbers. The first number is a minimum value and the second number is a maximum value. RandomNum then...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • Write a program that prompts the user to enter a binary string and displays the corresponding...

    Write a program that prompts the user to enter a binary string and displays the corresponding decimal integer value. For example, binary string ‘10001’ is 17 (1*24 +0*23 +0*22 +0*2 + 1 = 17) A sample run : Enter a binary: 10001 17 Enter second integer: 110 6 Use python.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT