USING C++
The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, and program planning and development.
You will read a data file and store all of the input data in a two dimensional array. You will perform calculations on the data and store the results in the 2 dimensional array. You will sort the array and print the results in a report.
Instructions
You will read in the same input file used in assignment 1, partially shown below. This 50 record file consists of a (8-digit numeric) student id, 11 assignment's points(20 points each = 220 total points), mid term points(only 1 mid term = 100 total points), lab exercise points(10 exercises 5 points each = 50 total points), final points(only 1 final = 150 total points), and CodeLab points(10 total points). All of the input data, calculated totals, percents, and grades (and plus or minus) must be stored in only one 2 dimensional array. The specifications for determination of the grades is the same as assignment 1 (or the course syllabus). Your output reports should be "very similar" to the output shown below. The point totals, percents, and grades must be follow the exact calculations. This is the same as assignment 1. You are to produce two output reports, one sorted by student id and one sorted by total points (in decending order). The two output reports must be written to separate files.
The Student Data Input File
75359264 14 20 11 13 9 20 13 20 11 13 9 78 81 8 90774483 39 19 20 20 9 17 19 15 18 13 10 55 72 8 91817488 40 16 14 18 20 18 9 5 15 19 16 58 81 9 96666943 33 9 19 15 18 12 18 9 7 19 19 57 70 0 22397483 31 18 11 15 19 13 20 9 17 20 15 59 64 8 51659342 22 19 12 15 17 15 20 14 14 20 16 79 89 3 01234567 22 18 11 17 20 18 18 5 18 20 18 60 56 8 96498948 22 10 12 12 18 20 13 17 9 18 9 63 67 8 ...
Output Report Sorted by Student Id
Stdnt Id Ex -------- Assignments -------- Tot Mi Fin CL Pts Pct
Gr
-------- -- ----------------------------- --- -- --- -- --- ---
--
01234567 22 18 11 17 20 18 18 5 18 20 18 158 60
56 8 304 76 C
22397483 31 18 11 15 19 13 20 9 17 20 15 148 59
64 8 310 78 C+
42759283 31 19 20 8 10 20 17 2 19 10 12 135 71
66 8 311 78 C+
48357004 22 19 13 15 19 13 12 9 17 19 19 146 79
22 4 273 68 D+
51659342 22 19 12 15 17 15 20 14 14 20 16 150 79
89 3 343 86 B
62939817 38 19 20 18 15 17 20 17 20 17 16 164 51 100 7
360 90 A-
64819064 40 18 9 11 16 20 17 18 16 15 18 149 72 29 10
300 75 C
65389274 35 9 8 8 17 18 19 9 17 11 14 122
72 98 5 332 83 B
65745185 35 19 16 11 11 8 18 5 11 18 13 125 52
53 8 273 68 D+
...
Output Report Sorted by Total Points
(decending)
Stdnt Id Ex -------- Assignments -------- Tot Mi Fin CL Pts Pct
Gr
-------- -- ----------------------------- --- -- --- -- --- ---
--
87654321 39 20 19 20 19 20 19 20 19 20 19 176 79
98 9 401 100 A+
86237404 25 18 20 20 18 20 19 9 19 13 16 163 74
96 8 366 92 A
96937234 27 19 15 13 16 20 16 18 16 11 14 147 78 99 10
361 90 A-
62939817 38 19 20 18 15 17 20 17 20 17 16 164 51 100 7
360 90 A-
92699940 33 17 18 16 20 7 19 15 12 19 18 154 74
87 9 357 89 B+
78086506 31 16 19 18 18 15 18 13 18 17 6 145 78
97 6 357 89 B+
78419400 40 20 19 20 19 19 7 13 13 20 18 161 48
99 6 354 89 B+
87085148 37 17 20 12 16 14 20 14 20 18 8 147 60
98 9 351 88 B+
51659342 22 19 12 15 17 15 20 14 14 20 16 150 79
89 3 343 86 B
...
Program requirements
You must use a 2-dimensional array for all of the data.
Your solution must include at least 5 functions. And ...
At least one function must include a two dimensional array argument.
At least one function must include an argument that consists of one row of a two dimensional array.
At least one function must include an argument that consists of one element of a two dimensional array.
Place the function definitions below main() and function prototypes above main().
All files must be checked for a successful open.
The full input file:
54288660 39 9 11 9 16 11 13 6 20 13 12 19 83 137 8 46595406 30 19 6 17 12 17 18 19 16 14 13 9 57 130 10 72453988 19 19 19 10 18 19 6 18 15 20 15 20 94 135 5 68954389 41 19 17 19 13 18 18 19 19 18 15 13 90 132 10 16543210 29 1 10 11 10 15 10 10 20 8 15 10 50 71 0 68954389 39 19 17 19 13 18 11 11 19 13 15 13 90 132 10 67654321 48 20 19 20 19 20 19 19 20 19 20 19 98 138 9 52613503 41 18 14 20 19 12 16 19 19 18 17 10 90 143 7 89585328 38 15 20 19 19 17 12 18 17 13 20 16 82 63 1 85168415 31 16 18 17 11 19 13 17 16 14 18 7 61 140 10 78517086 32 12 13 19 4 20 8 20 9 20 20 14 87 146 6 92649840 17 13 17 19 16 7 20 20 10 14 16 18 54 88 5 73119641 48 11 17 13 6 20 17 19 11 20 7 16 85 114 8 84887310 43 19 17 14 4 4 14 15 17 16 15 6 56 130 10 93576148 47 16 20 3 14 13 15 14 20 7 11 19 81 149 5 92166763 44 18 16 20 18 14 13 18 15 10 18 17 77 100 7 66058384 45 20 12 13 6 19 20 7 3 19 20 16 72 108 10 98199230 22 18 20 12 14 20 19 20 16 13 13 19 49 150 6 96595989 36 20 16 20 14 14 9 20 17 19 10 19 82 104 8 83258721 42 13 11 13 20 18 12 17 20 11 19 6 33 63 10 44169013 44 19 14 12 18 10 12 15 11 8 19 20 71 130 8 66625489 23 17 6 10 19 2 17 3 12 19 12 13 97 128 10 90398220 19 17 19 19 19 15 20 18 17 18 10 20 97 79 9 76759496 13 6 5 17 16 10 11 18 11 11 16 9 91 140 10 75395766 44 11 16 20 11 11 19 4 19 20 17 15 82 77 6 84476553 22 16 17 11 13 19 12 12 16 13 17 6 71 123 4 56924850 46 18 14 13 20 9 18 17 12 18 7 18 73 141 7 98797886 35 7 18 20 16 15 8 17 18 7 10 15 65 120 10 74798952 40 20 20 20 20 19 5 16 13 15 9 9 85 63 9 90438228 27 10 9 15 15 8 19 17 18 19 20 16 32 138 9 95145592 5 11 19 10 14 17 12 17 13 18 18 14 41 111 4 98375746 38 16 18 16 16 17 8 6 16 18 14 6 88 97 9 73347521 43 13 4 13 19 12 13 15 12 14 20 10 89 121 3 10736268 39 14 18 14 17 14 19 19 15 19 20 14 24 97 10 19519568 44 12 17 9 10 12 15 13 14 2 20 9 87 147 5 70548235 32 19 16 9 17 12 20 12 13 17 19 17 75 140 9 35519284 32 9 18 16 20 17 20 16 19 20 11 9 95 129 10 85308844 42 15 20 20 16 13 16 10 15 16 18 7 98 77 10 94444187 49 11 17 15 12 18 10 19 11 17 16 20 93 114 6 74042799 32 19 6 16 20 15 19 17 12 16 19 14 64 131 6 41239604 33 15 4 15 18 12 19 18 18 10 10 16 78 129 2 68068052 43 15 18 17 18 20 16 20 19 20 16 19 91 62 9 83508364 45 18 13 20 11 8 12 16 16 20 17 19 84 62 10 84279006 43 19 10 19 15 14 19 20 15 8 10 8 47 146 6 97987657 49 16 16 10 10 16 15 12 6 16 7 17 92 56 6 87815174 18 20 17 16 18 4 19 9 16 17 13 7 97 59 10 76543210 29 3 10 10 10 15 10 15 10 8 15 10 50 71 0 76543211 19 0 15 10 10 15 18 11 15 10 15 10 60 90 0 00654321 50 20 18 20 19 20 19 19 20 19 20 19 98 138 9 77698342 28 19 18 10 5 20 19 19 11 16 12 8 78 43 2
program code to copy
main.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
const int SIZE = 8;
const int NumRows = 50;
const int NumCols = 17;
int findsum(int assignments[]);
int findsmallest(int assignments[]);
string lettergrade(int pct);
void printStudent(int data[][NumCols]);
void print1ElementOf2dArray(int element,ofstream &outputFile);
void print1RowOf2dArray(int row[],ofstream &outputFile);
void printPtsDescending(int data[][NumCols]);
void sortArray(int [][NumCols], int col);
void swapRow(int a[], int b[]);
void swap(int& a, int& b);
int getDataFromFile(int data[][NumCols]);
void descendSortArray(int data [][NumCols], int col);
int main ()
{
int data[NumRows+1][NumCols];
getDataFromFile(data);
sortArray(data,0);
printStudent(data);
descendSortArray(data,15);
printPtsDescending(data);
}
void print1RowOf2dArray(int data[],ofstream &outputFile)
{
string grade;
outputFile <<right << setw(8) << setfill('0')<< data[0];
outputFile << " " << setfill(' ');
for (int i=0;i<SIZE;i++)
{
outputFile << right << setw(2) << data[i+1]<< " ";
}
grade = lettergrade(data[16]);
outputFile << right << setw(3)<< data[10]<< " ";
outputFile << right << setw(2)<< data[11]<< " ";
outputFile << right << setw(2)<< data[12]<< " ";
outputFile << right << setw(2)<< data[13]<< " ";
outputFile << right << setw(3)<< data[14]<< " ";
outputFile << right << setw(3)<< data[15]<< " ";
outputFile << right << setw(3)<< data[16]<< " ";
outputFile << left << setw(2)<< grade << " ";
outputFile << endl;
}
void print1ElementOf2dArray(int element,ofstream &outputFile)
{
outputFile << right << setw(8) << setfill('0')<< element;
outputFile << " " << setfill(' ');
}
void printStudent(int data[][NumCols])
{
ofstream outputFile;
outputFile.open("StudentIDs.txt");
outputFile << "Stdnt Id " << "----- Assignments ----- "<< "Tot ";
outputFile << "Mi " << "Ex "<< "Cl "<< "Fin "<< "Pts ";
outputFile << "Pct "<< "Gr"<< endl;
outputFile << "-------- "<< "----------------------- "<< "--- ";
outputFile << "-- "<< "-- "<< "-- "<< "--- "<<"--- "<< "--- ";
outputFile << "-- "<< endl;
string grade;
print1ElementOf2dArray(data[0][0],outputFile);
for (int i=0;i<SIZE;i++)
{
outputFile << right << setw(2) << data[0][i+1]<< " ";
}
grade = lettergrade(data[0][16]);
outputFile << right << setw(3)<< data[0][10]<< " ";
outputFile << right << setw(2)<< data[0][11]<< " ";
outputFile << right << setw(2)<< data[0][12]<< " ";
outputFile << right << setw(2)<< data[0][13]<< " ";
outputFile << right << setw(3)<< data[0][14]<< " ";
outputFile << right << setw(3)<< data[0][15]<< " ";
outputFile << right << setw(3)<< data[0][16]<< " ";
outputFile << left << setw(2)<< grade << " ";
outputFile << endl;
print1RowOf2dArray(data[1],outputFile);
for(int count=2;count<NumRows;count++)
{
outputFile <<right << setw(8) << setfill('0')<< data[count][0];
outputFile << " " << setfill(' ');
for (int i=0;i<SIZE;i++)
{
outputFile << right << setw(2) << data[count][i+1]<< " ";
}
grade = lettergrade(data[count][16]);
outputFile << right << setw(3)<< data[count][10]<< " ";
outputFile << right << setw(2)<< data[count][11]<< " ";
outputFile << right << setw(2)<< data[count][12]<< " ";
outputFile << right << setw(2)<< data[count][13]<< " ";
outputFile << right << setw(3)<< data[count][14]<< " ";
outputFile << right << setw(3)<< data[count][15]<< " ";
outputFile << right << setw(3)<< data[count][16]<< " ";
outputFile << left << setw(2)<< grade << " ";
outputFile << endl;
}
outputFile.close();
}
void printPtsDescending(int data[][NumCols])
{
ofstream outputFile;
outputFile.open("Descending.txt");
outputFile << "Stdnt Id " << "----- Assignments ----- "<< "Tot ";
outputFile << "Mi " << "Ex "<< "Cl "<< "Fin "<< "Pts ";
outputFile << "Pct "<< "Gr"<< endl;
outputFile << "-------- "<< "----------------------- "<< "--- ";
outputFile << "-- "<< "-- "<< "-- "<< "--- "<<"--- "<< "--- ";
outputFile << "-- "<< endl;
string grade;
for(int count=0;count<NumRows;count++)
{
outputFile <<right << setw(8) << setfill('0')<< data[count][0];
outputFile << " " << setfill(' ');
for (int i=0;i<SIZE;i++)
{
outputFile << right << setw(2) << data[count][i+1]<< " ";
}
grade = lettergrade(data[count][16]);
outputFile << right << setw(3)<< data[count][10]<< " ";
outputFile << right << setw(2)<< data[count][11]<< " ";
outputFile << right << setw(2)<< data[count][12]<< " ";
outputFile << right << setw(2)<< data[count][13]<< " ";
outputFile << right << setw(3)<< data[count][14]<< " ";
outputFile << right << setw(3)<< data[count][15]<< " ";
outputFile << right << setw(3)<< data[count][16]<< " ";
outputFile << left << setw(2)<< grade << " ";
outputFile << endl;
}
outputFile.close();
}
int getDataFromFile(int data[][NumCols]){
int studentid, mid, ex, cl, finals;
int assignments[SIZE];
string grade;
int pct;
int pts;
int count = 0;
ifstream fin;
fin.open("StudentData.txt");
if(!fin)
{
cerr << "File not found\n";
exit(1);
}
while (!fin.eof())
{
fin >> studentid;
if (fin.eof() || count == NumRows) break;
data[count][0] = studentid;
for (int i=0; i < SIZE; i++)
{
fin >> assignments[i];
}
for(int i=0; i < SIZE; i++)
{
data[count][i+1] = assignments[i];
}
fin >> mid >> ex >> cl >> finals;
int sum = findsum(assignments);
int smallest= findsmallest(assignments);
int total = sum - smallest;
data[count][10] = total;
data[count][11] = mid;
data[count][12] = ex;
data[count][13] = cl;
data[count][14] = finals;
float pts = total + mid + ex + cl + finals;
pct= (((pts/400) * 100)+.5);
data[count][15] = pts;
data[count][16] = pct;
count++;
}
fin.close();
}
void sortArray(int data [][NumCols], int col)
{
int i, j;
for (i = 0; i < NumRows - 1; i++)
{
for (j = i+1; j < NumRows; j++)
{
if (data[i][col] > data[j][col]) swapRow(data[i],data[j]);
}
}
}
void descendSortArray(int data [][NumCols], int col)
{
int i, j;
for (i = 0; i < NumRows - 1; i++)
{
for (j = i+1; j < NumRows; j++)
{
if (data[i][col] < data[j][col]) swapRow(data[i],data[j]);
}
}
}
void swapRow(int a[], int b[])
{
for (int i = 0; i < NumCols; i++)
{
swap(a[i],b[i]);
}
}
void swap(int& a, int& b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int findsum (int assignments[])
{
int a,sum;
sum = 0;
for( a=0 ;a < 8 ;a++)
{
sum += assignments[a];
}
return sum;
}
int findsmallest(int assignments[])
{
int b, smallest;
smallest = assignments[0];
for (int b=1; b < 7; b++)
{
if (assignments[b] < smallest)
smallest = assignments[b];
}
return smallest;
}
string lettergrade(int pct)
{
string grade;
if (pct > 97)
{
grade = "A+";
}
else if (pct <= 97 && pct >=93)
{
grade = "A";
}
else if (pct >=90 && pct <93)
{
grade = "A-";
}
else if (pct > 87 && pct < 90)
{
grade = "B+";
}
else if (pct <= 87 && pct >=83)
{
grade = "B";
}
else if (pct >=80 && pct <83)
{
grade = "B-";
}
else if (pct > 77 && pct < 80)
{
grade = "C+";
}
else if (pct <= 77 && pct >=73)
{
grade = "C";
}
else if (pct >=70 && pct <73)
{
grade = "C-";
}
else if (pct > 67 && pct < 70)
{
grade = "D+";
}
else if (pct <= 67 && pct >=63)
{
grade = "D";
}
else if (pct >=60 && pct <63)
{
grade = "D-";
}
else
{
grade = "F";
}
return grade;
}
==================================================================
StudentData.txt
94846751 15 12 17 19 20 19 15 13 55 30 9 118
72768560 20 10 3 13 18 8 7 17 27 25 8 56
87438591 19 5 15 11 13 19 8 20 17 54 14 85
66146196 14 8 18 9 10 16 17 19 43 38 7 76
94888427 11 19 20 15 18 20 18 10 73 47 20 98
98018769 17 4 14 20 16 17 20 12 63 52 1 101
1697676 15 17 14 19 18 18 20 16 74 54 7 118
58058213 15 11 17 14 19 15 15 9 71 17 0 76
83739363 10 15 14 6 5 5 18 15 63 32 15 81
63694028 5 12 17 10 19 12 20 20 72 56 16 63
98958598 8 12 19 10 17 18 14 17 33 59 11 71
76562576 14 20 20 17 20 10 6 19 63 68 20 121
80959250 11 6 18 17 20 19 8 15 61 51 16 83
56728145 13 8 2 8 4 17 20 0 41 45 19 122
95546254 16 11 20 4 16 15 18 17 66 52 7 46
58379513 19 18 12 18 16 12 8 16 56 60 10 92
61036923 16 20 19 5 15 16 20 19 49 51 18 72
97149098 18 5 20 5 18 19 20 20 57 56 6 67
54416856 18 10 10 16 15 13 20 10 30 54 10 93
46907790 17 16 8 6 20 11 0 20 48 46 0 75
79265956 17 13 11 19 10 19 8 8 57 41 19 71
79506149 15 13 18 20 18 18 19 20 67 45 10 92
13139720 13 0 16 5 14 2 12 19 54 60 16 90
90757664 20 19 16 15 16 7 12 12 50 58 14 112
59939293 19 16 17 10 17 13 17 17 53 37 10 80
90581726 11 14 19 13 18 15 13 20 41 32 9 90
50598453 19 16 20 19 15 4 12 16 38 41 15 112
74559512 11 19 19 14 20 9 6 13 51 48 17 86
57249968 20 11 20 17 16 20 14 12 49 23 16 113
90749960 9 14 11 20 9 6 13 18 50 48 19 78
93255554 15 20 16 19 20 18 9 18 52 58 19 103
75075020 17 19 20 20 9 17 8 19 17 53 19 102
81627101 6 19 20 9 9 9 17 20 37 39 10 81
56458631 9 14 20 16 19 12 17 7 71 31 14 118
54197920 18 6 20 18 19 9 20 17 66 60 20 69
55177372 20 5 5 17 19 18 10 14 66 54 7 123
54674884 16 15 7 19 17 19 10 20 32 37 9 97
64799727 16 12 18 18 15 14 3 8 75 42 9 105
96489515 11 16 15 9 16 14 16 19 21 47 6 122
84617126 16 15 13 20 19 20 18 18 54 28 13 113
97306732 11 6 7 4 7 14 9 11 41 27 10 104
95587356 20 10 16 14 7 10 17 14 72 47 20 120
64034032 15 20 12 20 10 12 20 17 35 48 15 41
83083660 7 12 13 14 17 9 13 14 52 15 0 95
98118954 17 17 10 20 8 12 15 12 75 54 4 63
52268117 9 5 2 8 16 0 18 0 56 33 0 50
95768917 18 8 13 5 19 17 12 11 56 26 3 118
98317182 4 6 18 16 7 12 15 8 31 24 15 109
6798839 17 10 13 17 18 16 19 20 49 35 10 87
96109943 11 17 15 20 11 20 17 8 23 27 20 105
sample output
Get Answers For Free
Most questions answered within 1 hours.