Question: 1. Assignment Description Write a C++ program called Assignment3.cpp, it will perform the following three tasks: Task #1: Generate a relevant multiplication table according to
1. Assignment Description
Write a C++ program called Assignment3.cpp, it will perform the following three tasks:
Task #1: Generate a relevant multiplication table according to user's input
Task #2: Display a triangle shape according to user's input
Task #3: Predict an organism's population according to certain initial values
Your program will ask for the user's choice based on which it will switch among above three tasks. After performing the computations of the selected task, your program should ask the user if the user wants to do another execution. If the user opts to continue, then your program should loop again and display the option for above three tasks, else it should terminate.
For the general structure of the program, please refer to Lab6's description. See below as a guide, feel free to create your own structure.
int choice; //...... do { // Display the menu // 1) Generate a multiplication tabel // 2) Display a triangle shape // 3) Predict organism's population // 4) Quit. // Ask user to pick from above menu // need to validate user's choice, i.e. handle the case when user entered 5, -1, etc. switch(choice) { case 1: //code for handle Task #1 break; case 2: //code for handle Task #2 break; case 3: //code for handle Task #3 break; case 4: break;
}
} while(/* termination condition*/);
Read the instructions carefully about each task. The development process of each task is decomposed into two steps. Follow the instruction one by one. Don't go to the next step if your program does not return the proper output in a previous step.
Task #1: Generate a multiplication table
Step1: The first step is to read input from the user. The input should be a single line with two positive numbers such as 4 3. The inputs are separated by a space. Make sure the user inputs a positive integer for the number and tableSize, or else prompt the user again to do so (as shown in Output 1).
Output 1:
Please enter a number and the tableSize: -3 4
Error, number and tableSize must be positive. Please enter a number and tableSize: 3 4
Step2: Generate a multiplication table for the entered number of the required tableSize. Your output should be well formatted (as shown in Output 2). You might want to make use of tabs for formatting.
Output 2:
Please enter a number and tableSize: 8 9 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 9 * 8 = 72
Task #2: Display a Triangle Shape
Display a pattern of "+" in a proper format as the following example shows.
+ +++ +++++ +++++++ +++++ +++ +
Step1: The first step is to read the user input. If the user input is invalid (not positive or not an odd number), the program displays the error message below and ask the user to re-enter (as shown in Output 3 and 4).
Output 3:
Please enter a number of rows: -6
Error, number of rows must be positive
Output 4:
Please enter a number of rows: 6
Error, number of rows must be odd
Step2: Create nested for loops to print out a triangle pattern of +. Your output should be well formatted (as shown in Output 5).
Output 5:
Please enter a number of rows: 9
+ +++ +++++ +++++++ +++++++++ +++++++ +++++ +++ +
Task #3: Predict organism's population
Step1: The task will ask the user for the starting number of organisms, their average daily population increase rate (a percentage of current population), and the number of days they will multiply. The program will then display the size of the population for each day. Note: for this task, you will need to verify the number of organisms must be >= 2 and increase reate must be > 0 (as shown in Output 6 & 7)
Output 6:
Enter the starting number of organisms (2 or more): -6
Error, starting number must be at least 2. Please re-enter:
Output 7:
Enter the daily population increase rate as a percentage(e.g 3.5) : -2
Error, increase rate must be positive. Please re-enter:
Step2: After above step #1, assume user entered valid starting number of organisms, increse rate and numer of days in the trial, the program should display each day of the population as below Output 8 shows.
Output 8:
Enter the starting number of organisms (2 or more): 100
Enter the daily population increase rate as a percentage(e.g 3.5) : 3.5
Enter the number of days the organisms will be left to multiply: 7
Population after day 1: 103 Population after day 2: 106 Population after day 3: 109 Population after day 4: 112 Population after day 5: 115 Population after day 6: 119 Population after day 7: 123
Sample Run
Click here to see the sample run
2. Misce. Programming Requirements
Your program must also meet the specifications stated as below:
See the sample run at the end of the specification. The exact spacing is not important, what is important is that the output looks good and the columns align.
Pick and use identifiers which are self-descriptive. One-letter variable names should not be used. As an example, if you were referring to the ticket price, the variable needed might be declared as double price; instead of double x;
As we stated before, make sure for each assignment, you put the following comment header block on top of the file:
Case 1:
1 8 9 2 9 3 100 4 7 4
Case 2:
3 -100 150 -2.5 4.5 10 2 10 -3 15 1 -9 -12 9 12 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
