Subject Computer Science C-Family Programming

Question

Programs – Chapter 5 – Repetition Structures (25 Points Each)
Directions (Read CAREFULLY and follow COMPLETELY):
• Create the following programs in C++ that perform the purpose described and show the sample output (with user input where applicable).
• Include at least three lines of comments/remarks in each program, including your name, the date, and a description of the program.
• Upload your .cpp source files to Moodle for each of the programs listed.
• Add to Homework 5s ’s Word file the output of your program and the screenshot of the run.
• Add pseudocode or a flowchart for ONE of the two programs below and add it to your Word/PDF document.
• Be sure to adhere to the college and course academic honesty policy.

1. Running and Grand Total Program
Create a .cpp program named hw5-1.cpp that asks the user for a maximum number. A loop will then run from 1 to this many times.
Each time the loop runs, two user-defined function will be called, each passing in two variables and returning one. The first function will calculate and return the running total (total) based on the loop counter. The second function will calculate and return the grand total. Both running total and grand total are accumulators (total accumulators count and grand total accumulates total).
Then, in the loop, the counter value and running total (accumulator) will be outputted as shown in the example below. Separate count and total by a tab and display the grand total as shown in the example. The grand total will be outputted after the loop is finished and is a total of all of the other totals.
Enter maximum number: 5
Count: 1 Total: 1
Count: 2 Total: 3
Count: 3 Total: 6
Count: 4 Total: 10
Count: 5 Total: 15
Grand Total: 35

The output should be formatted EXACTLY as above.


2. Table Creator Program
Create a .cpp program named hw5-2.cpp that will create a table as shown below where the user can specify by user input how many rows and columns to display.

Sample:
Enter how many columns you want your table to have: 4
Enter how many rows you want your table to have: 3
Row 1 Column 1 Row 1 Column 2 Row 1 Column 3 Row 1 Column 4
Row 2 Column 1 Row 2 Column 2 Row 2 Column 3 Row 2 Column 4
Row 3 Column 1 Row 3 Column 2 Row 3 Column 3 Row 3 Column 4

The main module of the program should do three things: accept in user input for how many columns the user wants, accept in user input for how many rows the user wants, call a user-defined function (module) passing in these two parameters. The function will then print a table using a nested loop as shown above. Use two tabs (\t\t) between each “Row x Column y”. You will have to search online to find out how to not have a print command start a new line. Then, start a new line after each row. Note: If you create a lot of columns, the window may print them on a new line if it is too small to accommodate them all.

Homework 5 Chapter 5 Repetition Structures
Extra Credit (10 Points Each)
1. Create a .cpp program named hw5-ec1.cpp that contains a loop. Within the loop, ask the user to enter a number. Multiply this number times 10 and display a message back to the user with the number multiplied by 10 and the result. Continue the loop as long as the product (i.e. result of multiplication) contains a value less than 100.
2. Create a .cpp program named hw5-ec2.cpp that uses a loop to read in a number from the user. If the user enters a positive integer (greater than 0) output “Congratulations, that’s a positive number” and continue the loop. If the user enters a negative number, end the loop and display the largest value previously inputted.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

Pseudo code for hw5-1.cpp

Input maximum number.
Initialize temp to zero.
Initialize total to zero.
Initialize grandtotal to zero.
Set count to one
While count is less than or equal to maximum number
Print the count
Add the count into the total....

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Programming Questions
Homework Solution
$20.00
Programming
C++
Computer Science
Integers
Series
Savings Accounts
Balance
Loops
Statements
Variables
Interest Rates
Deposits
Withdrawals
Input
Output
Number Conversion to Any Base
Homework Solution
$18.00
Base Conversion
Hexadecimal
Any Base
Convert
Number
Computer Science
C-Family Programming
C Programming: ASCII Code Characters to Integers
Homework Solution
$30.00
C Programming
Computer Science
ASCII Codes
Characters
Bits
Integers
Operations
File Management
Statements
Variables
Functions
Input
Output
Encoding
Decoding
Get help from a qualified tutor
Live Chats