OOP9

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Heaven’s light is our guide

Rajshahi University of Engineering &Technology

Assignment on CSE 1203


Department of Computer Science & Engineering
Course Code: CSE 1203
Course Title: Object Oriented Programming
Date- 12 .11.2023

Submitted to:
Dr. Md. Shahid Uz Zaman
Professor
Shyla Afroge
Assistant Professor
Department of Computer Science & Engineering
Rajshahi University of Engineering & Technology

Submitted by:
Md. Al- Mottaki
Roll No: 1503028
Sec: B
Problem No & Name: We know bKash is a pioneering mobile financial service in Bangladesh that
has played a significant role in transforming the country's financial landscape. Launched in
2011, bKash was established as a joint venture between BRAC Bank Limited, one of
Bangladesh's leading private banks, and Money in Motion LLC, a US-based technology
company. Our goal is to write a similar type of program that would be very close to their
functionalities. The name of our application is myCash.
Write a C++ program to create myCash application using class and objects to fulfill the following
criteria.
i. The program is capable of storing data for each member permanently in a file. The
member data includes mobile-no, name, amount and pin.
ii. To use the system a user must register first.
iii. The program should be menu operated
iv. The program starts with a login menu. If login successful then main menu appears.
v. Define a class with data members mobile, name, amount and pin.
vi. Treat mobile number as the key information for each member.
vii. Create facilities for cash-in, cash-out, send-money and pay- bill.
viii. The system must check for duplicate member.
ix. The application should produces appropriate error message when required (table 1)
x. The system must use OTP (one time passcode) when more security is required like
Add Member, Change pin, Send money, Cash-out and Pay bill. The time validity for
the OTP is 2 minutes.
xi. The History stores the details of each transaction like Transaction ID, Customer
Mobile, Type of Transaction etc. with Date and Time.
Code:
1. #include <bits/stdc++.h>
2. using namespace std;
3.
4. class Member
5. {
6. private:
7. string mobile;
8. string name;
9. double amount;
10. string pin;
11.
12. public:
13. Member() {}
14. Member(const string &m, const string &n, double a, const string &p)
15. : mobile(m), name(n), amount(a), pin(p) {}
16.
17. string getMobile() const { return mobile; }
18. string getName() const { return name; }
19. double getAmount() const { return amount; }
20. string getPin() const { return pin; }
21.
22. void setName(const string &n) { name = n; }
23. void setAmount(double a) { amount = a; }
24. void setPin(const string &p) { pin = p; }
25. };
26.
27. class History
28. {
29. private:
30. struct Transaction
31. {
32. int transactionID;
33. string description;
34. double amount;
35. double balance;
36. };
37.
38. vector<Transaction> transactions;
39.
40. public:
41. void addTransaction(int id, const string &desc, double amt, double bal)
42. {
43. Transaction t;
44. t.transactionID = id;
45. t.description = desc;
46. t.amount = amt;
47. t.balance = bal;
48. transactions.push_back(t);
49. }
50.
51. void displayHistory()
52. {
53. cout << "Tran ID\tDescription\tAmount\tBalance" << endl;
54. for (const auto &t : transactions)
55. {
56. cout << t.transactionID << "\t" << t.description << "\t"
57. << t.amount << "\t" << t.balance << endl;
58. }
59. }
60. };
61.
62. class MyCash
63. {
64. private:
65. vector<Member> members;
66. History history;
67. string mobile;
68.
69. bool isMemberExists(const string &mobile) const
70. {
71. for (const auto &m : members)
72. {
73. if (m.getMobile() == mobile)
74. {
75. return true;
76. }
77. }
78. return false;
79. }
80.
81. Member &getMember(const string &mobile)
82. {
83. auto it = find_if(members.begin(), members.end(),
84. [mobile](const Member &m)
85. { return m.getMobile() == mobile; });
86.
87. if (it == members.end())
88. {
89. throw logic_error("Member not found");
90. }
91.
92. return *it;
93. }
94.
95. int generateOTP() const
96. {
97. int otp = rand() % 9000 + 1000;
98. cout << "myCash OTP: " << otp << endl;
99. return otp;
100. }
101.
102. bool verifyOTP(int otpEntered, int otpGenerated) const
103. {
104. cout << otpEntered << otpGenerated << endl;
105. return otpEntered == otpGenerated;
106. }
107.
108. public:
109. void registerMember()
110. {
111. cout << "Enter Mobile No. (11-digit): ";
112. string mobile;
113. cin >> mobile;
114.
115. if (isMemberExists(mobile))
116. {
117. cout << "1 Member already exists" << endl;
118. return;
119. }
120.
121. cout << "Enter Name: ";
122. string name;
123. cin.ignore();
124. getline(cin, name);
125.
126. cout << "Enter pin (5-digit): ";
127. string pin;
128. cin >> pin;
129.
130. cout << "Reconfirm pin: ";
131. string confirmPin;
132. cin >> confirmPin;
133.
134. int confirmedOtp;
135.
136. if (pin != confirmPin)
137. {
138. cout << "7 Pins must be same" << endl;
139. return;
140. }
141.
142. confirmedOtp = generateOTP();
143. cout << "Enter OTP: ";
144. int otpEntered;
145. cin >> otpEntered;
146.
147. // Simulating OTP verification
148. if (!verifyOTP(otpEntered, confirmedOtp))
149. {
150. cout << "5 OTP does NOT matched" << endl;
151. return;
152. }
153.
154. members.emplace_back(mobile, name, 0.0, pin);
155. cout << "Registration is Successful" << endl;
156. }
157.
158. bool login()
159. {
160. cout << "Enter Mobile No. (11-digit): ";
161. cin >> mobile;
162.
163. if (!isMemberExists(mobile))
164. {
165. cout << "2 Member NOT exists" << endl;
166. return false;
167. }
168.
169. cout << "Enter pin: ";
170. string pin;
171. cin >> pin;
172.
173. Member &member = getMember(mobile);
174.
175. if (member.getPin() != pin)
176. {
177. cout << "8 Invalid login" << endl;
178. return false;
179. }
180.
181. cout << "Login is Successful" << endl;
182. return true;
183. }
184.
185. void updateMember()
186. {
187. try
188. {
189. Member ¤tMember = getMember(mobile);
190.
191. cout << "Old Name: " << currentMember.getName() << endl;
192.
193. cout << "New Name (enter to ignore): ";
194. string newName;
195. cin.ignore();
196. getline(cin, newName);
197.
198. cout << "Old pin: " << currentMember.getPin() << endl;
199.
200. cout << "New pin (enter to ignore): ";
201. string newPin;
202. cin >> newPin;
203.
204. if (!newName.empty())
205. {
206. currentMember.setName(newName);
207. }
208.
209. if (!newPin.empty())
210. {
211. cout << "Confirm New pin: ";
212. string confirmPin;
213. cin >> confirmPin;
214.
215. if (newPin != confirmPin)
216. {
217. cout << "7 Pins must be same" << endl;
218. return;
219. }
220.
221. int confirmedOtp = generateOTP();
222. cout << "Enter OTP: ";
223. int otpEntered;
224. cin >> otpEntered;
225.
226. // Simulating OTP verification
227. if (!verifyOTP(otpEntered, confirmedOtp))
228. {
229. cout << "5 OTP does NOT matched" << endl;
230. return;
231. }
232.
233. currentMember.setPin(newPin);
234. }
235.
236. cout << "Update is Successful" << endl;
237. }
238. catch (const logic_error &e)
239. {
240. cout << e.what() << endl;
241. }
242. }
243.
244. void removeMember()
245. {
246. int confirmedOtp = generateOTP();
247. cout << "Enter OTP: ";
248. int otpEntered;
249. cin >> otpEntered;
250.
251. // Simulating OTP verification
252. if (!verifyOTP(otpEntered, confirmedOtp))
253. {
254. cout << "5 OTP does NOT matched" << endl;
255. return;
256. }
257.
258. members.erase(std::remove_if(members.begin(), members.end(),
259. [this](const Member &m)
260. { return m.getMobile() == mobile; }),
261. members.end());
262.
263. cout << "Remove is Successful" << endl;
264. }
265.
266. void sendMoney()
267. {
268. cout << "Enter Destination no. (11-digit): ";
269. string destMobile;
270. cin >> destMobile;
271.
272. if (!isMemberExists(destMobile))
273. {
274. cout << "9 Destination Mobile no. is invalid" << endl;
275. return;
276. }
277.
278. cout << "Enter Amount: ";
279. double amount;
280. cin >> amount;
281.
282. Member &sender = getMember(mobile);
283. Member &receiver = getMember(destMobile);
284.
285. if (sender.getAmount() < amount)
286. {
287. cout << "3 Insufficient Fund" << endl;
288. return;
289. }
290.
291. cout << "Sending " << amount << " to " << destMobile << endl;
292. cout << "Are you sure(Y/N)? ";
293. char choice;
294. cin >> choice;
295.
296. if (choice == 'Y' || choice == 'y')
297. {
298. int confirmedOtp = generateOTP();
299. cout << "Enter OTP: ";
300. int otpEntered;
301. cin >> otpEntered;
302.
303. // Simulating OTP verification
304. if (!verifyOTP(otpEntered, confirmedOtp))
305. {
306. cout << "5 OTP does NOT matched" << endl;
307. return;
308. }
309.
310. sender.setAmount(sender.getAmount() - amount);
311. receiver.setAmount(receiver.getAmount() + amount);
312.
313. history.addTransaction(rand() % 1000, "Send Money", amount,
sender.getAmount());
314. cout << "Send Money is Successful" << endl;
315. }
316. else
317. {
318. cout << "Send Money Cancelled" << endl;
319. }
320. }
321.
322. void cashIn()
323. {
324. cout << "Enter Amount: ";
325. double amount;
326. cin >> amount;
327.
328. Member &member = getMember(mobile);
329.
330. cout << "Cash-in " << amount << endl;
331. cout << "Are you sure(Y/N)? ";
332. char choice;
333. cin >> choice;
334.
335. if (choice == 'Y' || choice == 'y')
336. {
337. member.setAmount(member.getAmount() + amount);
338. history.addTransaction(rand() % 1000, "Cash-in", amount,
member.getAmount());
339. cout << "Cash-in is Successful" << endl;
340. }
341. else
342. {
343. cout << "Cash-in Cancelled" << endl;
344. }
345. }
346.
347. void cashOut()
348. {
349. cout << "Enter Amount: ";
350. double amount;
351. cin >> amount;
352.
353. Member &member = getMember(mobile);
354.
355. int confirmedOtp = generateOTP();
356. cout << "Enter OTP: ";
357. int otpEntered;
358. cin >> otpEntered;
359.
360. // Simulating OTP verification
361. if (!verifyOTP(otpEntered, confirmedOtp))
362. {
363. cout << "5 OTP does NOT matched" << endl;
364. return;
365. }
366.
367. if (member.getAmount() < amount)
368. {
369. cout << "3 Insufficient Fund" << endl;
370. return;
371. }
372.
373. cout << "Cash-out " << amount << endl;
374. cout << "Are you sure(Y/N)? ";
375. char choice;
376. cin >> choice;
377.
378. if (choice == 'Y' || choice == 'y')
379. {
380. member.setAmount(member.getAmount() - amount);
381. history.addTransaction(rand() % 1000, "Cash-out", amount,
member.getAmount());
382. cout << "Cash-out is Successful" << endl;
383. }
384. else
385. {
386. cout << "Cash-out Cancelled" << endl;
387. }
388. }
389.
390. void payBill()
391. {
392. cout << "Enter Bill Type (Gas/Electricity/Water/Internet-1/2/3/4): ";
393. int billType;
394. cin >> billType;
395.
396. cout << "Your ";
397. switch (billType)
398. {
399. case 1:
400. cout << "Gas";
401. break;
402. case 2:
403. cout << "Electricity";
404. break;
405. case 3:
406. cout << "Water";
407. break;
408. case 4:
409. cout << "Internet";
410. break;
411. default:
412. cout << "Invalid";
413. break;
414. }
415.
416. cout << " Bill: ";
417. double billAmount;
418. cin >> billAmount;
419.
420. cout << "Want to pay(Y/N)? ";
421. char choice;
422. cin >> choice;
423.
424. if (choice == 'Y' || choice == 'y')
425. {
426. int confirmedOtp = generateOTP();
427. cout << "Enter OTP: ";
428. int otpEntered;
429. cin >> otpEntered;
430.
431. // Simulating OTP verification
432. if (!verifyOTP(otpEntered, confirmedOtp))
433. {
434. cout << "5 OTP does NOT matched" << endl;
435. return;
436. }
437.
438. Member &member = getMember(mobile);
439. if (member.getAmount() < billAmount)
440. {
441. cout << "3 Insufficient Fund" << endl;
442. return;
443. }
444.
445. member.setAmount(member.getAmount() - billAmount);
446. history.addTransaction(rand() % 1000, "Pay Bill", billAmount,
member.getAmount());
447. cout << "Bill Payment is Successful" << endl;
448. }
449. else
450. {
451. cout << "Bill Payment Cancelled" << endl;
452. }
453. }
454.
455. void checkBalance()
456. {
457. cout << "Balance: " << getMember(mobile).getAmount() << endl;
458. }
459.
460. void displayHistory()
461. {
462. history.displayHistory();
463. }
464. };
465.
466. int main()
467. {
468. srand(time(0));
469.
470. MyCash myCash;
471. int option;
472.
473. do
474. {
475. cout << "\n*** MyCash Login Menu ***" << endl;
476. cout << "1. Login\n2. Register\n3. Exit\nEnter Your Option: ";
477. cin >> option;
478.
479. switch (option)
480. {
481. case 1:
482. if (myCash.login())
483. {
484. do
485. {
486. cout << "\n********** MyCash Menu ********" << endl;
487. cout << "1. Update Me\n2. Remove Me\n3. Send Money\n4. Cash-
in\n5. Cash-out\n"
488. << "6. Pay Bill\n7. Check Balance\n8. History\n9.
Logout\nEnter Your Option (1-9): ";
489. cin >> option;
490.
491. switch (option)
492. {
493. case 1:
494. myCash.updateMember();
495. break;
496. case 2:
497. myCash.removeMember();
498. option = 9; // Logout after removing the member
499. break;
500. case 3:
501. myCash.sendMoney();
502. break;
503. case 4:
504. myCash.cashIn();
505. break;
506. case 5:
507. myCash.cashOut();
508. break;
509. case 6:
510. myCash.payBill();
511. break;
512. case 7:
513. myCash.checkBalance();
514. break;
515. case 8:
516. myCash.displayHistory();
517. break;
518. case 9:
519. cout << "Logout Successful" << endl;
520. break;
521. default:
522. cout << "10 Invalid Option" << endl;
523. }
524. } while (option != 9);
525. }
526. break;
527. case 2:
528. myCash.registerMember();
529. break;
530. case 3:
531. cout << "Exiting MyCash Application" << endl;
532. break;
533. default:
534. cout << "Invalid Option" << endl;
535. }
536.
537. } while (option != 3);
538.
539. return 0;
540. }

