By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,498 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,498 IT Pros & Developers. It's quick & easy.

How to use delete in string in c++ With using class (delete information)

P: 2
Hi, friends:

This is my programme (work on Microsoft visual c++) and I have two question .

First, I want to say that there is no error but I need a little help.

This is a small programme about Bank :


it's work but my question is (about 6-closing account) on function closing account....
.....How could I delete the information in this function to close account by using string (I know how to delete in pointer,but
here I don't use pointer ,I want to use string) should I make it zero's (but I don't think so )
...I really need a help........

Please Help




and I have another question but not importante like the first one , that if I want to use two class in the
programme not one class , I'll make it class Bank (which have making new account & closing account & Zakat account) and the
other class is class account (which have the deposit & the withdrawal & the display of information for just one account)


Expand|Select|Wrap|Line Numbers
  1.  #include <iostream> 
  2. #include <string> //Must include this to use class string 
  3.  
  4. using namespace std; 
  5. class account 
  6. private: 
  7. //int size; 
  8. //int customer; 
  9. string firstname,lastname,name; 
  10. double accountbalance,amount1,amount2; 
  11. int index; 
  12.  
  13. double zakat1,zakat; 
  14. int num,i,month; 
  15. /*static*/ int counter; 
  16.  
  17.  
  18. public: 
  19.  
  20. account(){index=1;counter=0;cout<<"account constructor\n";} 
  21. void newaccount(); 
  22. void closeaccount(); 
  23. void calzakat(); 
  24. ~account(){cout<<"account destrurctor\n";} 
  25. void depositing(); 
  26. void withdrawal(); 
  27. void displayaccount(); 
  28. }; 
  29. //static int bank::counter=0; 
  30. void account::newaccount() 
  31. cout<<"enter the customer firstname,lastname,account balance\n"; 
  32. //customer=index; 
  33. cin>>firstname; 
  34. cin>>lastname; 
  35. name=firstname+lastname; 
  36. cin>>accountbalance; 
  37. index++; 
  38. counter++; 
  39. void account::closeaccount() 
  40. //name=' '; 
  41. accountbalance=00.00; 
  42. counter--; 
  43. /* 
  44. for(int y=0;y<index;y++) 
  45. if((y==num)||(y>num)) 
  46. customer[y]=customer[y+1]; 
  47. name[y]=name[y+1]; 
  48. accountbalance[y]=accountbalance[y+1]; 
  49. customer[size-1]; 
  50. name[size-1]; 
  51. accountbalance[size-1];*/ 
  52. void account::calzakat() 
  53. cout<<"enter how many month is ago from last deposite money in the account th to calculate zakat\n"; 
  54. cin>>month; 
  55. if((accountbalance>4000)&&(month>12)) 
  56. zakat1=((accountbalance*2.5)/100); 
  57. accountbalance=accountbalance-zakat1; 
  58. cout<<" the name of the customer "<<name; 
  59. cout<<" the account balance "<<accountbalance<<"\n"<<"the zakat is\n"<<zakat1<<"\n"; 
  60. else 
  61. zakat1=00.00; 
  62. cout<<" the name of the customer "<<name; 
  63. cout<<" the account balance "<<accountbalance<<"\n"<<zakat1<<"\n"; 
  64. zakat=zakat+zakat1; 
  65.  
  66.  
  67.  
  68.  
  69.  
  70. void account::depositing() 
  71. cout<<"enter the amount you want to depositing\n"; 
  72. cin>>amount1; 
  73. accountbalance=accountbalance+amount1; 
  74. cout<<"the account balance after the depositing\n"<<accountbalance; 
  75. void account::withdrawal() 
  76.  
  77. cout<<"enter the amount you want to withdrawal\n"; 
  78. cin>>amount2; 
  79. if (amount2<=accountbalance) 
  80. accountbalance=accountbalance-amount2; 
  81. cout<<"the account balance after withdrawal from it\n"; 
  82. cout<<accountbalance; 
  83. else 
  84. cout<<"sorry..the account is less than the amount you want to withdrawal\n"; 
  85.  
  86.  
  87. void account::displayaccount() 
  88. cout<<"the name of customer is\n"<<name<<"\nthe account balance is\n"<<accountbalance<<"\n"; 
  89.  
  90.  
  91. int main() 
  92. int choice,accountnum,x; 
  93. account ob[3]; 
  94.  
  95. do 
  96. cout<<"enter your choice\n"; 
  97. cout<<"1-Opening a new account for a customer\n"; 
  98. cout<<"2-deposit to the account\n"; 
  99. cout<<"3-withdrawal from the account\n"; 
  100. cout<<"4-Zakat calculate and debits the account zakat\n"; 
  101. cout<<"5-display the information of account\n"; 
  102. cout<<"6-closing an account\n"; 
  103. cout<<"7-display all account information\n"; 
  104. cout<<"8-exit\n"; 
  105. cin>>choice; 
  106. switch(choice) 
  107. case 1: 
  108.  
  109. cout<<"enter the account number from 0 to 14\n"; 
  110. cin>>accountnum; 
  111. x=accountnum; 
  112. cout<<"the account has the number "<<x; 
  113. ob[accountnum].newaccount(); 
  114. break; 
  115. case 2: 
  116. cout<<"enter the account number from 0 to 14 to depositing it\n"; 
  117. cin>>accountnum; 
  118. x=accountnum; 
  119. cout<<"the account has the number "<<x; 
  120. ob[accountnum].depositing(); 
  121. break; 
  122. case 3: 
  123. cout<<"enter the account number from 0 to 14 to withdrawal from it\n"; 
  124. cin>>accountnum; 
  125. x=accountnum; 
  126. cout<<"the account has the number "<<x; 
  127. ob[accountnum].withdrawal(); 
  128. break; 
  129. case 4: 
  130. cout<<"enter the account number from 0 to 14 to calculate zakat to it\n"; 
  131. cin>>accountnum; 
  132. x=accountnum; 
  133. cout<<"the account has the number "<<x; 
  134. ob[accountnum].calzakat(); 
  135. break; 
  136. case 5: 
  137. cout<<"enter the account number from 0 to 14 to display it\n"; 
  138. cin>>accountnum; 
  139. x=accountnum; 
  140. cout<<" the account that has the number "<<x; 
  141. ob[accountnum].displayaccount(); 
  142. break; 
  143. case 6: 
  144. cout<<"enter the account number from 0 to 14 to close it\n"; 
  145. cin>>accountnum; 
  146. x=accountnum; 
  147. cout<<"the account has the number "<<x; 
  148. ob[accountnum].closeaccount(); 
  149. break; 
  150. case 7: 
  151. int i; 
  152. for(i=0;i<3;i++) 
  153. cout<<"the zakat of the account that has the number "<<i; 
  154. ob[i].displayaccount(); 
  155. break; 
  156. case 8: 
  157. cout<<"the exit\n"; 
  158. break; 
  159. default: 
  160. cout<<"invalid choice\n"; 
  161. break; 
  162. }//end switch 
  163. }//end while 
  164. while(choice!=8); 
  165. return 0; 
  166.  
Thank you all very much..........I hope if any one can help me ..
..........I need it tomorrow .... :o
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: 2
thanks i solved it with flag
Nov 22 '05 #2

P: 1
memosa is there any chance to post your solution...
I have th same problem and i have to give my work yesterday...

The code works in the same way in c++??
Feb 10 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.