#include <iostream>
#include<fstream>
#include <cstdio>
using namespace std;
class exchange{
public:
string num,name,pass,cash,findNum,findPass;
float bal,sentMoney;
fstream file,file_1;
void signUp()
{
cout<<endl<<"----------SIGNUP---------"<<endl;
cout<<endl<<"Enter Your Name : ";
getline(cin,name);
cout<<endl<<"Enter Your Phone Number : ";
getline(cin,num);
cout<<endl<<"Enter Your Password : ";
getline(cin,pass);
file.open("loginData.txt",ios :: out | ios :: app);
file<<num<<"*"<<pass<<"*"<<name<<"*0"<<endl;
file.close();
}
void logIn()
{
cout<<endl<<"----------LOGIN---------"<<endl;
cout<<endl<<"Enter Your Phone Number : ";
getline(cin,findNum);
cout<<endl<<"Enter Your Password : ";
getline(cin,findPass);
file.open("loginData.txt",ios :: in);
getline(file,num,'*');
getline(file,pass,'*');
getline(file,name,'*');
getline(file,cash,'\n');
bool f=true;
while(!file.eof())
{
if(findNum==num && findPass==pass)
{
cout<<endl<<"Hello "<<name<<endl;
f=false;
break;
}
else
{
getline(file,num,'*');
getline(file,pass,'*');
getline(file,name,'*');
getline(file,cash,'\n');
}
}
if(f) cout<<endl<<"Invalid Password or Number";
file.close();
bal=stof(cash);
}
void balance()
{
cout<<endl<<"Your Account Balance is : ";
printf("%.2f TK",bal);
}
void sent()
{
string revNum,revName,revPass,revCash;
float revBal;
cout<<endl<<"Enter Receiver Number : ";
getline(cin,revNum);
cout<<endl<<"Enter the Amount : ";
cin>>sentMoney;
file.open("loginData.txt",ios :: in);
file_1.open("new.txt",ios :: out | ios :: app);
getline(file,num,'*');
getline(file,pass,'*');
getline(file,name,'*');
getline(file,cash,'\n');
while(!file.eof())
{
if(findNum==num)
{
bal-=sentMoney;
cash=to_string(bal);
}
else if(revNum==num)
{
revBal=stof(cash);
cash=to_string(revBal+sentMoney);
}
file_1<<num<<'*'<<pass<<'*'<<name<<'*'<<cash<<endl;
getline(file,num,'*');
getline(file,pass,'*');
getline(file,name,'*');
getline(file,cash,'\n');
}
file.close();
file_1.close();
remove("loginData.txt");
rename("new.txt","loginData.txt");
cout<<endl<<"Successful...!";
}
}money;
int main()
{
char choice;
cout<<"\n---------LenDen App--------\n";
cout<<"\n1- Login";
cout<<"\n2- Sign-Up";
cout<<"\n3- Exit";
cout<<"\nEnter Your Choice :: ";
cin>>choice;
switch(choice){
case '1':
cin.ignore();
money.logIn();
char c;
cout<<"\n1- Check balance";
cout<<"\n2- Send Money";
cout<<"\nEnter Your Choice :: ";
cin>>c;
cin.ignore();
if(c=='1')
{
money.balance();
}
else
{
money.sent();
}
break;
case '2':
cin.ignore();
money.signUp();
break;
case '3':
return 0;
break;
defualt:
cout<<"Invalid Selection...!";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxmc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIGV4Y2hhbmdlewogICAgcHVibGljOgogICAgc3RyaW5nIG51bSxuYW1lLHBhc3MsY2FzaCxmaW5kTnVtLGZpbmRQYXNzOwogICAgZmxvYXQgYmFsLHNlbnRNb25leTsKICAgIGZzdHJlYW0gZmlsZSxmaWxlXzE7CgogICAgdm9pZCBzaWduVXAoKQogICAgewogICAgICAgIGNvdXQ8PGVuZGw8PCItLS0tLS0tLS0tU0lHTlVQLS0tLS0tLS0tIjw8ZW5kbDsKICAgICAgICBjb3V0PDxlbmRsPDwiRW50ZXIgWW91ciBOYW1lIDogIjsKICAgICAgICBnZXRsaW5lKGNpbixuYW1lKTsKICAgICAgICBjb3V0PDxlbmRsPDwiRW50ZXIgWW91ciBQaG9uZSBOdW1iZXIgOiAiOwogICAgICAgIGdldGxpbmUoY2luLG51bSk7CiAgICAgICAgY291dDw8ZW5kbDw8IkVudGVyIFlvdXIgUGFzc3dvcmQgOiAiOwogICAgICAgIGdldGxpbmUoY2luLHBhc3MpOwoKICAgICAgICBmaWxlLm9wZW4oImxvZ2luRGF0YS50eHQiLGlvcyA6OiBvdXQgfCBpb3MgOjogYXBwKTsKICAgICAgICBmaWxlPDxudW08PCIqIjw8cGFzczw8IioiPDxuYW1lPDwiKjAiPDxlbmRsOwogICAgICAgIGZpbGUuY2xvc2UoKTsKICAgIH0KCiAgICB2b2lkIGxvZ0luKCkKICAgIHsKICAgICAgICBjb3V0PDxlbmRsPDwiLS0tLS0tLS0tLUxPR0lOLS0tLS0tLS0tIjw8ZW5kbDsKICAgICAgICBjb3V0PDxlbmRsPDwiRW50ZXIgWW91ciBQaG9uZSBOdW1iZXIgOiAiOwogICAgICAgIGdldGxpbmUoY2luLGZpbmROdW0pOwogICAgICAgIGNvdXQ8PGVuZGw8PCJFbnRlciBZb3VyIFBhc3N3b3JkIDogIjsKICAgICAgICBnZXRsaW5lKGNpbixmaW5kUGFzcyk7CgogICAgICAgIGZpbGUub3BlbigibG9naW5EYXRhLnR4dCIsaW9zIDo6IGluKTsKICAgICAgICBnZXRsaW5lKGZpbGUsbnVtLCcqJyk7CiAgICAgICAgZ2V0bGluZShmaWxlLHBhc3MsJyonKTsKICAgICAgICBnZXRsaW5lKGZpbGUsbmFtZSwnKicpOwogICAgICAgIGdldGxpbmUoZmlsZSxjYXNoLCdcbicpOwogICAgICAgIGJvb2wgZj10cnVlOwogICAgICAgIHdoaWxlKCFmaWxlLmVvZigpKQogICAgICAgIHsKICAgICAgICAgICAgaWYoZmluZE51bT09bnVtICYmIGZpbmRQYXNzPT1wYXNzKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjb3V0PDxlbmRsPDwiSGVsbG8gIjw8bmFtZTw8ZW5kbDsKICAgICAgICAgICAgICAgIGY9ZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGdldGxpbmUoZmlsZSxudW0sJyonKTsKICAgICAgICAgICAgICAgIGdldGxpbmUoZmlsZSxwYXNzLCcqJyk7CiAgICAgICAgICAgICAgICBnZXRsaW5lKGZpbGUsbmFtZSwnKicpOwogICAgICAgICAgICAgICAgZ2V0bGluZShmaWxlLGNhc2gsJ1xuJyk7CiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGlmKGYpIGNvdXQ8PGVuZGw8PCJJbnZhbGlkIFBhc3N3b3JkIG9yIE51bWJlciI7CiAgICAgICAgZmlsZS5jbG9zZSgpOwoKICAgICAgICBiYWw9c3RvZihjYXNoKTsKICAgIH0KICAgIHZvaWQgYmFsYW5jZSgpCiAgICB7CgogICAgICAgIGNvdXQ8PGVuZGw8PCJZb3VyIEFjY291bnQgQmFsYW5jZSBpcyA6ICI7CiAgICAgICAgcHJpbnRmKCIlLjJmIFRLIixiYWwpOwogICAgfQogICAgdm9pZCBzZW50KCkKICAgIHsKICAgICAgICBzdHJpbmcgcmV2TnVtLHJldk5hbWUscmV2UGFzcyxyZXZDYXNoOwogICAgICAgIGZsb2F0IHJldkJhbDsKICAgICAgICBjb3V0PDxlbmRsPDwiRW50ZXIgUmVjZWl2ZXIgTnVtYmVyIDogIjsKICAgICAgICBnZXRsaW5lKGNpbixyZXZOdW0pOwogICAgICAgIGNvdXQ8PGVuZGw8PCJFbnRlciB0aGUgQW1vdW50IDogIjsKICAgICAgICBjaW4+PnNlbnRNb25leTsKCiAgICAgICAgZmlsZS5vcGVuKCJsb2dpbkRhdGEudHh0Iixpb3MgOjogaW4pOwogICAgICAgIGZpbGVfMS5vcGVuKCJuZXcudHh0Iixpb3MgOjogb3V0IHwgaW9zIDo6IGFwcCk7CgogICAgICAgIGdldGxpbmUoZmlsZSxudW0sJyonKTsKICAgICAgICBnZXRsaW5lKGZpbGUscGFzcywnKicpOwogICAgICAgIGdldGxpbmUoZmlsZSxuYW1lLCcqJyk7CiAgICAgICAgZ2V0bGluZShmaWxlLGNhc2gsJ1xuJyk7CiAgICAgICAgd2hpbGUoIWZpbGUuZW9mKCkpCiAgICAgICAgewogICAgICAgICAgICBpZihmaW5kTnVtPT1udW0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGJhbC09c2VudE1vbmV5OwogICAgICAgICAgICAgICAgY2FzaD10b19zdHJpbmcoYmFsKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKHJldk51bT09bnVtKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICByZXZCYWw9c3RvZihjYXNoKTsKICAgICAgICAgICAgICAgIGNhc2g9dG9fc3RyaW5nKHJldkJhbCtzZW50TW9uZXkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZpbGVfMTw8bnVtPDwnKic8PHBhc3M8PCcqJzw8bmFtZTw8JyonPDxjYXNoPDxlbmRsOwogICAgICAgICAgICBnZXRsaW5lKGZpbGUsbnVtLCcqJyk7CiAgICAgICAgICAgIGdldGxpbmUoZmlsZSxwYXNzLCcqJyk7CiAgICAgICAgICAgIGdldGxpbmUoZmlsZSxuYW1lLCcqJyk7CiAgICAgICAgICAgIGdldGxpbmUoZmlsZSxjYXNoLCdcbicpOwoKICAgICAgICB9CiAgICAgICAgZmlsZS5jbG9zZSgpOwogICAgICAgIGZpbGVfMS5jbG9zZSgpOwoKICAgICAgICByZW1vdmUoImxvZ2luRGF0YS50eHQiKTsKICAgICAgICByZW5hbWUoIm5ldy50eHQiLCJsb2dpbkRhdGEudHh0Iik7CgogICAgICAgIGNvdXQ8PGVuZGw8PCJTdWNjZXNzZnVsLi4uISI7CgogICAgfQoKCn1tb25leTsKCmludCBtYWluKCkKewogICAgY2hhciBjaG9pY2U7CiAgICBjb3V0PDwiXG4tLS0tLS0tLS1MZW5EZW4gQXBwLS0tLS0tLS1cbiI7CiAgICBjb3V0PDwiXG4xLSBMb2dpbiI7CiAgICBjb3V0PDwiXG4yLSBTaWduLVVwIjsKICAgIGNvdXQ8PCJcbjMtIEV4aXQiOwogICAgY291dDw8IlxuRW50ZXIgWW91ciBDaG9pY2UgOjogIjsKICAgIGNpbj4+Y2hvaWNlOwoKICAgIHN3aXRjaChjaG9pY2UpewogICAgICAgIGNhc2UgJzEnOgogICAgICAgICAgICBjaW4uaWdub3JlKCk7CiAgICAgICAgICAgIG1vbmV5LmxvZ0luKCk7CiAgICAgICAgICAgIGNoYXIgYzsKICAgICAgICAgICAgY291dDw8IlxuMS0gQ2hlY2sgYmFsYW5jZSI7CiAgICAgICAgICAgIGNvdXQ8PCJcbjItIFNlbmQgTW9uZXkiOwogICAgICAgICAgICBjb3V0PDwiXG5FbnRlciBZb3VyIENob2ljZSA6OiAiOwogICAgICAgICAgICBjaW4+PmM7CiAgICAgICAgICAgIGNpbi5pZ25vcmUoKTsKICAgICAgICAgICAgaWYoYz09JzEnKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBtb25leS5iYWxhbmNlKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBtb25leS5zZW50KCk7CiAgICAgICAgICAgIH0KICAgICAgICBicmVhazsKICAgICAgICBjYXNlICcyJzoKICAgICAgICAgICAgY2luLmlnbm9yZSgpOwogICAgICAgICAgICBtb25leS5zaWduVXAoKTsKICAgICAgICBicmVhazsKICAgICAgICBjYXNlICczJzoKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmdWFsdDoKICAgICAgICAgICAgY291dDw8IkludmFsaWQgU2VsZWN0aW9uLi4uISI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==