-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.cpp
More file actions
176 lines (150 loc) · 4.46 KB
/
update.cpp
File metadata and controls
176 lines (150 loc) · 4.46 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
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
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<ctime>
#include<vector>
#include<fstream>
#include<sstream>
#include "class.h"
#include "search.h"
#include "title.h"
using namespace std;
void update(int indicator)
{
string currentTime;
system("cls");
display(UPDATE WINDOW);
int choice,chosenId=indicator;
vector<BasicInfo> base;
Account sampleAccount;
ifstream bfile("files\\data");
if(bfile.is_open()) //if the file opening is successful.
{
while(!bfile.eof())
{
BasicInfo dummy;
dummy.loadBasic(bfile);
base.push_back(dummy);
}
bfile.close();
}
else
{
cout<<"There is nothing on this server please input a new account first."<<endl;
return;
}
if(indicator==-1) //if no indicator value passed from search
{
cout<<"You need to find the account first.Choose a option below :"<<endl
<<"1. Go to SEARCH WINDOW to search by name."<<endl
<<"2. Enter the account ID."<<endl
<<endl<<"INPUT : ";
cin>>choice;
while(choice!=1 && choice!=2)
{
cout<<"Invalid selection !! Try again : ";
cin>>choice;
}
if(choice==1)
{
chosenId=search_();
if(chosenId==-1) //if search was not finished properly.
{
cout<<"Could not find the account!"<<endl;
return;
}
}
else
{
cout<<"Enter the id you want to find : ";
cin>>choice;
unsigned int i;
for(i=0; i<base.size(); i++)
{
if(base[i].getId()==choice)
{
chosenId=choice;
break;
}
}
if(i==base.size())
{
cout<<"Id not found!"<<endl;
return;
}
}
}
system("cls");
display(UPDATE WINDOW);
//Starting updating.
string path="files\\customers\\";
stringstream str(path);
str<<path<<chosenId;
path=str.str();
ifstream data(path.c_str());
sampleAccount.loadData(data);
data.close();
cout<<"Name : "<<setw(20)<<left<<sampleAccount.name<<"ID : "<<sampleAccount.getId()<<endl<<endl; //Formatted I/O
cout<<"1. Updating Balance"<<endl
<<"2. Updating Other Information"<<endl
<<"3. Cancel."<<endl
<<endl<<"INPUT: ";
cin>>choice;
while(choice!=1 && choice!=2 && choice!=3)
{
cout<<"Invalid selection !! Try again : ";
cin>>choice;
}
if(choice==1)
{
sampleAccount.balanceExchange();
}
else if(choice==2)
{
cout<<"Select the index from the following list to upgrade information-- "<<endl
<<"1.Present address. "<<endl
<<"2.Email address. "<<endl
<<"3.Contact Number. "<<endl
<<"4.Enter zero (0) to cancel "<<endl
<<"[N.B: Some informations like name,age etc are not changable] "<<endl;
cin>>choice;
cin.ignore();
while(choice!=1 && choice!=2 && choice!=3 && choice!=4)
{
cout<<"Invalid selection !! Try again : ";
cin>>choice;
cin.ignore();
}
switch (choice)
{
case 1:
cout<<"Your current address: "<<sampleAccount.address<<endl;
cout<<"Enter the new address: ";
getline(cin,sampleAccount.address);
break;
case 2:
cout<<"Your current E-mail address: "<<sampleAccount.email<<endl;
cout<<"Enter the new E-mail address: ";
getline(cin,sampleAccount.email);
break;
case 3:
cout<<"Your current Contact Number: "<<sampleAccount.contactNo<<endl;
cout<<"Enter the new Contact Number: ";
getline(cin,sampleAccount.contactNo);
break;
default:
cout<<"Process canceled."<<endl;
return;
}
cout<<"Information updated successfully."<<endl;
}
else
{
cout<<"Process canceled."<<endl;
return;
}
ofstream data2(path.c_str());
sampleAccount.saveData(data2);
data2.close();
}