1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
//Project : Assignment 12
//File : Assignment 12.cpp
//Name : Kirby Wood
//Date : 03/27/14
//
// Description : Write a program to simulate managing test scores.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <ctime>
#include <fstream>
using namespace std;
//Function prototypes
void countFunction();
int main()
{
// Initialize and name program variables
int row1, column1, count, grade_sums, value, randomnumbers, indexnum, variable, number;
//Initialize arrays
//initialize starting 2 dimensional array
srand(time(NULL));
string filename = "scores.txt"; //put the filename up front
string filename2 = "scores2.txt"; //second filename after reading, manipulating, and formatting.
string data;
ofstream outFile;
ifstream inFile;
outFile.open(filename.c_str());
if (outFile.fail())
{
cout << "The file was not successfully opened" << endl;
exit(1);
}
//Set the output file stream formats
outFile << setiosflags(ios::fixed)
<< setw(5);
//Send data to the file
//Generate 100 random numbers between 60-100 and save them in a text file
for (row1 = 0; row1 < 10; row1++)
{//start on row 1
for (column1=0; column1 < 10; column1++)
{
randomnumbers = 60 + rand() % (100 + 1 - 60);
outFile << setiosflags(ios::fixed)
<< setw(5) << randomnumbers;
cout << setiosflags(ios::fixed)
<< setw(5) << randomnumbers;
}
outFile << endl;
cout << endl;
}
outFile.close();
cout << endl << "The file " << filename
<< " has been successfully written." << endl << endl;
// Read the text file and do the following:
// Count the number of test scores between 60-69, 70-79, 80-89, 90-100.
// Determine the high, low, and average score of all test scores.
// Display summary results (number of test scores in each range; high, low and average of all scores.)
// Read the text file
inFile.open(filename.c_str());
if (inFile.fail()) //check for successful open
{
cout << "\nThe file was not successfully opened"
<< "\n Please check that the file currently exists."
<< endl;
exit(1);
}
// Read and display the file's contents
while (getline(inFile,data))
cout << data << endl;
//Count the number of test scores between 60-69
return 0;
}
//function declarations and definitions
|