solutions26 - CSCI-1100 Computer Science I Rensselaer...

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

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 26 -- Solutions Part 1 // Maximum list size const int MAXSIZE = 1000; #include <iostream> #include <fstream> void selection(int list[ ], int len); int median(int list[ ], int len); int main () //PURPOSE: find median of a list of ints //PRECONDITIONS: file list.txt in project folder //POSTCONDITIONS: displays median of list { int list[MAXSIZE]; // list of numbers ifstream infile; // source file for list int len; // length of list // Get list from file infile.open("list.txt"); len = 0; infile >> list[len]; while (!infile.eof()) { len = len + 1; infile >> list[len]; } // Sort the list selection(list, len); // Compute and display the mode cout << "The median of the list is: " << median(list, len) << endl; return 0; } void selection(int list[ ], int length) //PURPOSE: sort list into ascending order using selection sort //PRECONDITIONS: 0 <= length, length is length of list //POSTCONDITIONS: reordres list into ascending order
Background image of page 1

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

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

Page1 / 2

solutions26 - CSCI-1100 Computer Science I Rensselaer...

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