27.07.2015 Views

COMP 122 Lab 3 Lab Report and Source Code (Devry) / comp122dotcom

For more course tutorials visit www.comp122.com COMP 122 Week 3 iLab Complete the following two programs: Programming Problem 1 Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3. This program has the following requirements: A. The user must enter a positive integer. If the user enters something else, your program should output an error message and let the user enter a new value. Use a do/while loop to make sure the user input is successful. B. The factors must be output in increasing order. The lowest factor your program should report is 2. C. Your program should output 4 factors per line, each factor in a field of 10 characters. (Hint: the number of factors output determines when to output endl!)

For more course tutorials visit
www.comp122.com
COMP 122
Week 3 iLab
Complete the following two programs:
Programming Problem 1
Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3. This program has the following requirements:
A. The user must enter a positive integer. If the user enters something else, your program should output an error message and let the user enter a new value. Use a do/while loop to make sure the user input is successful.
B. The factors must be output in increasing order. The lowest factor your program should report is 2.
C. Your program should output 4 factors per line, each factor in a field of 10 characters. (Hint: the number of factors output determines when to output endl!)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>COMP</strong> <strong>122</strong> <strong>Lab</strong> 3 <strong>Lab</strong> <strong>Report</strong> <strong>and</strong> <strong>Source</strong> <strong>Code</strong> (<strong>Devry</strong>)<br />

Click Here to Buy the Tutorial<br />

http://www.comp<strong>122</strong>.com/product-27-<strong>COMP</strong>-<strong>122</strong>-<strong>Lab</strong>-3-<strong>Lab</strong>-<strong>Report</strong>-<strong>and</strong>-<br />

<strong>Source</strong>-<strong>Code</strong><br />

<strong>COMP</strong> <strong>122</strong><br />

Week 3 i<strong>Lab</strong><br />

Complete the following two programs:<br />

Programming Problem 1<br />

For more course tutorials visit<br />

www.comp<strong>122</strong><br />

comp<strong>122</strong>.com<br />

Write a program that generates all the factors of a number entered by the user. For instance,<br />

the number 12 has the factors 2 * 2 * 3. This program has the following requirements:<br />

A. The user must enter a positive integer. If the user enters something else, your program<br />

should output an error message <strong>and</strong> let the user enter a new value. Use a do/while loop to<br />

make sure the user input is successful.<br />

B. The factors must be output in increasing order. The lowest factor your program should<br />

report is 2.<br />

C. Your program should output 4 factors per line, each factor in a field of 10 characters. (Hint:<br />

the number of factors output determines when to output endl!)<br />

D. You will need a while loop to report the factors. Here are some helpful hints:<br />

1. If (a % b == 0) then a is a factor of b.<br />

2. When you have found a factor, output the factor <strong>and</strong> then reduce the number you are<br />

working with by dividing the number by the factor… ie) / a;<br />

1. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get<br />

each input <strong>and</strong> to report the output. Include steps to deal with error cases as specified above.<br />

2. Identify three test cases, one using a number with 4 factors, one using a negative number,<br />

<strong>and</strong> one using a number with more than 4 factors. For each of the three test cases show what<br />

inputs you will use <strong>and</strong> what your expected outputs should be.<br />

3. Write the program to implement your algorithm. Test your program using your test cases.<br />

Programming Problem 2


This program is designed to analyze the growth of two cities. Each city has a starting<br />

population <strong>and</strong> annual growth rate. The smaller city has the larger growth rate (required).<br />

Show the comparative populations of each city year by year until the smaller city has grown<br />

larger than the bigger city.<br />

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown<br />

has a population of 7000 growing at 10% annually. The projected populations are:<br />

Year DogvilleCattown<br />

1 6000 7700<br />

2 7200 8470<br />

3 8640 9317<br />

4 10368 10249<br />

1. Identify the inputs <strong>and</strong> outputs of the problem.<br />

2. Identify the processing needed to convert the inputs to the outputs<br />

3. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get<br />

each input <strong>and</strong> to report each output.<br />

4. Identify three significant test cases including one for incorrect input (ie Small town has<br />

lower growth rate). For each of the three test cases show what inputs you will use <strong>and</strong><br />

calculate what your expected outputs should be.<br />

5. Write the program to implement your algorithm. Test your program using your test cases.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!