View Single Post
Join Date: Apr 2008
Posts: 1
Reputation: alexdm50 is an unknown quantity at this point 
Solved Threads: 0
alexdm50 alexdm50 is offline Offline
Newbie Poster

help with c++ coursework - code so far included.

 
0
  #1
Nov 21st, 2008
hi im new to daniweb im currently working on a piece of work. the idea is to create a bank account with deposit and withdrawal functions. create student business and current accounts (this is all roughly done and a case of copying and pasting for each account type with a different set of questions) . what it requires me to do is allow 10 accounts to be opened and then allow the user to search for each one and deposit and withdraw from each one. would anyone have any suggestions on how i could do this. below is my code so far and thankyou for taking the time to look. also it requires me to take an object orientated approach and im rather confused what this entails, any suggestions again would be appreciated.

1st - BANK.CPP

  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. // Declare Variables
  9. int withdraw;
  10. int sqone;
  11. int sqtwo;
  12. int bone;
  13. string colname;
  14. string name;
  15. string sname;
  16. int housenumber;
  17. string postcode;
  18. string dob;
  19. string telno;
  20. double acctbalance, deposit;
  21. char choices;
  22. acctbalance = 0;
  23.  
  24. //inputs, get the name and initial balance
  25.  
  26.  
  27. do
  28. {
  29. cout<<"\n\n-------------------------------------------------\n";
  30. cout << "What do you wish to do?" << endl;
  31. cout << "O open new account" << endl;
  32. cout << "C open new Business account" << endl;
  33. cout << "D Deposit Money" << endl;
  34. cout << "W Withdraw Money" << endl;
  35. cout << "B Display Balance" << endl;
  36. cout << "P Bank Account Details" << endl;
  37. cout << "Q Quit" << endl<<endl;cout<<"Enter selection: ";
  38. cin >> choices;
  39. switch (choices)
  40. {
  41. //add account type options here under letter O
  42. case 'O':
  43. case 'o':
  44. {
  45. {
  46. cout<<"\n\n-------------------------------------------------\n";
  47. cout << "What Account Do You Wish To Open?" << endl;
  48. cout << "S Student Account" << endl;
  49. cout << "C Current Account" << endl;
  50. cout << "B Business Account" << endl;
  51. cout<<"Enter selection: ";
  52. cin >> choices;
  53. break;// Need a break statement here
  54. }
  55. }
  56.  
  57.  
  58.  
  59. //STUDENT ACCOUNT
  60. case 'S':
  61. case 's':
  62. {
  63. cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
  64. cout<<"---------------------------------------------------------"<<endl;
  65. cout<<"Are You A Full Time Student?"<<endl;
  66. cin>>sqone;
  67. if (sqone == 0)
  68. {
  69. cout << "sorry that is not a valid option"<< endl;
  70. break;
  71. }
  72. if (sqone == 2)
  73. {
  74. cout<<"Sorry You Are Not Valid For This Account"<<endl;
  75. break;
  76. }
  77. else if (sqone == 1)
  78. {
  79. cout<<"Thankyou"<<endl;
  80. cout<<"Have You Got Documentation To Support Your Course And Accomadation?"<<endl;
  81. cin>>sqtwo;
  82. if (sqtwo == 0)
  83. {
  84. cout << "sorry that is not a valid option"<< endl;
  85. break;
  86. }
  87. if (sqtwo == 1)
  88. {
  89. cout<<"Thankyou you are elegible for this account"<<endl;
  90. cout<<"------------------------------------------"<<endl;
  91. cout << "Colleague Name: ";
  92. cin >> colname;
  93. cout << "Enter First Name: ";
  94. cin >> name;
  95. cout << "Enter Surname: ";
  96. cin >> sname;
  97. cout << "House Number: ";
  98. cin >> housenumber;
  99. cout << "Post Code: ";
  100. cin >> postcode;
  101. cout << "Date Of Birth: ";
  102. cin >> dob;
  103. cout << "Telephone Number: ";
  104. cin >> telno;
  105. cout << "Please enter initial balance: ";
  106. cin >> acctbalance;
  107. break;
  108.  
  109.  
  110. }
  111. else if (sqtwo == 2)
  112. {
  113. cout<<"Sorry You Are Not Valid For This Account"<<endl;
  114. break;
  115. }
  116.  
  117.  
  118.  
  119. //BUSINESS ACCOUNT
  120. case 'c':
  121. case 'C':
  122. {
  123. cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
  124. cout<<"---------------------------------------------------------"<<endl;
  125. cout<<"Have you got documentation showing your business details?"<<endl;
  126. cin>>bone;
  127. if (bone == 0)
  128. {
  129. cout << "sorry that is not a valid option"<< endl;
  130. break;
  131. }
  132. if (bone == 2)
  133. {
  134. cout<<"Sorry You Are Not Valid For This Account"<<endl;
  135. break;
  136. }
  137. if (bone == 1)
  138. {
  139.  
  140. cout<<"We Will Now Proceed To Open This Account For You?"<<endl;
  141. cout<<"------------------------------------------"<<endl;
  142. cout << "Colleague Name: ";
  143. cin >> colname;
  144. cout << "Enter First Name: ";
  145. cin >> name;
  146. cout << "Enter Surname: ";
  147. cin >> sname;
  148. cout << "House Number: ";
  149. cin >> housenumber;
  150. cout << "Post Code: ";
  151. cin >> postcode;
  152. cout << "Date Of Birth: ";
  153. cin >> dob;
  154. cout << "Telephone Number: ";
  155. cin >> telno;
  156. cout << "Please enter initial balance: ";
  157. cin >> acctbalance;
  158. break;
  159.  
  160.  
  161. }
  162. else if (sqtwo == 2)
  163. {
  164. cout<<"Sorry You Are Not Valid For This Account"<<endl;
  165. break;
  166. }
  167. }
  168. }
  169. }
  170.  
  171.  
  172.  
  173. case 'D':
  174. case 'd':
  175. {
  176. cout << "Enter amount to be deposited: "<< endl;
  177. cin >>deposit;
  178. if (deposit > 0)
  179. {
  180. acctbalance = acctbalance + deposit;
  181. if (deposit >= 10000)
  182. cout <<"Big Money!"<<endl;
  183. break;
  184. }
  185. if (deposit == 0 || deposit < 0)
  186. {
  187. cout <<"Amount must be greater than 0";
  188. break ;
  189. }
  190. }
  191. case 'B':
  192. case 'b':
  193. {
  194. cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
  195. if (acctbalance ==0)
  196. cout <<"Big Money!"<<endl;
  197. break;
  198. }
  199. case 'W':
  200. case 'w':
  201. {
  202. cout<<"Please enter amount to withdraw "<<endl;
  203. cout<<"Withdrawal must be multiple of 10"<<endl;
  204. cin>>withdraw;
  205. if (withdraw == 00)
  206. {
  207. cout << "Can't withdraw 0 dollars"<< endl;
  208. break;
  209. }
  210. if (withdraw < 0)
  211. {
  212. cout<<"Must be a positive number"<<endl;
  213. break;
  214. }
  215. if (withdraw > acctbalance)
  216. {
  217. cout<<"Can't withdraw more than balance"<<endl;
  218. break;
  219. }
  220. if ((withdraw % 10) !=0)
  221. {
  222. cout<<"amount must be a multiple of 20"<<endl;
  223. break;
  224. }
  225. else
  226. {
  227. acctbalance=acctbalance - withdraw;
  228. cout<<"Here is your money. Enjoy!"<< endl;
  229. break;
  230. }
  231. case 'P':
  232. case 'p':
  233. {
  234. cout << "\n\n"<<endl;
  235. cout <<"Personal Details"<<endl;
  236. cout <<"First Name : "<<name<<endl;
  237. cout <<"Surname : " <<sname<<endl;
  238. cout <<"house number : " <<housenumber<<endl;
  239. cout <<"post code : " <<postcode<<endl;
  240. cout <<"telephone number : " <<telno<<endl;
  241.  
  242. cout <<"Your current balance is £ "<<acctbalance<<'.'<<endl;
  243. if (acctbalance ==0)
  244. cout <<"Big Money!"<<endl;
  245. break;
  246. }
  247. }
  248.  
  249. case 'Q':
  250. case 'q':
  251. {
  252. cout<<"Thank for using our services have a nice day!"<<endl;
  253. break;
  254. }
  255. }
  256. }while (choices != 'q' && choices != 'Q');
  257. return 0;
  258. }

and the 2nd class - account.h
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Account
  7. {
  8. double money; // amount of money held by this account
  9. double interestRate; // a monthly or yearly interestrate, depending on how the account is to be used.
  10.  
  11.  
  12. public:
  13.  
  14. // create an account with an initial amountand a specified interest rate
  15. Account(double amount, double percent)
  16. {
  17. money = amount;
  18. interestRate = percent;
  19. }
  20.  
  21. // return the account's balance
  22. double balance()
  23. {
  24. return money;
  25. }
  26.  
  27. // add money to the account
  28. void deposit(double amount)
  29. {
  30. money += amount;
  31. }
  32.  
  33. // substract money from the account
  34. void withdraw(double amount)
  35. {
  36.  
  37. }
  38.  
  39. // add money according to the interest rate.
  40. void addInterest()
  41. {
  42. money *= (1 + interestRate/100.0);
  43.  
  44. }
  45.  
  46. };

thankyou again
Reply With Quote