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
|
//include the neccessary headers
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
//declare the necessary constants
const int arrsize = 1000;
const int arrsize2 = 1000;
bool going = true;
//Users arrays
string user_id[arrsize], fname[arrsize], lname[arrsize], address[arrsize];
char Gender[arrsize];
int Age[arrsize], Phone[arrsize];
int x;
string user_id2[arrsize2], fname2[arrsize2], lname2[arrsize2], address2[arrsize2];
char Gender2[arrsize2];
int Age2[arrsize2], Phone2[arrsize2];
int x2;
//Contacts arrays
string user_ids[arrsize], contact_with[arrsize];
int contact_start[arrsize], contact_duration[arrsize], contact_end[arrsize];
int distances[arrsize];
int y;
string user_ids2[arrsize], contact_with2[arrsize];
int contact_start2[arrsize], contact_duration2[arrsize], contact_end2[arrsize];
int distances2[arrsize];
int y2;
void mySearchUser();
void myUserDistance();
void myReadFromUser();
void myReadFromUser2();
void myReadFromContact();
void myReadFromContact2();
void requirements(string respond);
//main function
int main()
{
//Display message and instructions about the program
cout << "\n\n\t\tWelcome to Covid-19 Record Manager" << endl;
cout << "\t\t**********************************" << endl;
cout << "1. Exit the Program" << endl;
cout << "2. Print the users" << endl;
cout << "3. Print all the contacts" << endl;
cout << "4. Print the contacts who came into contact" << endl;
cout << "5. Searching by UerID" << endl;
string repond;
cout << "Enter your option (1-5):";
cin >> repond;
//read the files using the functions
requirements(repond);
//rest of the program
return 0;
}
//declare the Contact struct
void mySearchUser() {
myReadFromUser2();
string search;
cout << "Please enter a User ID to search: ";
cin >> search;
for (int i = 0; i < x2; i++) {
if (user_id2[i] == search) {
cout << "-------------------------" << endl;
cout << "UserID:" << user_id2[i] << endl;
cout << "Name:" << fname2[i] << " " << lname2[i] << endl;
cout << "Gender:" << Gender2[i] << endl;
cout << "Age:" << Age2[i] << endl;
cout << "Phone:" << Phone2[i] << endl;
cout << "Address:" << address2[i] << endl;
cout << "-------------------------" << endl;
}
}
main();
}
//declare the User struct
void myUserDistance() {
myReadFromContact2();
int xy = 0;
cout << "-------------------------------------------------------------" << endl;
cout << "\nUserID\t Con/With\t Duration(s)\t Distance(cm) \n";
cout << "-------------------------------------------------------------" << endl;
for (int i = 0; i < y2 - 1; i++)
{
if (distances2[i] < 100 || contact_duration2[i] >= 15) {
cout << user_ids2[i] << "\t\t" << contact_with2[i] << "\t\t" << contact_duration2[i] << "\t\t" << distances2[i] << endl;
xy++;
}
}
cout << "Total Contacts: " << xy << "/" << y2 - 1 << endl;
cout << "-------------------------------------------------------------" << endl;
main();
}
//function to read the users.txt file
void myReadFromUser() {
string line;
fstream myRead;
myRead.open("users.txt", ios::in);//read
if (myRead.is_open()) {
while (getline(myRead, line))
{
myRead >> user_id[x] >> fname[x] >> lname[x] >> Gender[x] >> Age[x] >> Phone[x] >> address[x];
x++;
}
cout << "-------------------------------------------------------------" << endl;
cout << "\nUserID\t Fname\t Lname\t Gender\t Age \t Phone\t Address \n";
cout << "-------------------------------------------------------------" << endl;
for (int i = 0; i < x - 1; i++) {
cout << user_id[i] << "\t" << fname[i] << "\t" << lname[i] << "\t" << Gender[i] << "\t" << Age[i] << "\t" << Phone[i] << "\t" << address[i] << endl;
}
cout << "Total Contacts: " << x - 1 << endl;
cout << "-------------------------------------------------------------" << endl;
}
else
{
cerr << "Error Opening";
}
myRead.close();
main();
}
void myReadFromUser2() {
string line;
fstream myRead;
myRead.open("users.txt", ios::in);//read
if (myRead.is_open()) {
while (getline(myRead, line))
{
myRead >> user_id2[x2] >> fname2[x2] >> lname2[x2] >> Gender2[x2] >> Age2[x2] >> Phone2[x2] >> address2[x2];
x2++;
}
for (int i = 0; i < x2 - 1; i++) {
}
}
myRead.close();
}
void myReadFromContact()
{
string line;
y = 0;
fstream myRead;
myRead.open("contacts.txt", ios::in);//open in read-mode
if (myRead.is_open()) //open file
{
while (getline(myRead, line))
{
//Read from contact.txt into each field array
myRead >> user_ids[y] >> contact_with[y] >> contact_start[y] >> contact_end[y] >> distances[y];
contact_duration[y] = contact_end[y] - contact_start[y];
y++;
}
cout << "-------------------------------------------------------------" << endl;
cout << "\nUserID\t Con/With\t Duration(s)\t Distance(cm) \n";
cout << "-------------------------------------------------------------" << endl;
for (int i = 0; i < y - 1; i++) {
cout << user_ids[i] << "\t\t" << contact_with[i] << "\t\t" << contact_duration[i] << "\t\t" << distances[i] << endl;
}
cout << "Total Contacts: " << y - 1 << endl;
cout << "-------------------------------------------------------------" << endl;
}
else
{
cerr << "Error Opening";
}
myRead.close();
main();
}
void myReadFromContact2() {
string line;
y2 = 0;
fstream myRead;
myRead.open("contacts.txt", ios::in);//open in read-mode
if (myRead.is_open()) //open file
{
while (getline(myRead, line))
{
//Read from contact.txt into each field array
myRead >> user_ids2[y2] >> contact_with2[y2] >> contact_start2[y2] >> contact_end2[y2] >> distances2[y2];
contact_duration2[y2] = contact_end2[y2] - contact_start2[y2];
y2++;
}
for (int i = 0; i < y2 - 1; i++) {
}
}
else
{
cerr << "Error Opening";
}
myRead.close();
}
//function to implement all the requirements (1-5)
void requirements(string respond)
{
if (respond == "1")
{
exit(1);
}
else if (respond == "2")
{
myReadFromUser();
}
else if (respond == "3")
{
myReadFromContact();
}
else if (respond == "4")
{
myUserDistance();
}
else if (respond == "5")
{
mySearchUser();
}
else
{
cout << "Invalid Input" << endl;
}
main();
| |