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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*Variables used:
noOfRecords ------------- Number of records
row --------------------- Array Row
selection --------------- User's selection
first ------------------- First name
last -------------------- Last Name
id ---------------------- Target's ID (4 digit number)
dob --------------------- Target's Date of birth
address ----------------- Target's Address
city -------------------- Target's City
state ------------------- Target's State
zip --------------------- Target's Zip code
*/
#include<iostream>
#include<fstream>
#include<string>
#include<Windows.h>
using namespace std;
//Function prototypes
int mainMenu();
void goto_xy(int c, int r);
int searchLast(string lname[], int maxRow);
int searchById(string id[], int maxRow);
int reports();
void clearScreen();
//Constant variables
const int column = 15, row = 8;
//---------------------------------------------------------------------------------------------------------------------
//Main Function
void main()
{
ifstream fin;
fin.open("F:\\master.txt");//File access
int noOfRecords = 0, row, selection;
string first[15], last[15], id[15], dob[15], address[15], city[15], state[15], zip[15];
while (!fin.eof())
{
getline(fin, first[noOfRecords], ',');
getline(fin, last[noOfRecords], ',');
getline(fin, id[noOfRecords], ',');
getline(fin, dob[noOfRecords], ',');
getline(fin, address[noOfRecords], ',');
getline(fin, city[noOfRecords], ',');
getline(fin, state[noOfRecords], ',');
getline(fin, zip[noOfRecords]);
noOfRecords++;
}
fin.close();
selection = mainMenu();
//Start of while
while (selection >= 1 && selection <= 3)
{
switch (selection)
{
case 1://Searches by last name
row = searchLast(last, noOfRecords);
clearScreen();
goto_xy(column, row);
if (row >= noOfRecords)//Checks if row is greater or equal than the number of records
{
cout << "Error, record not found!";
}
else
{
cout << first[row] << " " << last[row];
}
break;
case 2://Searches by ID number
row = searchById(id, noOfRecords);
clearScreen();
goto_xy(column, row);
if (row >= noOfRecords)
{
cout << "Error, record not found!";
}
else
{
cout << first[row] << " " << last[row];
}
break;
case 3://Report menu
reports();
if (sel == 1)
{
row = searchLast(last, noOfRecords);
clearScreen();
goto_xy(column, row);
if (row >= noOfRecords)//Checks if row is greater or equal than the number of records
{
cout << "Error, record not found!";
}
else
{
cout << first[row] << " " << last[row];
}
}
else if (sel == 2)
{
row = searchById(id, noOfRecords);
clearScreen();
goto_xy(column, row);
if (row >= noOfRecords)
{
cout << "Error, record not found!";
}
else
{
cout << first[row] << " " << last[row];
}
}
else
{
clearScreen();
mainMenu();
}
break;
}
goto_xy(column, row + 14);
system("pause");
clearScreen();
selection = mainMenu();
}//End of while
selection = reports();
clearScreen();
goto_xy(column, row + 14);
system("pause");
}
//---------------------------------------------------------------------------------------------------------------------
void goto_xy(int C, int R)
{
COORD coord;
coord.X = C;
coord.Y = R;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
return;
}
//---------------------------------------------------------------------------------------------------------------------
int mainMenu()
{
//Main menu
int sel;
goto_xy(column, row);
cout << "Main Menu";
goto_xy(column, row + 1);
cout << "1. Search by last name";
goto_xy(column, row + 2);
cout << "2. Search by ID";
goto_xy(column, row + 3);
cout << "3. Reports";
goto_xy(column, row + 4);
cout << "4. Exit";
goto_xy(column, row + 7);
cout << "Please enter you selection: ";
cin >> sel;
return sel;
}
//---------------------------------------------------------------------------------------------------------------------
//Function to search by last name
int searchLast(string lname[], int maxRow)
{
int searchRow = 0;
string target;
clearScreen();
goto_xy(column, row);
cout << "Enter the last name: ";
cin >> target;
while (target != lname[searchRow] && searchRow < maxRow)
{
searchRow++;
}
return searchRow;
}
//---------------------------------------------------------------------------------------------------------------------
//Function to search by ID number
int searchById(string id[], int maxRow)
{
int searchRow = 0;
string target;
clearScreen();
goto_xy(column, row);
cout << "Enter the ID: ";
cin >> target;
while (target != id[searchRow] && searchRow < maxRow)
{
searchRow++;
}
return searchRow;
}
//---------------------------------------------------------------------------------------------------------------------
//Reports
int reports()
{
clearScreen();
int sel;
goto_xy(column, row);
cout << "Report Menu";
goto_xy(column, row + 1);
cout << "1. Report by last name";
goto_xy(column, row + 2);
cout << "2. Report by ID";
goto_xy(column, row + 3);
cout << "3. Return to Main Menu";
goto_xy(column, row + 7);
cout << "Please enter you selection: ";
cin >> sel;
return sel;
}
//---------------------------------------------------------------------------------------------------------------------
//Function that clears the screen
void clearScreen()
{
goto_xy(0, 0);
for (int i = 1; i <= 4000; i++)
{
cout << " ";
}
goto_xy(0, 0);
}
//---------------------------------------------------------------------------------------------------------------------
//Sorting last
/*void sortLast(string last[], int maxRows)
{
string temp;
int pass, row;
for (pass = 0; pass < maxRows - 1; pass++)
for (row = 0; row < maxRows - 1; row++)
{
if (last[row] > last[row + 1]);
{
temp = last[row];
last[row] = last[row + 1];
last[row + 1] = temp;
}
}
}*/
|