check this code pleeeeeeeeeease

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

check this code pleeeeeeeeeease

 
0
  #1
Dec 12th, 2005
hi every please i need your expriment to help to complete this code my problem is with three functions i think so there is no errors
the funcions are
display account...>does not work just display name
transection...>it count jyst one time
standing order...>i do not know how to compare the date the customer enter with the local time

here is the code
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <conio.h>
  5. #include<ctime>
  6. #include<math.h> //Cos,Sin
  7. #include<stdlib.h> //itoa
  8. #include<string.h> //strcpy,strcat,strlen
  9.  
  10. using std::fixed;
  11.  
  12. using namespace::std;
  13.  
  14. /////////ACCOUNT///////////////////////////////
  15. class Account
  16. {
  17.  
  18. string name;
  19. string AccNum;
  20. double balance;
  21. string AccType;
  22. double transfer;
  23.  
  24. public:
  25.  
  26. Account();//defalt constructor
  27.  
  28. void setName(string n);//enter customer's name
  29. string getName();//return customer's name
  30.  
  31. void setNum(string n);//enter account's number
  32. string getNum();//return account's number
  33.  
  34. void setbalance(double bal);//enter customer's balance
  35. double getbalance();//return account's balance
  36.  
  37. void settype(string T);
  38. string gettype();
  39.  
  40. void withdraw(double amount);
  41. void deposit (double amount);
  42. double zakat();//calculate customer's zakat
  43.  
  44. void disolayaccount();//display account info
  45. friend int gettime (){
  46. struct tm *ptr;
  47. time_t lt;
  48. lt=time('\0');
  49. ptr=localtime(&lt);
  50. cout<<asctime(ptr);
  51. return 0;
  52.  
  53. }
  54.  
  55.  
  56. };
  57.  
  58. ///////////////////////BANK//////////////////////////////
  59.  
  60. class Bank
  61. {
  62.  
  63.  
  64. vector<Account *> Accs; //A vector of account pointers
  65. double Newbalance;
  66.  
  67. string accnum;
  68. string name;
  69. string acctype;
  70. double OpeningBalance;
  71. double transfer;
  72. public:
  73.  
  74. void DisplayAllAccounts();//display all accounts info
  75.  
  76. void OpenAccount();//open new acount
  77.  
  78. void CloseAccount(); //close an account
  79.  
  80. int FindAccountbyNumber(string accnum);
  81. //search for an aaccount by account's number
  82. //Returns the index for the account having this number
  83.  
  84. void Standing_Order();
  85. int transactions();
  86. void Withdraw();
  87. void Deposit();
  88. void ShowAccount();
  89.  
  90. };// end of bank
  91.  
  92.  
  93. //////////////////TRANSACTIONS/////////////////////////////
  94. int Bank::transactions()
  95. {
  96. int acount_d=0;int acount=0;int count=0;
  97.  
  98. Deposit();
  99. Withdraw();
  100. acount_d=acount_d+1;
  101. cout << "\nTotal Deposits: " << acount_d<<endl;
  102. acount=acount+1;
  103. cout << "\nTotal Withdraw: " << acount<<endl;
  104. count=acount_d+acount;
  105. cout<<"count="<<count;
  106. return 0;
  107. }
  108.  
  109. //////////////////STANDING ORDER/////////////////////////////
  110. void Bank::Standing_Order()
  111. {
  112.  
  113.  
  114. int sec, min, hr; //Store time
  115.  
  116. gettime (); //Get time
  117. //Get Date
  118. char strhr[5] = "",strmin[5] = "",strsec[5] = "";//Store date.
  119.  
  120. char strdate[30];
  121. //Select day of Month
  122. char strday[][3]={"01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
  123. "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
  124. "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
  125. //Select month of Year
  126. char strmonth[][10]={"January", "February", "March", "April", "May", "June",
  127. "July", "August", "September", "October", "November", "December"};
  128. char stryr[5] = "";//Store year
  129. //Select day of Week
  130. char strwday[][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  131.  
  132.  
  133.  
  134. while( ! kbhit() ){
  135.  
  136.  
  137.  
  138.  
  139. itoa (hr, strhr, 10); //Get hours in a string
  140. if( strlen (strhr) == 1) //Make it a string having len = 2
  141. {
  142. strhr[2] = '\0';
  143. strhr[1] = strhr[0];
  144. strhr[0] = '0';
  145. }
  146. itoa (min, strmin, 10);//Get minutes in a string
  147. if( strlen (strmin) == 1) //Make it a string having len = 2
  148. {
  149. strmin[2] = '\0';
  150. strmin[1] = strmin[0];
  151. strmin[0] = '0';
  152. }
  153. itoa (sec, strsec, 10);//Get seconds in a string
  154. if( strlen (strsec) == 1) //Make it a string heving len = 2
  155. {
  156. strsec[2] = '\0';
  157. strsec[1] = strsec[0];
  158. strsec[0] = '0';
  159. }
  160.  
  161.  
  162. }
  163. /*cout<<"enter the date"<<endl;
  164. cin>>day>>month>>yr;*/
  165. }
  166.  
  167. /////////////////DEFAULT CONSTRUCTOR////////////////////////
  168.  
  169. Account::Account()
  170. {
  171. name="\0";
  172. AccNum="\0";
  173. AccType="\0";
  174. balance=0.0;
  175. transfer=0;
  176. };
  177.  
  178. ///////////////////SET NAME///////////////////
  179.  
  180. void Account::setName(string n)
  181. {
  182. name=n;
  183. }
  184.  
  185. //////////////////SET ACCOUNT NUMBER///////////
  186.  
  187. void Account::setNum(string n)
  188. {
  189. AccNum=n;
  190. }
  191.  
  192. //////////////////SET BALANCE////////////////
  193.  
  194. void Account::setbalance(double bal)
  195. {
  196. balance=bal;
  197. }
  198.  
  199. ///////////////////SET TYPE////////////////
  200.  
  201. void Account::settype(string T)
  202. {
  203. AccType=T;
  204. }
  205.  
  206. //////////////////GET TYPE//////////////////
  207.  
  208. string Account::gettype()
  209. {
  210. return AccType;
  211. }
  212.  
  213. ///////////////////GET NAME////////////////
  214.  
  215. string Account::getName()
  216. {
  217. return name;
  218. }
  219.  
  220. /////////////GET ACCOUNT NUMBER////////////
  221.  
  222. string Account::getNum()
  223. {
  224. return AccNum;
  225. }
  226.  
  227. ///////////////GET BALANCE////////////////
  228.  
  229. double Account::getbalance()
  230. {
  231. return balance;
  232. }
  233.  
  234. ////////////////WITHDRAW//////////////////
  235.  
  236. void Account::withdraw(double amount)
  237. {
  238. int acount=0;
  239. if (AccType=="PERSONAL")
  240. {
  241. balance=balance-amount;
  242. setbalance(balance);
  243. }
  244.  
  245.  
  246. if (AccType=="COMPANY")
  247. {
  248. balance=balance-amount-0.05;
  249. setbalance(balance);
  250. }
  251.  
  252. acount=acount+1;
  253. cout << "\nTotal Withdraw: " << acount;
  254. }
  255.  
  256.  
  257. //////////////DEPOSTE///////////////////
  258.  
  259. void Account::deposit(double amount)
  260. {
  261. int acount_d=0;
  262. if (AccType=="personal")
  263. {
  264. balance=balance+amount;
  265. setbalance(balance);
  266. }
  267.  
  268. if (AccType=="company")
  269. {
  270. balance=balance+amount-0.05;
  271. setbalance(balance);
  272. }
  273.  
  274. acount_d=acount_d+1;
  275. cout << "\nTotal Deposits: " << acount_d;
  276. }
  277.  
  278.  
  279.  
  280.  
  281. /////////////FIND ACCOUNT//////////////
  282.  
  283. int Bank::FindAccountbyNumber(string accnum)
  284. {
  285.  
  286. for (int j=0;j<Accs.size();j++)
  287. {
  288. if (Accs[j]->getNum() == accnum)
  289.  
  290. return j;
  291. }
  292. return -1;
  293. }
  294.  
  295.  
  296. ////////////DisplayAllAccounts//////////////
  297.  
  298. void Bank::DisplayAllAccounts()
  299. {
  300. int i;
  301.  
  302. cout<<"ENTER THE NUMBER OF ACCOUNT YOU WANT TO DISPLAY: ";
  303. cin>>accnum;
  304. cout<<"\nname:"<<name<<endl;
  305. if (i != -1)
  306. Newbalance = Accs[i]->getbalance();
  307.  
  308. cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
  309. }
  310. /************(BANK)*************************/
  311. /////////////OPEN NEW ACCOUNT////////////////
  312. void Bank::OpenAccount()
  313. {
  314.  
  315. int i=0;
  316.  
  317. cout<<"ENTER CUSTOMER NAME: ";
  318. cin>>name;
  319. //Accs[i]->setName(name);
  320.  
  321. cout<<"ENTER CUSTOMER BALANCE: ";
  322. cin>>OpeningBalance;
  323. //Accs[i]->setbalance(OpeningBalance);
  324.  
  325. cout<<"ENTER ACCOUNT'S NUMBER: ";
  326. cin>>accnum;
  327. //Accs[i]->setNum(accnum);
  328.  
  329. cout<<"ENTER ACCOUNT TYPE (PERSONAL OR COMPANY): ";
  330. cin>>acctype;
  331. //Accs[i]->settype(acctype);
  332.  
  333. Accs.push_back(new Account);
  334. }
  335.  
  336. ////////////CLOSE ACCOUNT///////////////////////
  337.  
  338. void Bank::CloseAccount()
  339. {
  340. int i;
  341.  
  342. string accnum;
  343. cout<<"ENTER THE NUMER OF ACCOUNT's YOU WANT TO CLOSE: ";
  344. cin>>accnum;
  345.  
  346. i = FindAccountbyNumber(accnum);
  347.  
  348. if (i != -1)
  349. {
  350. vector<Account *>::iterator p = Accs.begin();
  351. p +=i;//gives the indix of this account
  352. delete Accs[i];//closing account
  353. Accs.erase(p,p+1);
  354. }
  355. }
  356.  
  357. /////////////////WITHDRAW//////////////////////
  358.  
  359. void Bank::Withdraw()
  360. {
  361. int i;
  362. int acount=0;
  363.  
  364. string accnum;
  365. double amount, Newbalance;
  366. cout<<"ENTER THE NUMBER OF ACCOUNT YOU WANT TO WITHDRAW FROM: ";
  367. cin>>accnum;//the account number from the user
  368.  
  369. cout<<"HOW MANY HE SHE WANT TO WITHDRAW? ";
  370. cin>>amount;//the amount to be withdrawn
  371.  
  372. //check amounts
  373. if (amount > OpeningBalance) {
  374. Accs[i]->setbalance(OpeningBalance);
  375. cout << "Sorry, your account only has $" << OpeningBalance << " dollars\n";}
  376.  
  377. i = FindAccountbyNumber(accnum);
  378. if (i != -1)
  379. {
  380. Accs[i]->withdraw(amount);
  381. //Get the current balancel
  382. Newbalance = Accs[i]->getbalance();
  383. cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
  384.  
  385. }
  386. //transfer = transfer - amount;
  387. acount=acount+1;
  388. cout << "\nTotal Withdraw: " << acount;
  389. }
  390. ////////////////DEPOSITE////////////////////////
  391. void Bank::Deposit(){
  392. int i;
  393. int acount_d=0;
  394.  
  395. char ch;
  396.  
  397. double amount, Newbalance;
  398.  
  399. cout<<"ENTER THE ACCOUNT S NUMBER YOU WANT TO DEPOSE TO: ";
  400. cin>>accnum;//the account number from the user
  401.  
  402. cout<<"HOW MANY HE/SHE WANT TO DEPOSE? ";
  403. cin>>amount;//the amount to be depsite
  404.  
  405. i = FindAccountbyNumber(accnum);
  406.  
  407. if (i != -1)
  408. {
  409. Accs[i]->deposit(amount);
  410. //Get the current balance
  411.  
  412. Newbalance = Accs[i]->getbalance();
  413. //Newbalance = balance+amount;
  414. cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
  415.  
  416. acount_d=acount_d+1;
  417. cout << "\nTotal Deposits: " << acount_d;
  418. cout<<"do you want to deposit another amount(y/n)"<<endl;
  419. cin>>ch;
  420. if(ch=='y')
  421. exit(1);
  422. }
  423.  
  424. }
  425.  
  426. //transfer =transfer + amount;
  427. //////////////Display///////////////////////////
  428. void Bank::ShowAccount()
  429. {
  430. int i;
  431.  
  432. cout<<"ENTER THE NUMBER OF ACCOUNT YOU WANT TO DISPLAY: ";
  433. cin>>accnum;
  434. cout<<"\nname:"<<name<<endl;
  435. if (i != -1)
  436. //Newbalance = Accs[i]->getbalance();
  437.  
  438. cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
  439. }
  440.  
  441.  
  442. ///////////////////////MAIN/////////////////////////
  443. void main()
  444. {
  445. Bank b;
  446.  
  447. char choice;
  448.  
  449.  
  450. bool flag =0;
  451. while (flag == false) {
  452. cout << "\t\t\n\n" << "Main Menu";
  453. cout << "\t\n\n" << "Select by letter:";
  454. cout << "\t\n" << "o - open new account.";
  455. cout << "\t\n" << "d - Deposit money.";
  456. cout << "\t\n" << "w - Withdraw money.";
  457. cout << "\t\n" << "v - Show Account Information.";
  458. cout<<"\t\n"<<"t- transiction";
  459. cout<<"\t\n"<<"s- standing order";
  460. cout << "\t\n" << "c _ close account.";
  461. cout << "\t\n" << "q - Quit Application.\n\n";
  462. cout << "\t" << "Choice: ";
  463. cin>>choice ;
  464. // END OF THE MENU
  465. cout<<fixed;
  466. switch(choice) {
  467. case 'o':
  468. system("cls");
  469. b.OpenAccount();
  470.  
  471. break;
  472.  
  473. case 'd':
  474. system("cls");
  475.  
  476. b.Deposit();
  477.  
  478. break;
  479.  
  480. case 'w':
  481. system("cls");
  482.  
  483. b.Withdraw();
  484.  
  485. system("cls");
  486. break;
  487. case 'v':
  488. system("cls");
  489.  
  490. b.DisplayAllAccounts();
  491. getche();
  492. system("cls");
  493.  
  494. break;
  495. case 't':
  496. system("cls");
  497.  
  498. b.transactions();
  499.  
  500. getche();
  501. break;
  502. case 's':
  503. system("cls");
  504.  
  505. b.Standing_Order();
  506.  
  507. getche();
  508. break;
  509.  
  510.  
  511. case 'c':
  512. system("cls");
  513.  
  514. b.CloseAccount();
  515.  
  516. system("cls");
  517. break;
  518.  
  519. case 'q':
  520. flag = 1;
  521. break;
  522.  
  523. default:
  524. cout << "\nInvalid selection. Press a key to return to main menu.";
  525.  
  526. }
  527.  
  528. if (flag == true) {
  529. break;
  530. }
  531.  
  532. }
  533.  
  534.  
  535. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: check this code pleeeeeeeeeease

 
0
  #2
Dec 13th, 2005
please help me please
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: check this code pleeeeeeeeeease

 
0
  #3
Dec 13th, 2005
If you'd posted a normal topic line someone'd likely have come along already.
As it is I'm disinclined to even try, I only dropped in to kill some time

You state yourself there are no errors, so I wonder what the problem is?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: check this code pleeeeeeeeeease

 
0
  #4
Dec 13th, 2005
hi jwenting there is no compiler error i think there is some think logical that why some function didn't work as expected
display just show the name without balance
transection count the operator just one time
standing order i don't know how to compare the time the user insert with the local time

that's it
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,625
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: check this code pleeeeeeeeeease

 
0
  #5
Dec 13th, 2005
Originally Posted by some one
i do not know how to compare the date the customer enter with the local time
use the struct tm and associated functions that are in time.h. get local time in time_t (an unsigned int) -- time() function returns that. Then convert the time string the user enters into struct tm, you will have to parse the string and apply its individual parts to the structure. After you have done that, call mktime() to convert struct tm into time_t. Now all you have to do is compare the two time_t objects using normal integer comparison operators.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,755
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is offline Offline
Posting Virtuoso

Re: check this code pleeeeeeeeeease

 
0
  #6
Dec 13th, 2005
To me a standing order means add/delete a certain amount on a certain day of each month. Obviously there are other definitions, too, so you really need to decide exactly what you want to do. It could be as simple as extracting the day of the month field from the time_t struct you get from local_time and looking at each Account to see if they have a standing order. If so, what day of the month is the standing order to be done. If the two dates are the same proceed with a transaction based on the standing order.

for each account
if day of month from time_t == day of month for standing order
then do transaction listed in standing order

For that matter, do you even need to use local_time. If you aren't familar with items in ctime header file you could just ask user to input day of month when they want to enter a transaction as opposed to having the computer input the data for you. Not as slick as having the computer running all the time, automatically monitoring the day of the month, and running standing orders automatically, but certainly less complicated to code, and probably meets the assignment criteria.

Maybe it's the yucky green font but I can't find where you define Account::disolayAccount(). I do see Bank:howAccount() and in there I strongly recommend to initialize 1 to some value before you try to compare i with -1.

I'm not sure where you are refering to transection, but if it is Bank::transaction() and you are trying to do more than one transaction withing the function (I note you have both deposit and withdrawal listed) then you I would suggest you use a loop similar to the one you used with menu.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: check this code pleeeeeeeeeease

 
0
  #7
Dec 13th, 2005
thanks all i will try
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC