User in put is in bold: Test 1 > run Enter integer: -5 Number must be positive. Enter integer: 0 Number must be positive. Enter integer: 1 Factors of all numbers up to l 1: 1

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 14PE
icon
Related questions
Question

Test 5 > run Enter integer: 7 Factors of all numbers up to 7 1: 1 2: 1, 2 3: 1, 3 4: 1, 2, 4 5: 1, 5 6: 1, 2, 3, 6 7: 1, 7 Test 6 >

run Enter integer: 21

Factors of all numbers up to 21

1: 1

2: 1, 2

3: 1, 3

4: 1, 2, 4

5: 1, 5

6: 1, 2, 3, 6

7: 1, 7

8: 1, 2, 4, 8 9: 1, 3, 9 10: 1, 2, 5, 10 11: 1, 11 12: 1, 2, 3, 4, 6, 12 13: 1, 13 14: 1, 2, 7, 14 15: 1, 3, 5, 15 16: 1, 2, 4, 8, 16 17: 1, 17 18: 1, 2, 3, 6, 9, 18 19: 1, 19 20: 1, 2, 4, 5, 10, 20 21: 1, 3, 7, 21

Programming Assignment

Your solution will be graded based upon program behavior (passing tests). Your solution will not receive full credit (or receives no credit) if you fail to follow these restrictions:

  • Your program must compile and run. Otherwise it will receive a zero.
  • Add your solution to the provided code template.
  • Do NOT use the do-while statement. Only use the while and for statements where appropriate.
  • Use descriptive variable names. Avoid too short variable names, especially single letter variable names.
  • DO NOT start a variable name with a capital letter.
  • DO NOT use == true or == false in your boolean expressions (see lecture notes).
  • DO NOT use explicit type casting. Instead use coercion (see lecture notes).
  • DO NOT unnecessarily use parenthesis in an expression, e.g. an equation or formula. Parenthesis should only be used for grouping portions of an expression to change operator precedence order. For example, parenthesis are unnecessary in the expression (a + b + c). Instead use a + b + c. Parenthesis are necessary in the expression (a + b + c) / 3.
  • DO NOT use the break and continue statements in your solution.
  • Your program must be readable including indenting, spaces, and avoid lines that are too long. Use the the sample programs in the lecture notes as a guide.
  • Comment your program. Read the document at the "Lecture" link on Carmen under Modules->Commenting Your Program-> Commenting your program. DO NOT comment every line.
  • Only use C++ statements presented in the course. I.e. statements and notation presented in the lecture notes and assigned readings.

To receive full credit, only use C++ statements presented in the lecture notes and assigned readings. Your solution will be graded based on passing test cases, formatting, and good choice of variable names. Write your solution in the provided code template.

Important!: Write your code incrementally. This means implement your solution one portion at a time where you compile, run, and test the code portion before moving on to the next portion. Use the provided test cases to help you arrive at your final solution.

 

TASK 3: Write C++ code to prompt the user for a positive integer. Repeatedly re-prompt the user if the value entered is not a positive value. Compile, run, and test this solution before continuing to the next task.

TASK 4: Write C++ code to display factors (comma separated) for each integer from 1 to the value entered in TASK 3.

  • Be sure that there is a comment documenting each variable (see the document on Carmen under Modules on how to comment your code).

  • Do not start a variable name with a capital letter. Be sure that your code is properly indented, readable, and use good descriptive names.

  • Test your solution.

Test 2
> run
Enter integer: 0
Number must be positive.
Enter integer: 2
Factors of all numbers up to 2
1: 1
2: 1,
2
Test 3
> run
Enter integer: 3
Factors of all numbers up to 3
1: 1
2: 1, 2
3: 1, 3
Test 4
> run
Enter integer: 4
Factors of all numbers up to 4
1: 1
2: 1, 2
3: 1,
4: 1, 2, 4
Transcribed Image Text:Test 2 > run Enter integer: 0 Number must be positive. Enter integer: 2 Factors of all numbers up to 2 1: 1 2: 1, 2 Test 3 > run Enter integer: 3 Factors of all numbers up to 3 1: 1 2: 1, 2 3: 1, 3 Test 4 > run Enter integer: 4 Factors of all numbers up to 4 1: 1 2: 1, 2 3: 1, 4: 1, 2, 4
Write a program that prompts for a positive integer and prints the factors of all integers from 1 to that input integer. For example, if the user
enters the integer 6 then the program will output:
1: 1
2: 1, 2
3: 1, 3
4: 1,
2,
4
5: 1, 5
6: 1, 2, 3, 6
Determine the appropriate loop(s) to use (while loop or for loop) when a task requires looping.
Study the tests below to help you understand program behavior. Use the following tests and your own tests to run against your solution in
Develop mode. These are the same tests that your solution will be executed against when you submit your work in Submit mode. User
input is in bold:
Sample Runs (Program Behavior)
User in put is in bold:
Test 1
> run
Enter integer: -5
Number must be positive.
Enter integer: 0
Number must be positive.
Enter integer: 1
Factors of all numbers up to 1
1: 1
Transcribed Image Text:Write a program that prompts for a positive integer and prints the factors of all integers from 1 to that input integer. For example, if the user enters the integer 6 then the program will output: 1: 1 2: 1, 2 3: 1, 3 4: 1, 2, 4 5: 1, 5 6: 1, 2, 3, 6 Determine the appropriate loop(s) to use (while loop or for loop) when a task requires looping. Study the tests below to help you understand program behavior. Use the following tests and your own tests to run against your solution in Develop mode. These are the same tests that your solution will be executed against when you submit your work in Submit mode. User input is in bold: Sample Runs (Program Behavior) User in put is in bold: Test 1 > run Enter integer: -5 Number must be positive. Enter integer: 0 Number must be positive. Enter integer: 1 Factors of all numbers up to 1 1: 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning