Introduction to Computing for Engineers - Loops - Assignment 2 | CS 145, Assignments of Computer Science

Material Type: Assignment; Class: Introduction to Computing for Engineers; Subject: Computer Science; University: Southern Illinois University Edwardsville; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-va6
koofers-user-va6 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 145.002
Introduction to Computing for Engineers
Fall 2008
Programming Assignment 2
“Loops”
Due: 7:30 AM, Thursday, September 18, 2008
This programming assignment requires you to write a program that extensively uses the C++ loop statements.
Basically, your program will interactively query the user for integer values and, for each value, output its prime
factorization. Recall that a prime number is an integer that cannot be evenly divided by any integer other than
itself and 1. Your program will produce prime factorizations according to the following guidelines:
The prime factorizations of 0, 1, and -1 are themselves.
The prime factorization of a negative number is -1 times the prime factorization of the positive version of
that number.
The prime factorization of a positive number larger than 1 is the listing of the individual prime numbers
which, when multiplied together, produces the positive number in question.
A sample interactive session
for this assignment is illus-
trated at right. Your output is
expected to be formatted in
an identical fashion to this.
Note that your program will
require at least three loops:
1. A "master" loop, which
will be repeatedly en-
tered as long as the user
wishes to perform
additional prime factori-
zations.
2. A "yes/no" loop, which
will compel the user to
type certain characters
when asked whether to
continue (only 'y', 'Y', 'n',
and 'N' are considered
acceptable).
3. A "factorization" loop,
which will cycle through
the numbers between 2
and half the value being
factored, checking (via
the modulus operator) whether the value can be factored by the number.
Name your project PA2_Lastname where Lastname is your last name (e.g., John Doe’s project would be
PA2_Doe). Don’t forget to include adequate explanatory comments in your code.
Zip-compress the entire project folder and place the zipped folder on your Moodle dropbox by 7:30 AM on
Thursday, September 18, 2008.

Partial preview of the text

Download Introduction to Computing for Engineers - Loops - Assignment 2 | CS 145 and more Assignments Computer Science in PDF only on Docsity!

Computer Science 145.

Introduction to Computing for Engineers

Fall 2008

Programming Assignment 2

“Loops”

Due: 7:30 AM, Thursday, September 18, 2008

This programming assignment requires you to write a program that extensively uses the C++ loop statements. Basically, your program will interactively query the user for integer values and, for each value, output its prime factorization. Recall that a prime number is an integer that cannot be evenly divided by any integer other than itself and 1. Your program will produce prime factorizations according to the following guidelines:  The prime factorizations of 0, 1, and -1 are themselves.  The prime factorization of a negative number is -1 times the prime factorization of the positive version of that number.  The prime factorization of a positive number larger than 1 is the listing of the individual prime numbers which, when multiplied together, produces the positive number in question. A sample interactive session for this assignment is illus- trated at right. Your output is expected to be formatted in an identical fashion to this. Note that your program will require at least three loops:

  1. A "master" loop, which will be repeatedly en- tered as long as the user wishes to perform additional prime factori- zations.
  2. A "yes/no" loop, which will compel the user to type certain characters when asked whether to continue (only 'y', 'Y', 'n', and 'N' are considered acceptable).
  3. A "factorization" loop, which will cycle through the numbers between 2 and half the value being factored, checking (via the modulus operator) whether the value can be factored by the number. Name your project PA2_ Lastname where Lastname is your last name (e.g., John Doe’s project would be PA2_Doe). Don’t forget to include adequate explanatory comments in your code. Zip-compress the entire project folder and place the zipped folder on your Moodle dropbox by 7:30 AM on Thursday, September 18, 2008.