Question

Write a C++ program using four enumerators. Initialize each as follows: 1. first, second, third, fourth,...

Write a C++ program using four enumerators. Initialize each as follows:

1. first, second, third, fourth, fifth, sixth, seventh, eighth, ninth

2. Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday

3. curve, fast, knuckle, slider

4. single, double, triple, homer

The program should prompt a user to input a character array or 4 numbers pertaining to each enumerator. Display help text to assists the user. The help text should display the smallest and largest possible valuesfor each inputted number. Validate the input.Display an error message for a number entered outside the range of the enumerator.Using the enumerators, generate a sentence that will display as follows:

In the fifth inning on Saturday, I hit a fast ball for a triple.;

where (fifth, Saturday, fast and triple)are printed using the input generated from the irrespective enumerators.

The input that produced the statement above would be: 4612

The program should loop allowing the user to decide whether or not he or she wishes to process the loop again.

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

#include<iostream>
#include<string>
using namespace std;
//enum decleration and defination
enum num{first, second, third, fourth, fifth, sixth, seventh, eighth, ninth};
enum day{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
enum speed{curve, fast, knuckle, slider};
enum score{single, Double, triple, homer};

//function getting string from enums
string get_number(num N)
{
std::string Number[9] = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth"};
return Number[N];
}
string get_day(day D)
{
std::string Days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
return Days[D];
}
string get_speed(speed S)
{
std::string SPeed[4] = {"curve", "fast", "knuckle", "slider"};
return SPeed[S];
}
string get_score(score SC)
{
std::string SCore[4] = {"single", "double", "triple", "homer"};
return SCore[SC];
}
int main()
{
string str;
char ch = 'y';
/*
We will use do while loop for asking inputs multiple times on user choice
*/
do
{
cout<<"\nRange for 1st Number 0-8"<<endl;
cout<<"Range for 2nd Number 0-6"<<endl;
cout<<"Range for 3rd Number 0-3"<<endl;
cout<<"Range for 4th Number 0-3"<<endl;

cout<<"Enter string pertaining to 4 enumerator : ";
cin >> str;
num N = (num)(str[0]-'0'); //converting char to enum type i.e. index of enum
day D = (day)(str[1]-'0');
speed S = (speed)(str[2]-'0');
score SC = (score)(str[3]-'0');
cout<<"\nIn the "<<get_number(N)<<" inning on "<<get_day(D)<<", I hit a "<<get_speed(S)<<" ball for a "<<get_score(SC)<<"."<<endl;

cout<<"Do you want to continue y/n : ";
cin>>ch;

}while(ch == 'y' || ch == 'Y');


return 0;
}

Please refer screenshot below

C:\Users kgumgaon\Desktop Test\binDebug test.exe Range for 1st Number 0-8 Range for 2nd Number 0-6 Range for 3rd Number 0-3 R

Add a comment
Know the answer?
Add Answer to:
Write a C++ program using four enumerators. Initialize each as follows: 1. first, second, third, fourth,...
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
  • Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides...

    Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides a text box for entering a 9-digit number. The btnValidate_Click procedure should use the algorithm and example shown in Figure 7-56 to validate the user’s entry. The procedure should display a message indicating whether the entry is or is not valid. Code the procedure. Include any other code that will professionalize the interface. Save the solution and then start and test the application. Create...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Trying to write this program using c language using functions, pointers and loops. "al 67% 1...

    Trying to write this program using c language using functions, pointers and loops. "al 67% 1 1 :14 AM importanu Name your TIies HW2 firstlastname.c Develop a solution to the following problem: A financial institution will only accept loan applications if the following conditions are met: The applicant must own his/her home with no mortgage payment and -The applicant must have a total annual household income of no less than $45000.00. The applicant must have a credit score of no...

  • Write a MIPS program that prints(displays) "Hello World" using MMIO (NOT syscall!) Here is a scre...

    Write a MIPS program that prints(displays) "Hello World" using MMIO (NOT syscall!) Here is a screenshot of a MIPS program that prints user input to the screen. And I need something that displays "Hello World" without taking any input. Please help! Thanks. The output should be something like this but without the input .data 7 strl:.asciiz "\nStart entering characters in the MMIO Simulator" .text 10 .globl echo 12 13 14 15 16 17 echo: al Read # single print statement...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Write a program that defines a Print Job structure as follows: 1) An integer job Id...

    Write a program that defines a Print Job structure as follows: 1) An integer job Id 2) A string user name (maximum 25 characters) 3) An integer tray (tray will hold the tray number 1 for 8 1/2 by 11 paper, number 2 for 8 1/2 by 11 paper, and number 3 for 8 1/2 by 14 paper) 4) An integer for paper size (this will hold a percentage: 100% is normal, 150% is 1.5 times the size) 5) A...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • I am using C++ Write a program to determine if a gird follows the rules to...

    I am using C++ Write a program to determine if a gird follows the rules to be classified as a Lo Shu Magic Square. The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in figure below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown...

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
ADVERTISEMENT