All pastes #2067215 Raw Edit

Miscellany

public cpp v1 · immutable
#2067215 ·published 2011-05-23 01:22 UTC
rendered paste body
/*Thomas BiddleM03719432biddletj@mail.uc.eduPart 1 Assignment #6*/#include <fstream>#include <iostream>#include <iomanip>#include <iostream>   using namespace std;#include <vector>int min_position(vector<string>& a, int from, int to) {	int min_pos = from;	int i;	for (i = from + 1; i <= to; i++)		if (a[i].length() < a[min_pos].length() ) min_pos = i;		return min_pos;}void selection_sort(vector<string>& a) {	int next; // The next position to be set to the minimum	for (next = 0; next < a.size() - 1; next++) {		// Find the position of the minimum		int min_pos = min_position(a, next, a.size() - 1);		if (min_pos != next)			swap(a[min_pos], a[next]);	}}int main() {	fstream Bible;	string line;	vector<string> bibleWords;	Bible.open ("bible.txt", fstream::in | fstream::out);	if ( !Bible.is_open() ) {		cout << "File could not be opened!" << endl;		return(1);	}	while(Bible.good()) {		getline (Bible,line);		bibleWords.push_back(line);	}		cout << "Done reading in Bible." << endl;	cout << endl;		Bible.close();		selection_sort(bibleWords);		int numberCount = 1;	for (int k=bibleWords.size()-1; k>bibleWords.size()-11; k--) {		cout << "Longest line number: " << numberCount << endl;		cout << bibleWords[k] << endl;		cout << endl;		numberCount++;	}	numberCount = 1;		for (int j=0; j<10; j++) {		cout << "Shortest line number: " << numberCount << endl;		cout << bibleWords[j] << endl;		cout << endl;		numberCount++;	}		return 0;}