Structured Programming in C++
Prof. Gregory Safko

Camden County College, Cherry Hill Campus

Project 1

 

Assigned: February 20, 2004

Due: March 5, 2004

 


 

Write a program (Project1.cpp) that will ask for three numbers (of type double)

 

Your code will run as follows:

 

Enter three real numbers

Number 1: 24

Number 2: 12

Number 3: 18

 

The results are:

Number 1: An Integer

Number 2: An Integer

Number 3: An Integer

 

Smallest: 12.0

Middle  : 18.0

Largest : 24.0

 

The GCD (Greatest Common Divisor) is : 6

The LCM (Least Common Multiple) is   : 72

 

 

An example of another run:

 

Enter three real numbers

Number 1: 3.2

Number 2: 1.1

Number 3: -18

 

The results are:

Number 1: Not An Integer

Number 2: Not An Integer

Number 3: An Integer

 

Smallest: -18.0

Middle  : 1.1

Largest : 3.2

 

The GCD (Greatest Common Divisor) is : Undefined

The LCM (Least Common Multiple) is   : Undefined

 

An example of another run:

 

Enter three real numbers

Number 1: 7

Number 2: 5.0

Number 3: 6

 

The results are:

Number 1: An Integer

Number 2: An Integer

Number 3: An Integer

 

Smallest: 5.0

Middle  : 6.0

Largest : 7.0

 

The GCD (Greatest Common Divisor) is : 1

The LCM (Least Common Multiple) is   : 210

 

An example of another run (involving a negative integer):

 

Enter three real numbers

Number 1: -2

Number 2: 9

Number 3: 6

 

The results are:

Number 1: An Integer

Number 2: An Integer

Number 3: An Integer

 

Smallest: -2.0

Middle  : 6.0

Largest : 9.0

 

The GCD (Greatest Common Divisor) is : 1

The LCM (Least Common Multiple) is   : 18

 

Some hints and rules:

 

  1. You must write your own findSmall, findMiddle, findLargest, findGCD, and findLCM functions.
  2. There are many algorithms for finding GCD and LCM on the Internet. If you use one of them, please note in your comments your source. UNCREDITED CODE DOWNLOADED FROM THE INTERNET WILL RECEIVE A ZERO.
  3. Recall that the Greatest Common Divisor is the largest number that can divided into 2 numbers. If your numbers are 75 and 100, you can divide 5 evenly into them, but the largest number you can divide into them is 25 (75 % 25 == 0 and 100 % 25 == 0)
  4. Recall that the Least Common Multiple is the smallest number that two numbers are a multiple of. An easy way to find a common multiple is to multiply the numbers together. So, a common multiple of 75 and 100 is 7500 (7500 % 75 == 0 and 7500 % 100 == 0). However, there is a smaller number, which is 300 (300 %75 == 0 and 300 % 100 == 0). A quick way to find the union of factors of the two numbers, and multiply them together. Hence, if the factors of 75 are 3 * 5 * 5, and the factors of 100 are 2 * 2 * 5 * 5, then find the common unique union of them (2,2,3,5,5), and multiply them together. Again, if this algorithm is too difficult to implement, the Internet may have resources for you.
  5. You cannot find LCMs and GCDs of numbers with decimals (i.e. doubles). Just say that it is undefined. You can find LCMs and GCDs of negative integers by first making them positive, (using abs( )), and then testing them.
  6. Code will be appropriately documented, formatted, and indented.
  7. Deduct 15 points for single submissions (i.e. submission without teammates)