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
|
//main().cpp
#include<iostream>
#include<fstream>
#include<limits>
#include<vector>
#include<string>
#include"students.h"
using namespace std;
int main() // Where Program Begins
{
vector<Students*> database; //Vector for database
bool quit=false;
ofstream outFile("out.txt"); //saving database in out.txt
int input,select1,j=0,age,exp,grade,grade2,quiz1,quiz2,hw1,hw2,as1,as2,as3,as4,as5,project; //defining all int variables
string firstName;string lastName;string major; string search; string id; //defining all string variables
while(!quit) //Prints the database before ever single iteration of the program
{
cout<<"Database size:"<<database.size()<<endl;
cout<<"Database contains:\n"<<endl;
for(int k=0;k<database.size();k++)
{
database[k]->printStats();
cout<<endl<<endl;
}
cout<<"\n1. Add a Student\n2. Delete a Student\n3. Save The Database\n4. Display Specific Data \n5. Exit The Database\n";
cin>>select1;
cout<<endl;
switch(select1)
{
case 1: // I broke this case into two cases for unknown grade and overall grade
cout<<"\n1. Do you know his or her overall grade? \n2. Do you not know his or her overall grade?" << endl;
cin>>input;
cin.ignore();
switch(input)
{
case 1: // Overall grade
cout<<"\nEnter first name:";
getline(cin,firstName);
cout<<"\nEnter last name:";
getline(cin,lastName);
cout<<"\nEnter Student ID:";
cin>>id;
cout<<"\nEnter Age:";
cin>>age;
cout<<"\nEnter Major:";
cin>>major;
cout<<"\nEnter Grade:";
cin>>grade;
// Inserts the database entry generated directly into the program via ID location.
if(database.size() < 1)
{
database.push_back(new PM1(firstName,lastName,id,age,major,grade));
cout << "\nif runs";
}
else if (database.size() == 1)
{
int i = 0;
if(database[i] -> getId() < id)
{
database.insert(database.begin() + 1, new PM1(firstName,lastName,id,age,major,grade));
cout << "\nelse if if == runs";
}
else
{
database.insert(database.begin(), new PM1(firstName,lastName,id,age,major,grade));
cout << "\nelse if else == runs";
}
}
else if (database.size() > 1)
{
for(int i = 0; i < database.size(); i++)
{
if(database[i] -> getId() < id && database[i + 1] -> getId() >= id)
{
database.insert(database.begin() + i + 1, new PM1(firstName, lastName, id, age, major, grade));
cout << "\nelse if if runs";
}
else
{
database.push_back(new PM1(firstName,lastName,id,age,major,grade));
cout << "\nelse if else runs";
}
break;
}
}
else
{
cout << "\nDidn't work!";
}
break;
case 2: // Case 2 is not completely completed yet, it works but I have not yet included the same insertion method as Case 1
cout<<"\nEnter first name:";
getline(cin,firstName);
cout<<"\nEnter last name:";
getline(cin,lastName);
cout<<"\nEnter Student ID:";
cin>>id;
cout<<"\nEnter Age:";
cin>>age;
cout<<"\nEnter Major:";
cin>>major;
cout<<"Enter Quiz One value:";
cin>>quiz1;
cout<<"Enter Quiz Two value:";
cin>>quiz2;
cout<<"Enter Homework One Value:";
cin>>hw1;
cout<<"Enter Homework Two Value:";
cin>>hw2;
cout<<"Enter Project Grade Value:";
cin>>project;
cout<<"Enter Assignment One Value:";
cin>>as1;
cout<<"Enter Assignment Two Value:";
cin>>as2;
cout<<"Enter Assignment Three Value:";
cin>>as3;
cout<<"Enter Assignment Four Value:";
cin>>as4;
cout<<"Enter Assignment Five Value:";
cin>>as5;
database.push_back(new Grade(firstName,lastName,id,age,major,quiz1,quiz2,hw1,hw2,project,as1,as2,as3,as4,as5));
break;
}
break;
case 2: // Deleting entry rule
cout<<"Enter Student ID to be deleted:";
cin.ignore(numeric_limits<streamsize>::max(),'\n');
getline(cin,search);
for(int l=0;l<database.size();l++)
{
if(database[l]->getId()==search)
{
database.erase(database.begin()+l);
break;
}
}
break;
case 3: // Saving to out.txt
for(int i=0;i<database.size();i++)
{
database[i]->save(outFile);
cout<<endl;
}
break;
case 4: // Locates database entry via searching ID
cout<<"Enter Student ID To Display Data:";
cin.ignore(numeric_limits<streamsize>::max(),'\n');
getline(cin,search);
for(int l = 0; l < database.size(); l++)
{
if(database[l] -> getId() == search)
{
database[l] -> printStats();
cout << endl;
break;
}
}
break;
case 5: //Exits program
cout<<"\nExiting............";
quit=true;
break;
}
}
}
|