-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMOBILE.CPP
More file actions
291 lines (290 loc) · 9.83 KB
/
MOBILE.CPP
File metadata and controls
291 lines (290 loc) · 9.83 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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*****************************************************************************
* HEADER FILES *
*****************************************************************************/
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<dos.h>
class Mobile
{
char name[50],G,WiFi,procssr[50],RAM[30],version[100];
double price,scrnsize,Rcamera,Fcamera;
int battery,no;
public:
/*****************************************************************************
* FUNCTIONS IN CLASS *
*****************************************************************************/
void sell();
void purchase();
int add();
void disp_all();
void display();
void search();
void remov();
char *rname();
}M;
void Mobile::sell()
{
int count=0,tno;
char tname[50];
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
ofstream fout("temp.txt",ios::app|ios::binary);
A.disp_all();
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter the Name of Mobile that You Want to Sell \n ";gets(tname);
while(fin.read((char*)&A,sizeof(A)))
{ if(stricmp(A.rname(),tname)==0)
{ count=1;
cout<<"\n Enter the Number of Mobiles that You Want to Sell \n ";cin>>tno;
if(A.no>=tno)
{ A.no=A.no-tno;
cout<<"\n Amount = $"<<A.price*tno<<"\n ";
cout<<"\n Mobile(s) Sold \n ";
}
else cout<<"\n Sorry!! Not Enough Stock \n ";
}
fout.write((char*)&A,sizeof(A));
}
if(count==0) cout<<"\n Enter Correct Name!! \n ";
fin.close();
fout.close();
remove("mobile.txt");
rename("temp.txt","mobile.txt");
}
void Mobile::purchase()
{
int count=0,tno;
char tname[50];
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
ofstream fout("temp.txt",ios::app|ios::binary);
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter Name of Mobile that You Want to Purchase \n ";gets(tname);
while(fin.read((char*)&A,sizeof(A)))
{ if(stricmp(A.rname(),tname)==0)
{ count=1;
cout<<"\n Enter the Number of Mobiles that You Want to Purchase \n ";cin>>tno;
A.no+=tno;
cout<<"\n Amount = $"<<A.price*tno<<"\n ";
cout<<"\n Mobile(s) Purchased \n ";
}
fout.write((char*)&A,sizeof(A));
}
if(count==0) cout<<"\n Enter Correct Name!! \n ";
fin.close();
fout.close();
remove("mobile.txt");
rename("temp.txt","mobile.txt");
}
int Mobile::add()
{
int i;
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
clrscr();
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter the Mobile Name \n ";gets(name);
for(i=0;name[i]!='\0';i++) name[i]=toupper(name[i]);
while(fin.read((char*)&A,sizeof(A)))
if(stricmp(A.rname(),name)==0)
{ cout<<"\n Record Already Exist!! \n ";
return 1;
}
cout<<"\n Enter Price (In US Dollors) \n ";cin>>price;
cout<<"\n Is the Mobile Supports 3G? (Y/N) \n ";cin>>G;
G=toupper(G);
cout<<"\n Is the Mobile Supports WiFi? (Y/N) \n ";cin>>WiFi;
WiFi=toupper(WiFi);
cout<<"\n Enter Processor \n ";gets(procssr);
for(i=0;procssr[i]!='\0';i++)
{ if(procssr[i]!='z'&&procssr[i]!='Z') procssr[i]=toupper(procssr[i]);
else procssr[i]=tolower(procssr[i]);
}
cout<<"\n Enter RAM \n ";gets(RAM);
for(i=0;RAM[i]!='\0';i++) RAM[i]=toupper(RAM[i]);
clrscr();
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter Battery Capacity (In mAh) \n ";cin>>battery;
cout<<"\n Enter Screen Size (In Inches) \n ";cin>>scrnsize;
cout<<"\n Enter Rear Camera (In Mega Pixals) \n ";cin>>Rcamera;
cout<<"\n Enter Front Camera (In Mega pixals) \n ";cin>>Fcamera;
cout<<"\n Enter Version \n ";gets(version);
for(i=0;version[i]!='\0';i++) version[i]=toupper(version[i]);
cout<<"\n Enter No. of Mobiles that You Want to Purchase \n ";cin>>no;
cout<<"\n\t\t\t\t Record Added \n ";
fin.close();
return 0;
}
void Mobile::disp_all()
{
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
while(fin.read((char*)&A,sizeof(A)))
{ A.display();
getch();
}
cout<<"\n\n\t\t\t\t No More Records \n ";
fin.close();
}
void Mobile::display()
{
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n The Information About Mobile Is: \n\n";
cout<<" Mobile Name : ";puts(name);
cout<<" Price : $"<<price<<endl;
cout<<" 3G : "<<G<<endl;
cout<<" WiFi : "<<WiFi<<endl;
cout<<" Processor : ";puts(procssr);
cout<<" RAM : ";puts(RAM);
cout<<" Battery Capacity: "<<battery<<" mAh"<<endl;
cout<<" Screen Size : "<<scrnsize<<" Inch"<<endl;
cout<<" Rear Camera : "<<Rcamera<<" MP"<<endl;
cout<<" Front Camera : "<<Fcamera<<" MP"<<endl;
cout<<" Version : ";puts(version);
cout<<" No. of Mobile : "<<no<<endl;
cout<<"\n Press Any Key to Continue.... \n ";
}
void Mobile::search()
{
int count=0;
char tname[50];
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter the Mobile Name that You Want to Search \n ";gets(tname);
while(fin.read((char*)&A,sizeof(A)))
if(stricmp(A.rname(),tname)==0)
{
count=1;
cout<<"\n Search Successful. Record Found. \n ";
getch();
A.display();
}
if(count==0) cout<<"\n Search Unsuccessful. Record Not Found. \n ";
fin.close();
}
void Mobile::remov()
{
char tname[50],ans;
int count=0;
Mobile A;
ifstream fin("mobile.txt",ios::app|ios::binary);
ofstream fout("temp.txt",ios::app|ios::binary);
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Enter the Mobile Name that You Want to Remove \n ";gets(tname);
while(fin.read((char*)&A,sizeof(A)))
{ if(stricmp(A.rname(),tname)==0)
{ count++;
A.display();
getch();
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Are You Sure? You Want to Remove This Record? \n ";cin>>ans;
if(ans=='N'||ans=='n') fout.write((char*)&A,sizeof(A));
else
{ cout<<"\n Deleting.... \n ";
sleep(1);
cout<<"\n Record Deleted \n ";
}
}
else fout.write((char*)&A,sizeof(A));
}
if(count==0) cout<<"\n The Record Does Not Exist!! \n ";
fin.close();
fout.close();
remove("mobile.txt");
rename("temp.txt","mobile.txt");
}
char *Mobile::rname()
{ return name; }
void add_mob()
{
Mobile C;
ofstream fout("mobile.txt",ios::app|ios::binary);
if(C.add()==0) fout.write((char*)&C,sizeof(C));
fout.close();
}
/*****************************************************************************
* USER DEFINED FUNCTIONS *
*****************************************************************************/
void add_mob();
void main();
void main()
{clrscr();
char ch;
char ans='Y';
clrscr();
for(int i=0;i<23;i++) cout<<char(-2);
while(ans=='Y'||ans=='y')
{
clrscr();
cout<<" ";for(int i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<"\n ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n\t\t Select Your Choice From The Options Below.... \n ";
cout<<"\n\n\t 1.Sell \t 2.Purchase \t 3.Add New \t 4.Display All \n\n\t 5.Search \t 6.Remove \t 7.Exit \n\n ";
ch=getche();
switch(ch)
{ case'1':M.sell();
break;
case'2':M.purchase();
break;
case'3':add_mob();
break;
case'4':M.disp_all();
break;
case'5':M.search();
break;
case'6':M.remov();
break;
case'7':exit(0);
default:cout<<"\n\n Enter Correct Choice \n ";
}
getch();
clrscr();
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ABCD MOBILE GALLARY ";
cout<<" ";for(i=0;i<23;i++) cout<<char(-2);
cout<<"\n ____________________________________________________________________________ ";
cout<<"\n\n Thank You \n ";
sleep(1);
cout<<"\n Want to Do More? (Y/N) \n ";cin>>ans;
}
}
/*****************************************************************************
* END OF PROGRAM *
*****************************************************************************/