All pastes #551523 Raw Edit

lol

public cpp v1 · immutable
·published 2007-06-08 20:47 UTC
rendered paste body
#include <iostream>#include <fstream>#include <string>using namespace std;typedef char Str[60];void Print (Str names[], int grades[], int count){	for (int i = 0; i < count; i++ )		cout << names[i] << '\t' << grades[i] << endl;}void BubbleSortAlph (Str names[], int grades[], int count){	Str tmp;	int itmp;	for (int i = 0; i < count-1; i++)	for (int j = 0; j < count-1; j++) 		if(strcmp(names[j+1], names[j]) < 0 )		{			strcpy(tmp, names[j+1]);			itmp = grades[j+1];			strcpy(names[j+1], names[j]);			grades[j+1] = grades[j];			strcpy(names[j], tmp);			grades[j] = itmp;		}}	void BubbleSortGrades (Str names[], int grades[], int count){	Str tmp;	int itmp;	for (int i = 0; i < count-1; i++)	for (int j = 0; j < count-1; j++) 		if (strcmp(names[j+1] ,names[j]) <0 )		{			strcpy(tmp, names[j+1]);			itmp = grades[j+1];			strcpy(names[j+1], names[j]);			grades[j+1] = grades[j];			strcpy(names[j], tmp);			grades[j] = itmp;		}}	void CountGrades (int grades[], int count){	int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;	for ( int i = 0; i < count; i++)	{		if ( grades[i] >= 90 ) gradeA++;		else if ( grades[i] >= 80 ) gradeB++;		else if ( grades[i] >= 70 ) gradeC++;		else if ( grades[i] >= 60 ) gradeD++;		else gradeF++;	}	if (gradeA > 0) 	{		cout << " There was " << gradeA << "A";		if (gradeA > 1) cout << "'s" << endl;	}	if (gradeB > 0)	{		cout << " There was " << gradeB << "B";		if (gradeB > 1) cout << "'s" << endl;	}	if (gradeC > 0)	{		cout << " There was " << gradeC << "C";		if (gradeC > 1) cout << "'s" << endl;	}	if (gradeD > 0)	{		cout << " There was " << gradeD << "D";		if (gradeD > 1) cout << "'s" << endl;	}	if (gradeF > 0)	{		cout << " There was " << gradeF << "F";		if (gradeF > 1) cout << "'s" << endl;	}}void High (int grades[], int count){	int highest = grades[0];	for (int i = 0; i < count-1; i++)	{		if (grades[i] > highest)			highest = grades[i];	}	cout << " The highest grade was " << highest << endl;}void Low (int grades[], int count){	int lowest = grades[0];	for (int i = 0; i < count-1; i++)	{		if (grades[i] < lowest)			lowest = grades[i];	}	cout << " The lowest grade was " << lowest << endl;}void PrintSummary(int grades[], int count){	cout << endl;	CountGrades(grades, count);	High(grades, count);	Low(grades, count);}int main(void){	Str names [20];	int grades[20], i = 0;	char fn[60];	cout << " Enter a file name ";	cin >> fn;	ifstream infile(fn);	if (infile)	{		int count = 0;		for ( ; infile >> names[i] >> grades[i]; count++ )		BubbleSortAlph(names, grades, count);		Print(names, grades, count);		PrintSummary(grades, count);		BubbleSortGrades(names, grades, count);		Print (names, grades, count);		PrintSummary(grades, count);		infile.close();	}	else cout << " Invalid File " << endl;	return 0;}