Question: Due date/Time: Friday, Feb. 23, 2018 at 5:30pm Write code using C++. What this Assignment Is About: Exercise on writing menu-driven program Exercise on writing

Due date/Time: Friday, Feb. 23, 2018 at 5:30pm

Write code using C++.

What this Assignment Is About:

Exercise on writing menu-driven program

Exercise on writing while loop

Exercise on writing input validation loop

Exercise on writing single or nested for loop

Coding Guidelines for All Labs/Assignments (You will be graded on this)

Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

Keep identifiers to a reasonably short length.

Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

Use white space to make your program more readable.

Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs.

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:

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

// FILE: Assignment3.cpp

// Name: your-name

// Student ID: your-ASU-10-digits-ID

// Description:

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

3. Submission

1) Test your program by using the inputs from the following two input test cases, compare your program's output with our solution output, make sure they are same before you submit the source file Assignment3.cpp. Read this short description on how to use test cases for your lab or assignments

2) Submit Assignment3.cpp at the following submission website.

https://courses.eas.asu.edu/cse100c/

login, then click on Assignment Submissions in the left frame. The dropdown box will start in HW1, make sure you change it by picking HW3 instead.

Click on the browse button and find where you saved your Assignment3.cpp file (and NOT the Assignment3.class file) on your computer. Upload the file to the site and then click on the Submit button.

Your file will be submitted and a screen will show up displaying if your program compiled and what your output is when run on the two input test cases.

You should then check to make sure that the actual file submitted properly and is readable to the grader. To do so click on Grades in the frame on the left of the page and then click on the 0 underneath column HW3. You will again see that your program compiled and the sample output, but you should scroll down to the bottom of the screen and make sure your file is readable as well.

It's your responsibility to make sure that you submitted the correct file on server. After the deadline, we will not accept submissions through emails!

4. Grading Rubric (20 pts)

a. Student submits the relevant source code files, whether the program compiles and/or runs correctly or not. [2 pts]

b. The general structure of the program is correct [2 pts]

c. For task #1, student correctly fulfil step #1 and #2's requirements [2 pts for each step, 4 pts in total]

d. For task #2, student correctly fulfil step #1 and #2's requirements [2 pts for each step, 4 pts in total]

e. For task #3, student correctly fulfil step #1 and #2's requirements [2 pts for each step, 4 pts in total]

f. The program student submitted compiles, runs, and produces the correct output for the two test cases [4 pts]

Input

The following files are the test cases that will be used as input for your program (Right-click and use "Save Target As"):

Test Case #1 Test Case #2

Output

The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save Target As"):

Test Case #1 Test Case #2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!