Output:

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 1
Enter Mobile No. (11-digit): 01910982274
2 Member NOT exists

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 2
Enter Mobile No. (11-digit): 01910982274
Enter Name: al mottaki
Enter pin (5-digit): 12345
Reconfirm pin: 12345
myCash OTP: 4386
Enter OTP: 4386
43864386
Registration is Successful

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 1
Enter Mobile No. (11-digit): 01910982274
Enter pin: 12345
Login is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 4
Enter Amount: 5000
Cash-in 5000
Are you sure(Y/N)? Y
Cash-in is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 1
Old Name: al mottaki
New Name (enter to ignore): MD AL MOTTAKI
Old pin: 12345
New pin (enter to ignore): 23456
Confirm New pin: 23456
myCash OTP: 4811
Enter OTP: 4811
48114811
Update is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 3
Enter Destination no. (11-digit): 01910982275
9 Destination Mobile no. is invalid

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 7
Balance: 5000

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 8
Tran ID Description Amount Balance
973 Cash-in 5000 5000

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 6
Enter Bill Type (Gas/Electricity/Water/Internet-1/2/3/4): 1
Your Gas Bill: 1000
Want to pay(Y/N)? Y
myCash OTP: 2135
Enter OTP: 2135
21352135
Bill Payment is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 5
Enter Amount: 2000
myCash OTP: 3912
Enter OTP: 3912
39123912
Cash-out 2000
Are you sure(Y/N)? Y
Cash-out is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 8
Tran ID Description Amount Balance
973 Cash-in 5000 5000
728 Pay Bill 1000 4000
910 Cash-out 2000 2000

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 7
Balance: 2000

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 9
Logout Successful

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 2
Enter Mobile No. (11-digit): 01910982275
Enter Name: Jamal Khan
Enter pin (5-digit): 12345
Reconfirm pin: 12345
myCash OTP: 7863
Enter OTP: 7863
78637863
Registration is Successful

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 1
Enter Mobile No. (11-digit): 01910982274
Enter pin: 23456
Login is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 3
Enter Destination no. (11-digit): 01910982275
Enter Amount: 1000
Sending 1000 to 01910982275
Are you sure(Y/N)? Y
myCash OTP: 5787
Enter OTP: 5787
57875787
Send Money is Successful

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 8
Tran ID Description Amount Balance
973 Cash-in 5000 5000
728 Pay Bill 1000 4000
910 Cash-out 2000 2000
618 Send Money 1000 1000

********** MyCash Menu ********


1. Update Me
2. Remove Me
3. Send Money
4. Cash-in
5. Cash-out
6. Pay Bill
7. Check Balance
8. History
9. Logout
Enter Your Option (1-9): 9
Logout Successful

*** MyCash Login Menu ***


1. Login
2. Register
3. Exit
Enter Your Option: 3
Exiting MyCash Application
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-
MIEngine-In-on2siopp.irp" 1>"/tmp/Microsoft-MIEngine-Out-evlffzss.x2x"

Conclusion and Discussion: The MyCash application is a simple banking system implemented in
C++. It provides basic functionalities such as member registration, login, updating member
information, sending money, cash-in, cash-out, paying bills, checking balance, and viewing
transaction history.
Key Features:
• User Registration and Login: Users can register with a unique mobile number and PIN. The
login process ensures secure access to the system.
• Transaction Operations: Users can perform various financial transactions, including
sending money, cash-in, cash-out, and paying bills.
• Error Handling: The application includes error messages for scenarios such as duplicate
member registration, insufficient funds, invalid input, and incorrect OTP verification.

You might also like