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 198 199
|
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
class schoolSystem
{
public:
void setData(string, int, double, string, string);
void getData(string&, int&, double&, string&, string&) const;
void printData() const;
schoolSystem(); //default
schoolSystem(string, int, double, string, string); //5 parameters
schoolSystem(int); //1 parameter
private:
string name;
int id;
double gpa;
string major;
string email;
};
void showMenu();
int main()
{
schoolSystem variable;
string newName;
int newId;
double newGpa;
string newMajor;
string newEmail;
char answer;
cout << "testing 5 parameter constructor" << endl;
variable.setData("joe smith", 00123, 3.4, "Comp Sci", "joe@myhouse.com");
variable.printData();
system("pause");
cout << endl <<"testing 1 parameter constructor" << endl;
variable.setData(newName, 2223334, newGpa, newMajor, newEmail);
variable.printData();
system("pause");
cout << endl << "testing default constructor and editor" << endl;
variable.setData(newName, newId, newGpa, newMajor, newEmail);
variable.printData();
system("pause");
system("CLS");
showMenu();
cin >> answer;
while (answer != 'r')
{
switch(answer)
{
case 'n':
cout << "new name?" << endl;
cin >> newName;
break;
case 'i':
cout << "new id?" << endl;
cin >> newId;
break;
case 'm':
cout << "new major?" << endl << setw(3) << " " << "approved majors" << endl << "CS" << endl << "math" << endl << "mech eng" << endl;
cin >> newMajor;
break;
case 'e':
cout << "new email?" << endl;
cin >> newEmail;
break;
case 'g':
cout << "new gpa?" << endl;
cin >> newGpa;
break;
default:
cout << "Invalid Selection." << endl;
}//End Switch
system("CLS");
showMenu();
cin >> answer;
}
//Set the time of system using the value of the variables newName, newId, newGpa, newMajor, and newEmail
variable.setData(newName, newId, newGpa, newMajor, newEmail);
variable.printData(); //print the time of myClock
cout << endl;
cout << "Enter the name, id, gpa, major, email: ";
cin >> newName >> newId >> newGpa >> newMajor >> newEmail;
cout << endl;
system("pause");
return 0;
}
void showMenu()
{
cout << fixed << showpoint;
cout << left;
cout << endl << endl << endl << setw(3) << " " << "Edit Student Menu" << endl << endl;
cout << setw(3) << "n" << "change name" << endl;
cout << setw(3) << "i" << "change id" << endl;
cout << setw(3) << "m" << "change major" << endl;
cout << setw(3) << "e" << "change email" << endl;
cout << setw(3) << "g" << "enter new gpa" << endl;
cout << setw(3) << "r" << "return to main menu" << endl << endl;
cout << "enter choice: -";
}//End showMenu
schoolSystem::schoolSystem(string newName, int newId, double newGpa, string newMajor, string newEmail)
{
if (newName!= "")
name = newName;
else
name = "none";
if (newId > 1 && newId < 99999999)
id = newId;
else
id = 0;
if (newGpa >= 0 || newGpa <= 4)
gpa = newGpa;
else
gpa = 0;
if (newMajor != "")
major = newMajor;
else
major = "none";
if (newEmail != "")
email = newEmail;
else
email = "none@";
}
schoolSystem::schoolSystem()
{
name = "none";
id = 0;
gpa = 0;
major = "none";
email = "none@";
}
schoolSystem::schoolSystem(int)
{
id = 0;
}
void schoolSystem::setData(string newName, int newId, double newGpa, string newMajor, string newEmail)
{
if (newName!= "")
name = newName;
else
name = "none";
if (newId > 1 && newId < 99999999)
id = newId;
else
id = 0;
if (newGpa > 0 || newGpa < 4)
gpa = newGpa;
else
gpa = 0;
if (newMajor != "")
major = newMajor;
else
major = "none";
if (newEmail != "")
email = newEmail;
else
email = "none@";
}
void schoolSystem::getData(string& newName, int& newId, double& newGpa, string& newMajor, string& newEmail) const
{
newName = name;
newId = id;
newGpa = gpa;
newMajor = major;
newEmail = email;
}
void schoolSystem::printData() const
{
cout << name << " " << "#" << id << endl << setprecision(1) << gpa << " as a " << major << endl << "email: " << email << endl;
}
|