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
|
#include "User.h"
using namespace std;
int search (User a[ ], int length, string userID);
int main(){
int returnto;
do
{
//User u; //object of class user
string id, password, firstname, lastname, userid; //Temp holder varibles
string choice; //Varible to hold the users choice in the while loop
int length=0; // A varible not used
int currentuser=-1; // varible that holds the array position for the current users
int passattempts=0;// Holds the number of pass attemps the users has made
ofstream fout;
ifstream fin; // declare input file stream object
fin.open ("a3.txt");
fout.close();
User a[50]; //array of 50 Users
for(int i=0; i<50; i++){
fin >> firstname >> lastname >> id >> password;
a[i].setFn(firstname);
a[i].setLn(lastname);
a[i].setID(id);
a[i].setPassword(password);
a[i].setUserid(id);
}
while(currentuser == -1){
cout << "Enter user User ID: ";
cin >> userid;
currentuser = search(a, length, userid);
}
while(passattempts != 3){
cout << "Enter password: ";
cin >> password;
if(password != a[currentuser].getPassword()){
passattempts++;
}
else if(password == a[currentuser].getPassword()){
cout << "\n" << a[currentuser].getUserid() << " successfully logged in";
cout << "\n\nWelcome Back: " << a[currentuser].getFn() << "\n";
while (choice != "q" || "Q"){
cout << "\nEnter choice from menu:";
cout << "\nF - Change first name";
cout << "\nL - Change last name";
cout << "\nP - Change password";
cout << "\nT - Record datea and time";
cout << "\nQ - Quit\n";
cout << "\nChoice: ";
cin >> choice;
if (choice == "f" || choice == "F"){
string input;
cout << "\nCurrent first name: " << a[currentuser].getFn() << "\nPlease Enter new first name: ";
cin >> input;
try
{
a[currentuser].setFn(input);
cout << "\nThe name is now " << a[currentuser].getFn() << "\n\n";
}
catch (string errorMsg)
{
cerr << "\nError: " << errorMsg << endl;
}
}
else if (choice == "l" || choice == "L"){
string input;
cout << "\nCurrent last name: " << a[currentuser].getLn() << "\nPlease Enter new last name: ";
cin >> input;
try{
a[currentuser].setLn(input);
a[currentuser].setUserid(a[currentuser].getID());
cout << "\nYour last name is now: " << a[currentuser].getLn();
cout << "\nNew User ID: " << a[currentuser].getUserid() << "\n\n";
}
catch (string errorMsg){
cerr << "\nError: " << errorMsg << endl;
}
}
else if (choice == "p" || choice == "P"){
string input;
cout << "Please Enter new password: ";
cin >> input;
try{
a[currentuser].setPassword(input);
cout << "\nYour password has been changed successufully" << "\n\n";
}
catch(string errorMsg){
cerr << "Error: " << errorMsg << endl;
}
}
else if (choice == "t" || choice == "T"){
//cout << a[currentuser].currentDateTime() << endl;
a[currentuser].recordTime(a[currentuser].getLn() , a[currentuser].getFn());
}
else if (choice == "q" || choice == "Q"){
//exit(1);
returnto = 1;
currentuser = -1;
system("cls");
}
else{
cout << "Invalid choice";
}
}
}
}
if(passattempts == 3){
cout << "\nTo many password attemps, The program will now exit\n\n";
exit(1);
}
}
while (returnto == 1);
if (returnto == 2){
exit(1);
}
}
int search (User a[ ], int length, string userID){
//pre: takes in the users array, length, and, UserID
//post: searches through array and looks for match of inputed userid
string tempid; //temp holder varible
int templegnth;
for(int i=0; i<50; i++){
tempid = a[i].getUserid();
templegnth = tempid.length();
if((tempid == userID)){
return i;
}
}
return -1;
}
|