Apr 16, 2013

GWC CS G175 C++ Assignment 10 - Due 4/22/2013

Requirements
Write a program that reads integers until 0 is entered.  Once input terminates, the program should report the total number of even integers entered (excluding the 0), list the even values, their average (using a float value), the total number of odd integers entered, list the odd values and their average (using a float value).
Hints: create an array of integers where you store the even values entered, and another array where you store the odd values.  Also, make sure that your program does not crash when NO even value has been entered (or no odd value)… 
This exercise does not require to create any custom class.
Disclaimer 
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am also a learner like you. Use it at your discretion.
Guidelines
In this assignment, you can use either 2 int Arrays or 2 dynamic int arrays (vector<int>) to store even and odd numbers
You need to:
  • Declare an int to store user input.
  • Declare 2 dynamic int arrays to store even and odd numbers separately.
  • Declare 2 float vars to store averages.

Pseudocode
// Get data
Input an integer
Do While the integer is not equal to zero
     if the integer is equal to zero
          get out of the loop
     else if the integer is an even number
          add the integer to the even dynamic array
     else
          add the integer to the odd dynamic array
     endif
endDo
// Process data
Initialize total to zero
Initialize average to zero
for each element in the even dynamic array
     add the element to total
endfor
if even array size is greater than zero
     compute the even average as total divided by array size
endif
Initialize total to zero
Initialize average to zero
for each element in the odd dynamic array
     add the element to total
endfor
if odd array size is greater than zero
     compute the odd average as total divided by array size
endif
// Output data
Print the size of the even array
for each element in the even array
     Print the element
     if the element is not the last in the array
          Print a comma followed by a space
     endif
endfor
Print the average of the even array
Print the size of the odd array
for each element in the odd array
     Print the element
     if the element is not the last in the array
          Print a comma followed by a space
     endif
endfor
Print the average of the odd array
 Code (updated 4/22/2013 11:30 pm)
https://drive.google.com/folderview?id=0B7j8G8dcaRWxYjBJSkVBd1RUdFE&usp=sharing