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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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, 3  
4: 1, 2, 4  

---

**Explanation:**
This text appears to be from the output of a program that calculates and displays the factors of numbers up to a specified integer. The tests demonstrate that input values must be positive, and they show the factors of each number from 1 to the specified integer.
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, 3 4: 1, 2, 4 --- **Explanation:** This text appears to be from the output of a program that calculates and displays the factors of numbers up to a specified integer. The tests demonstrate that input values must be positive, and they show the factors of each number from 1 to the specified integer.
### Program for Finding Factors

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 input 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:### Program for Finding Factors 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 input 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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education