fork download
  1. #include <iostream>
  2. #include<fstream>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. class exchange{
  8. public:
  9. string num,name,pass,cash,findNum,findPass;
  10. float bal,sentMoney;
  11. fstream file,file_1;
  12.  
  13. void signUp()
  14. {
  15. cout<<endl<<"----------SIGNUP---------"<<endl;
  16. cout<<endl<<"Enter Your Name : ";
  17. getline(cin,name);
  18. cout<<endl<<"Enter Your Phone Number : ";
  19. getline(cin,num);
  20. cout<<endl<<"Enter Your Password : ";
  21. getline(cin,pass);
  22.  
  23. file.open("loginData.txt",ios :: out | ios :: app);
  24. file<<num<<"*"<<pass<<"*"<<name<<"*0"<<endl;
  25. file.close();
  26. }
  27.  
  28. void logIn()
  29. {
  30. cout<<endl<<"----------LOGIN---------"<<endl;
  31. cout<<endl<<"Enter Your Phone Number : ";
  32. getline(cin,findNum);
  33. cout<<endl<<"Enter Your Password : ";
  34. getline(cin,findPass);
  35.  
  36. file.open("loginData.txt",ios :: in);
  37. getline(file,num,'*');
  38. getline(file,pass,'*');
  39. getline(file,name,'*');
  40. getline(file,cash,'\n');
  41. bool f=true;
  42. while(!file.eof())
  43. {
  44. if(findNum==num && findPass==pass)
  45. {
  46. cout<<endl<<"Hello "<<name<<endl;
  47. f=false;
  48. break;
  49. }
  50. else
  51. {
  52. getline(file,num,'*');
  53. getline(file,pass,'*');
  54. getline(file,name,'*');
  55. getline(file,cash,'\n');
  56. }
  57.  
  58. }
  59. if(f) cout<<endl<<"Invalid Password or Number";
  60. file.close();
  61.  
  62. bal=stof(cash);
  63. }
  64. void balance()
  65. {
  66.  
  67. cout<<endl<<"Your Account Balance is : ";
  68. printf("%.2f TK",bal);
  69. }
  70. void sent()
  71. {
  72. string revNum,revName,revPass,revCash;
  73. float revBal;
  74. cout<<endl<<"Enter Receiver Number : ";
  75. getline(cin,revNum);
  76. cout<<endl<<"Enter the Amount : ";
  77. cin>>sentMoney;
  78.  
  79. file.open("loginData.txt",ios :: in);
  80. file_1.open("new.txt",ios :: out | ios :: app);
  81.  
  82. getline(file,num,'*');
  83. getline(file,pass,'*');
  84. getline(file,name,'*');
  85. getline(file,cash,'\n');
  86. while(!file.eof())
  87. {
  88. if(findNum==num)
  89. {
  90. bal-=sentMoney;
  91. cash=to_string(bal);
  92. }
  93. else if(revNum==num)
  94. {
  95. revBal=stof(cash);
  96. cash=to_string(revBal+sentMoney);
  97. }
  98. file_1<<num<<'*'<<pass<<'*'<<name<<'*'<<cash<<endl;
  99. getline(file,num,'*');
  100. getline(file,pass,'*');
  101. getline(file,name,'*');
  102. getline(file,cash,'\n');
  103.  
  104. }
  105. file.close();
  106. file_1.close();
  107.  
  108. remove("loginData.txt");
  109. rename("new.txt","loginData.txt");
  110.  
  111. cout<<endl<<"Successful...!";
  112.  
  113. }
  114.  
  115.  
  116. }money;
  117.  
  118. int main()
  119. {
  120. char choice;
  121. cout<<"\n---------LenDen App--------\n";
  122. cout<<"\n1- Login";
  123. cout<<"\n2- Sign-Up";
  124. cout<<"\n3- Exit";
  125. cout<<"\nEnter Your Choice :: ";
  126. cin>>choice;
  127.  
  128. switch(choice){
  129. case '1':
  130. cin.ignore();
  131. money.logIn();
  132. char c;
  133. cout<<"\n1- Check balance";
  134. cout<<"\n2- Send Money";
  135. cout<<"\nEnter Your Choice :: ";
  136. cin>>c;
  137. cin.ignore();
  138. if(c=='1')
  139. {
  140. money.balance();
  141. }
  142. else
  143. {
  144. money.sent();
  145. }
  146. break;
  147. case '2':
  148. cin.ignore();
  149. money.signUp();
  150. break;
  151. case '3':
  152. return 0;
  153. break;
  154. defualt:
  155. cout<<"Invalid Selection...!";
  156. }
  157. return 0;
  158. }
Success #stdin #stdout 0s 5276KB
stdin
3
stdout
---------LenDen App--------

1- Login
2- Sign-Up
3- Exit
Enter Your Choice ::