-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount_Create_and_Access.cpp
More file actions
132 lines (126 loc) · 3.98 KB
/
Account_Create_and_Access.cpp
File metadata and controls
132 lines (126 loc) · 3.98 KB
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
#include <iostream>
#include<fstream>
#include <chrono>
#include <thread>
using namespace std;
int i=0;
string selection,username,cellphone,zipcode,getUsername;
string line;
string number_instring;
int number;
ofstream WriteFile;
ifstream ReadFile;
class SimpleAccount
{
public:
int ReadLine()
{
ReadFile.open ("Account.csv");
if (ReadFile.is_open())
{
ReadFile.seekg(-3,ios::end);
number_instring=ReadFile.get();
number=stoi(number_instring,nullptr,0);
}
else
{
cout<<"\n"<<"Creating Account File Right Now..."<<endl;
WriteFile.open("Account.csv");
WriteFile<<"Username"<<","<<"Cellphone Number"<<","<<"Zip Code"<<","<<"No."<<endl;
WriteFile.close();
number=0;
this_thread::sleep_for(std::chrono::milliseconds(1000));
cout<<"Done! Now you can type in the service you may want!"<<endl;
}
ReadFile.close();
return number;
}
void CreateEverything(string& name,string& cell,string& zip)
{
i++;
WriteFile.open("Account.csv",fstream::app);
WriteFile<<name<<","<<cell<<","<<zip<<","<<i<<endl;
WriteFile.close();
}
};
int main()
{
SimpleAccount Account;
while(1)
{
cout<<"Please select the service."<<endl;
cout<<"1.Create a new account;"<<endl;
cout<<"2.Read an account;"<<endl;
cout<<"3.Exit."<<endl<<endl;
cout<<"Please type in your selection: ";
//cout<<Account.ReadLine();
i=Account.ReadLine();
getline(cin,selection);
if(selection=="1")
{
cout<<"Please type in username: ";
getline(cin,username);
cout<<"Please type in cellphone number: ";
getline(cin,cellphone);
cout<<"Please type in your zipcode: ";
getline(cin,zipcode);
cout<<"Transmitting..."<<endl;
Account.CreateEverything(username,cellphone,zipcode);
this_thread::sleep_for(std::chrono::milliseconds(1000));
cout<<"You are all set!"<<endl<<endl;
this_thread::sleep_for(std::chrono::milliseconds(1000));
cout<<"What else can I help you?"<<endl<<endl;
}
else if(selection=="2")
{
bool findit=false;
cout<<"Please type in the username: ";
getline(cin,getUsername);
ReadFile.open("Account.csv");
if (ReadFile.is_open())
{
size_t pos;
while(ReadFile.good())
{
getline(ReadFile,line);
pos=line.find(getUsername);
if(pos!=string::npos)
{
findit=true;
cout<<"Found!"<<endl;
this_thread::sleep_for(std::chrono::milliseconds(500));
cout<<"User Info is as follow: ";
cout<<line<<endl<<endl;
this_thread::sleep_for(std::chrono::milliseconds(500));
break;
}
}
}
else
{
cout<<"\n"<<"Creating Account File Right Now..."<<endl;
WriteFile.open("Account.csv");
WriteFile<<"Username"<<","<<"Cellphone Number"<<","<<"Zip Code"<<","<<"No."<<endl;
WriteFile.close();
this_thread::sleep_for(std::chrono::milliseconds(1000));
cout<<"Done! Now you can type in the service you may want!"<<endl;
}
ReadFile.close();
if(findit==false)
{
cout<<"No such name is found in the file."<<endl<<endl;
}
}
else if(selection=="3")
{
break;
}
else
{
cout<<"Please select again."<<endl;
}
}
WriteFile.close();
ReadFile.close();
return 0;
}