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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
#include <iostream>
#include <iomanip>
using namespace std;
// Making a data type structure of "person"
struct person{
char name[25];
char number[13];
float salary;
};
// Prototyping Procedures
void menu();
void compReport(person temp[], int size);
void condReport(person temp[], int size);
void inputData(person temp[], int &size);
void nameSort(person temp[], int &size);
void salarySort(person temp[], int &size);
void search(person temp[], int &size);
int main()
{
char selection;
int size = 0;
person thePeeps[10];
do{
menu(); // Displaying the menu.
cout << "Please make a selection "<< endl;//Allowing the user to select the option from the menu.
cin >> selection;
cin.ignore();
switch (selection)
{
case '1':// If selection is 1 the program will allow the user to input more data.
inputData(thePeeps, size);
break;
case '2':// if selection is 2 the program will print out a report of the people stored.
compReport(thePeeps, size);
break;
case '3':// If selection is 3 the program will print a conditional report.
condReport(thePeeps, size);
break;
case '4':// If selection is 4 the program will sort the data by name using a bubble sort.
nameSort(thePeeps, size);
break;
case '5':
salarySort(thePeeps, size);
break;
case '6':
search(thePeeps, size);
break;
case '7':// If selection is 7 the loop will break.
break;
default: cout << "Invalid Entry" << endl;// The menu will come back up and show this message if the user inputs anything else but a number between 1 and 7.
}
}while(selection != '7');// If the selection is anything but 7, the loop will continue to run.
return 0;
}
void menu()
{
cout << "1) Add new user info " << endl; // Input
cout << "2) Print complete report " << endl; // All input
cout << "3) Print conditional report " << endl; // "Greater than"
cout << "4) Sort the data by name " << endl; // With a bubble sort
cout << "5) Sort the data by Salary " << endl; // With selection sort
cout << "6) Search for name " << endl;
cout << "7) Quit " << endl;
}
void compReport(person temp[], int size)
{
cout << setiosflags(ios_base::left) << setw(20) << "Name " << setw(10) << "Phone Number "
<< resetiosflags(ios_base::left) << setw(12) << "Salary " << endl;
for(int x = 0; x < size; x++)
{
cout << setiosflags(ios_base::left) << setw(20) << temp[x].name << setw(15) << temp[x].number
<< resetiosflags(ios_base::left) << setw(10) << setprecision(2) << setiosflags(ios_base::fixed) << temp[x].salary << endl;
}
}
void condReport(person temp[], int size)
{
float moneyChoice;
cout << "Print user with a greater salary than: ";
cin >> moneyChoice;
cout << setiosflags(ios_base::left) << setw(20) << "Name " << setw(10) << "Phone Number "
<< resetiosflags(ios_base::left) << setw(12) << "Salary " << endl;
for (int x = 0; x < size; x++)
{
if(moneyChoice < temp[x].salary)
{
cout << setiosflags(ios_base::left) << setw(20) << temp[x].name << setw(15) << temp[x].number
<< resetiosflags(ios_base::left) << setw(10) << setprecision(2) << setiosflags(ios_base::fixed) << temp[x].salary << endl;
}
}
}
void inputData(person temp[], int &size)
{
cout << "Enter name: ";
cin.getline(temp[size].name, 25);
cout << "Enter Phone Number: ";
cin.getline(temp[size].number, 13);
cout << "Enter Salary: ";
cin >> temp[size].salary;
size++;
}
void nameSort(person temp[], int &size)
{
bool swap = true;
for(int m = 1; m < size; m++)
{
swap = false;
for(int n = 0; n < size-m; n++)
{
int result = strcmp (temp[n].name, temp[n+1].name);
if (result > 0)
{
person swindle = temp[n];
temp[n] = temp[n+1];
temp[n+1] = swindle;
swap = true;
}
else if (result == 0)
{
swap = false;
}
else
{
swap = false;
}
}
}
}
void salarySort(person temp[], int &size)
{
int minIndex;
float minValue;
person quick;
for (int start = 0; start < (size-1); start++)
{
minIndex = start;
minValue = temp[start].salary;
quick = temp[start];
for (int index = start+1; index < size; index++)
{
if (temp[index].salary < minValue)
{
quick = temp[index]; // New value copied into quick
minIndex = index;
}
}
temp[minIndex] = temp[start]; // Copying the value back
temp[start] = quick;
}
}
void search(person temp[], int &size)
{
char searchname;
cout << "Please enter the name to seach for " << endl;
cin >> searchname;
for(int y = 0; y < size; y++)
{
for(int x = 0; x < size - y; x++)
{
int result = strcmp(temp[x].name, searchname);
if (result = 0)
{
cout << setiosflags(ios_base::left) << setw(20) << temp[x].name << setw(15) << temp[x].number
<< resetiosflags(ios_base::left) << setw(10) << setprecision(2) << setiosflags(ios_base::fixed) << temp[x].salary << endl;
}
else
{
cout << "Sorry, no student exists with such name" << endl;
}
}
}
}
/*cout << "Please enter a name to search for: " << endl;
cin >> nameSearch;
for(int x = 0; x < size; x++)
{
if (strcmp(temp[x].name, nameSearch) == 0)
{
cout << setiosflags(ios_base::left) << setw(20) << temp[x].name << setw(15) << temp[x].number
<< resetiosflags(ios_base::left) << setw(10) << setprecision(2) << setiosflags(ios_base::fixed) << temp[x].salary << endl;
else
cout << "Name Not Found " << endl;
}
}
}*/
|