PracticeTest2 CS101_sol

# PracticeTest2 - Practice Quiz CS101 1 Write a C function Process_List to read a list of real numbers a file If any of the numbers are negative skip

This preview shows pages 1–2. Sign up to view the full content.

Practice Quiz CS101 1) Write a C++ function “ Process_List ” to read a list of real numbers a file. If any of the numbers are negative skip them but count them and return the count to the calling program, return the average of the positive numbers. File handler is passed as an argument to the function. (You need to decide pass by value or reference is required) int ct = 0 ; float num , tot = 0 ; counter = 0 ; fin >> num ; while ( !fin.eof() ) { if ( num >= 0 ) { tot += num ; ct ++ ; } else counter ++ ; fin >> num ; } if ( ct > 0 ) avg = tot / ct ; } 2) Write a C++ function “ Process_Num ” to receive a float number as argument, find and report the ceil, floor, and rounded number in the form of long type to the calling program. Ceil means the next higher whole number, floor mean the previous whole number and round means if the first digit is 5 or greater then use ceil, if it is smaller than 5 then use the floor. You may use any system math function or make your own

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/06/2009 for the course CSCI 101L taught by Professor Ghyam during the Spring '07 term at USC.

### Page1 / 3

PracticeTest2 - Practice Quiz CS101 1 Write a C function Process_List to read a list of real numbers a file If any of the numbers are negative skip

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online