Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <limits>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- int testScoreArray[100];
- void selectSort(int testScoreArray[], int n);
- void fileOutput(int testScoreArray[]);
- int main()
- {
- int n = 100;
- ifstream infile;
- infile.open("testscoresarrayhomework.txt");
- for (int i = 0; i < 100; i++) {
- infile >> testScoreArray[i];
- }
- selectSort(testScoreArray, n);
- fileOutput(testScoreArray);
- infile.close();
- return 0;
- }
- void selectSort(int testScoreArray[], int n)
- {
- int pos_max, temp;
- for (int i = 0; i < n - 1; i++) {
- pos_max = i;
- for (int j = i + 1; j < n; j++) {
- if (testScoreArray[j] > testScoreArray[pos_max])
- pos_max = j;
- }
- if (pos_max != i) {
- temp = testScoreArray[i];
- testScoreArray[i] = testScoreArray[pos_max];
- testScoreArray[pos_max] = temp;
- }
- }
- };
- void fileOutput(int testScoreArray[])
- {
- ofstream outfile;
- int gradeEvent = 1;
- int previousGrade = 0;
- outfile.open("testscoresoutput.txt");
- outfile << "Test Score Breakdown: ";
- outfile << endl
- << "Score / Occurance";
- for (int i = 0; i < 100; i++) {
- if (previousGrade == testScoreArray[i]){
- gradeEvent++;
- }
- if (previousGrade && previousGrade != testScoreArray[i]) {
- outfile << '\n' << previousGrade << " / " << gradeEvent;
- gradeEvent=1;
- }
- previousGrade = testScoreArray[i];
- }
- outfile << '\n' << previousGrade << " / " << gradeEvent;
- outfile.close();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement