Solution_to_the_coding_part[1]

Solution_to_the_coding_part[1] - 90 50 60 80 90 90...

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

View Full Document Right Arrow Icon
Solution to the first coding part #include <iostream> #include <fstream> using namespace std ; int main () { ifstream input; int x, output[ 10 ]; input. open ( "input.txt" ); for ( int i= 0 ;i< 10 ;i++) output[i]= 0 ; for ( int i= 0 ;i< 10 ;i++){ input >> x; output[x]++; } for ( int i= 0 ; i< 10 ; i++){ cout << "Appearances of " << i << ":" << output[i] << endl; } return 0 ; } Solution to the second coding part //The solution will be the same for 150 students, just replace 10 with 150. Also, no main is needed it is only there so that you can run the program for yourselves. #include <iostream> #include <fstream> using namespace std ; void function( int x[]); int main () { int x[ 10 ] = { 70 , 90 , 100 , 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: , 90 , 50 , 60 , 80 , 90 , 90 }; function (x); return ; } void function( int x){ ofstream file; file. open ( "report.txt" ); float avg= ; int count= ; int array[ 101 ]; for ( int i= ;i< 101 ;i++) array[i]= ; for ( int i= ;i< 10 ;i++){ avg+=x[i]; if (x[i]< 60 ) count++; array[x[i]]++; } int max=array[ ]; int k= ; for ( int i= 1 ; i< 101 ;i++){ if (array[i]>max){ max=array[i]; k=i; }} file << "The average is: " << avg/ 10 << endl; file << "The number of failed students is: " << count << endl; file << "The value that appears the most: " << k << endl; }...
View Full Document

This note was uploaded on 09/27/2011 for the course CGS 2421 taught by Professor Onal during the Spring '09 term at University of Florida.

Page1 / 2

Solution_to_the_coding_part[1] - 90 50 60 80 90 90...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online