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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
struct Student
{
string lastName;
string firstName;
double exam1;
double exam2;
double exam3;
Student(string ln, string fn, double s1, double s2, double s3)
{
lastName = ln;
firstName = fn;
exam1 = s1;
exam2 = s2;
exam3 = s3;
}
};
void newRecord(vector<string> &, vector<string> &, vector<string> &, vector<string> &, vector<string> &);
void displayRecord(vector<string> , vector<string> , vector<string> , vector<string> , vector<string>);
void deleteRecord(vector<string> &, vector<string> &, vector<string> &, vector<string> &, vector<string> &);
void scoreAverage(vector<string> &, vector<string> &, vector<string> &, vector<string> &, vector<string> &);
void saveAndExit(vector<string> , vector<string> , vector<string>, vector<string>, vector<string>);
int main()
{
vector<string> firstName, lastName, score1, score2, score3;
int option = 0;
do
{
cout << "----------Menu Options--------------" << endl;
cout << " 1. Enter students name and scores " << endl;
cout << " 2. Display students information " << endl;
cout << " 3. Remove a students information " << endl;
cout << " 4. Display Exam Averages " << endl;
cout << " 5. Save and Exit " << endl;
cout << " Enter your choice 1, 2, 3, 4 ,5 " << endl;
cin >> option;
cout << endl << endl;
switch(option)
{
case 1:
newRecord(firstName, lastName, score1, score2, score3);
break;
case 2:
displayRecord(firstName, lastName, score1, score2, score3);
break;
case 3:
deleteRecord(firstName, lastName, score1, score2, score3);
break;
case 4:
scoreAverage(firstName, lastName, score1, score2, score3);
break;
case 5:
saveAndExit(firstName, lastName, score1, score2, score3);
return 0;
break;
default:
cout << "Please enter 1, 2, 3, 4, or 5" << endl << endl;
break;
}
}while(option != 4);
}
void newRecord(vector<string> &fName, vector<string> &lName, vector<string> &score1, vector<string> &score2, vector<string> &score3)
{
string fn, ln, s1, s2, s3;
char ans = 'n';
do
{
cout << " Enter First Name: ";
cin >> fn;
cout << " Enter Last Name: ";
cin >> ln;
cout << " Enter Score 1: ";
cin >> s1;
cout << " Enter Score 2: ";
cin >> s2;
cout << " Enter Score 3: ";
cin >> s3;
fName.push_back(fn);
lName.push_back(ln);
score1.push_back(s1);
score2.push_back(s2);
score3.push_back(s3);
cout << " Would you like to enter another record? Y or N : ";
cin >> ans;
ans = tolower(ans);
cout << endl << endl;
}while(ans == 'y');
}
void displayRecord(vector<string> fName, vector<string> lName, vector<string> score1, vector<string> score2, vector<string> score3)
{
cout << " There are " << fName.size() << " at this time. " << endl << endl;
if(fName.size() > 0)
{
cout << " RecNum" << '\t' << "FName" << '\t' << "LName" << '\t' << "Score1" << '\t' << "Score2" << '\t' << "Score3" << '\t' << endl;
for(int i = 0; i < fName.size(); i++)
{
cout << " " << (i + 1) << "." << '\t' << fName[i] << '\t' << lName[i] << '\t' << score1[i] << '\t' << score2[i] << '\t' << score3[i] << endl;
}
}
cout << endl;
}
void deleteRecord(vector<string> &fName, vector<string> &lName, vector<string> &score1, vector<string> &score2, vector<string> &score3)
{
int index = 0;
cout << "There are " << fName.size() << " records at this time. " ;
if(fName.size() == 0)
{
cout << " No records can be removed. " << endl << endl;
return;
}
else
{
cout << "The names are: " << endl << endl;
for(int i = 0; i < fName.size(); i++)
{
cout << i + 1 << '\t' << fName[i] << " " << lName[i] << endl;
}
cout << endl << " Enter the number of the file that you wish to delete: 1 through " << fName.size();
cin >> index;
if(index <= 0 || index > fName.size())
{
cout << " The number you entered is not within the proper range." << endl;
return;
}
index = index - 1;
for(int i = index; i < fName.size() - 1; i++)
{
fName[i] = fName[i+1];
lName[i] = lName[i+1];
score1[i] = score1[i+1];
score2[i] = score2[i+1];
score3[i] = score3[i+1];
}
fName.pop_back();
lName.pop_back();
score1.pop_back();
score2.pop_back();
score3.pop_back();
}
cout << " There are now " << fName.size() << " records." << endl;
}
void scoreAverage(vector<string> &fName, vector<string> &lName, vector<string> &score1, vector<string> &score2, vector<string> &score3)
{
double total;
double average;
average = total / 3;
}
void saveAndExit(vector<string> fName, vector<string> lName, vector<string> score1, vector<string> score2, vector<string> score3)
{
ofstream outFile;
outFile.open("studentScores.txt");
if(outFile.is_open())
{
for(int i = 0; i < fName.size(); i++)
{
outFile << fName[i] << '\t' << lName[i] << '\t' << score1[i] << '\t' << score2[i] << '\t'<< score3[i] << endl;
}
cout << fName.size() << " The records were saved to studentScores.txt" << endl << endl;
}
}
|