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 107 108 109 110 111 112 113
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int display(int number, char itemDescription[], int points[], int score[],
int average, char letter, char symbol);
/**********************************************************************
* Reads the file.
***********************************************************************/
int readFile(int number, char itemDescription[], int points[], int score[])
{
ifstream input;
input.open("grades.txt");
input >> number;
for (int count = 0; count < number; count++)
input >> itemDescription[count] >> points[count] >> score[count];
//display(number, itemDescription, points, score);
input.close();
}
/**********************************************************************
* Creates a new file.
***********************************************************************/
int newFile(int number, char itemDescription[], int points[], int score[])
{
cout << "How many records are in the file? \n";
cin >> number;
cout << "Description for #1: \n";
cin >> itemDescription[0];
cout << "Description for #2: \n";
cin >> itemDescription[1];
cout << "Description for #3: \n";
cin >> itemDescription[2];
cout << "Description for #4: \n";
cin >> itemDescription[3];
ifstream input;
for (int count = 0; count < number; count++)
input >> itemDescription[count] >> points[count] >> score[count];
display(number, itemDescription, points, score);
return 0;
}
/**********************************************************************
* Write the file to grades.txt.
***********************************************************************/
int writeFile(int number, char itemDescription[], int points[], int score[])
{
ofstream output;
output.open("grades.txt");
output << number;
for (int count = 0; count < number; count++)
output << itemDescription[count] << points[count] << score[count] << endl;
output.close();
}
/**********************************************************************
* Displays the table.
***********************************************************************/
int display(int number, char itemDescription[], int points[], int score[])
{
cout << "Number" << setw(16) << "Name" << " Points" << " Score" << endl;
cout << "====== =============== ====== =====\n";
writeFile(number, itemDescription, points, score);
readFile(number, itemDescription, points, score);
for (int count = 0; count < number; count++)
{
cout << number; //I think this is where I'm going
cout << itemDescription[count]; //wrong, I don't know how to make
cout << points[count]; //it display my table.
cout << score[count];
}
cout << "====== =============== ====== =====\n";
cout << setw(12) << "Total" << setw(22) << "--" << endl;
return 0;
}
/**********************************************************************
* Add text here to describe what the function "main" does. Also don't forget
* to fill this out with meaningful text or YOU WILL LOOSE POINTS.
***********************************************************************/
int main(int file, int records, int d1, int d2, int d3, int d4)
{
int number;
char itemDescription[50];
int points[100];
int score[100];
int option;
readFile(number, itemDescription, points, score);
newFile(number, itemDescription, points, score);
writeFile(number, itemDescription, points, score);
return 0;
}
|