please help me in my project (urgent )

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

Join Date: Oct 2008
Posts: 3
Reputation: uae_uae99 is an unknown quantity at this point 
Solved Threads: 0
uae_uae99 uae_uae99 is offline Offline
Newbie Poster

please help me in my project (urgent )

 
0
  #1
Oct 16th, 2008
after i tried many times to solf this program i couldnt do it
this is the sorce of my program and it is about sell and rent a care.
my problem is when i run do progrm it works but when i try to see the car i want buy or rent cant . i created text file for rent and sell and it has all information about all cars and also i created anther file for member to save username and password.

2- i want to add a fuction for rent that multuple a days that user choose and the price of car???

plz help me and i will be thankfull to all

i hope you got it ???why it is not display cars ???it show me 0 0 0 for all cars??

  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. struct member // This structure is made for the member
  11. {
  12. string member_name; // Each member will have a member's name
  13. string member_pass; // password and
  14. double balance; // balance
  15. }; // This will make things easier for organizing the data
  16.  
  17.  
  18. struct item // This structure is made for the items
  19. {
  20. int id; // Each item will have an id
  21. char name[100]; // name and
  22. double price; // price
  23. }; // This will make things easier for organizing the data
  24.  
  25.  
  26. //After making the structures then we initialize the needed variables as types of the structures
  27. item personal_cars[20]; // Initialize personal cars variable
  28. item rent_cars[10]; // Initialize rent cars variable
  29. item cart[10]; // Initialize cart variable
  30. member members[20]; // Initialize members variable
  31.  
  32.  
  33. //Initializing these global variables to 0 is necesary each time the program is run
  34. int position=0; // Position is a counter that will stop at the user that logs in
  35. int size=0; // Size will determine the position of the item, i.e if size is at 3 then there are 3 items in cart
  36. int counter=0; // Counter will count the total number of members
  37. fstream log_member; // Initializes file for both reading and writing
  38.  
  39.  
  40. //These are the user defined functions
  41. void intro();
  42. void start();
  43. void login();
  44. void new_member();
  45. void options();
  46. void view_account();
  47. void view_cart();
  48. void add_to_cart(char);
  49. void check_out();
  50. void drop();
  51. void order();
  52. void logout();
  53. void display_items(char);
  54. void Add_to_balance();
  55. void receipt(double total);
  56. void update();
  57.  
  58.  
  59.  
  60. //*********************************************************************************************************************
  61.  
  62. //############################## MAIN FUNCTION ##################################################
  63.  
  64. int main()
  65. {
  66. intro();
  67. start();
  68. options();
  69.  
  70. system("PAUSE");
  71. return 0;
  72. }
  73.  
  74. //############################## END MAIN ###################################################
  75.  
  76. //*********************************************************************************************************************
  77.  
  78.  
  79.  
  80. //The start function Prints out the Welcome screen and gives the user his first choices in the program
  81. //The choices chosen are other functions thenselves
  82.  
  83. void intro()
  84. {
  85. cout <<endl;
  86. cout << " ***************************************************************************" <<endl;
  87. cout << " * <<<Welcome to SMW Company>>> *\n" <<endl;
  88. cout << " * This program takes your to buy a car that you are looking for *" << endl;
  89. cout << " * and returns the answer to the screen. If an illegal operator is *" << endl;
  90. cout << " * selected, an error message will be displayed. Be careful which *" <<endl;
  91. cout << " * number you select because the program depends on you for input. *" <<endl;
  92. cout << " * The only error check function it has, is for unacceptable opreators. *" <<endl;
  93. cout << " * Acceptable operators are : (1 , 2 , 3 and 4). The character c sets *" <<endl;
  94. cout << " * the value stored to ZERO. ENJOY YOUR PROGRAM !!!!!! *" <<endl;
  95. cout << " ***************************************************************************" <<endl;
  96. cout <<endl;
  97. }
  98.  
  99.  
  100.  
  101. void start()
  102. {
  103. char choice;
  104.  
  105. cout<<"\n\n1. New Account Sign Up\n2. Login\n"<<endl;
  106. cin >> choice;
  107.  
  108. if(choice=='1')
  109. new_member();
  110. else if(choice=='2')
  111. login();
  112. else
  113. {
  114. cout<<"Invalid input"<<endl;
  115. start();
  116. }
  117. }
  118.  
  119.  
  120. //The new user function as implied in the name adds a new user to the record
  121.  
  122. void new_member()
  123. {
  124. fstream log_member; //Initializing file
  125. log_member.open ("members.txt"); // opening a file
  126.  
  127. int i=0; //Loop used to read all existing members into memory
  128.  
  129.  
  130. while(log_member>>members[i].member_name && log_member>>members[i].member_pass && log_member>>members[i].balance)
  131. {
  132. i++;
  133. }
  134.  
  135. //20 is the max number of members, so if i is >= 20 then that means there is no more space, but hopefully not :)
  136. if(i<20)
  137. {
  138. cout<<"Enter new Username (Max 12 Characters) : ";
  139. cin >> members[i].member_name;
  140.  
  141. cout<<"Enter new Password (Max 10 Characters) : ";
  142. cin >> members[i].member_pass;
  143.  
  144. members[i].balance=0; //Initializes new user balance to RM 0
  145. position=i;
  146. counter=position;
  147.  
  148. log_member.close();
  149. }
  150.  
  151. else
  152. {
  153. cout<<"Maximum limit of members reached"<<endl;
  154. }
  155.  
  156.  
  157. }
  158.  
  159.  
  160. //Login function logs in an existing member by reading the member name and password,
  161. //and then checking it with existing member names and passwords
  162.  
  163. void login()
  164. {
  165. fstream log_member; //Initilizing and opening a file
  166. char member_name[12],password[10]; //Initializing arrays to store member name and password
  167. position = -1;
  168.  
  169. cout<<"Member's name : ";
  170. cin >> member_name;
  171. cout<<"Password : ";
  172. cin >> password;
  173.  
  174. log_member.open("members.txt");
  175.  
  176. //This loops reads throuhg all existing member names and pasword sets,
  177. //and if any set mathces the one entered then it allocates to variable position
  178. //and then continues the loop till it reads all
  179.  
  180. for (int i = 0; log_member>>members[i].member_name && log_member>>members[i].member_pass && log_member>>members[i].balance; i++)
  181. {
  182. if(members[i].member_name == member_name && members[i].member_pass == password)
  183. {
  184. position = i;
  185. }
  186. else
  187. {
  188. position = position;
  189. }
  190. }
  191.  
  192. if(position>=0) //This checks to see if the member has been found
  193. {
  194. log_member.close();
  195. }
  196. else //This alerts the user that the details he/she entered were not found
  197. {
  198. cout<<"Incorrect username or password!"<<endl; //cout<<"Position: "<< position <<endl;
  199.  
  200. log_member.close();
  201. start();
  202. }
  203.  
  204. log_member.close();
  205. }
  206.  
  207.  
  208. void options() //Options functions comes after login and it gives the member his next options
  209. {
  210. char option;
  211.  
  212. cout<<"\n\nWelcome to your account "<<members[position].member_name<<endl;
  213. cout<<"\nChoose an option :"<<endl;
  214. cout<<"\n1. View Account Summary\n2. Order\n3. View Shopping Cart\n4. Logout\n"<<endl;
  215. cin >> option;
  216.  
  217. switch (option) //Switch is used to select his chosen option
  218. {
  219. case '1':
  220. view_account();
  221. break;
  222. case '2':
  223. order();
  224. break;
  225. case '3':
  226. view_cart();
  227. break;
  228. case '4':
  229. logout();
  230. break;
  231. default:
  232. cout<<"Invalid input"<<endl;
  233. options();
  234. }
  235. }
  236.  
  237.  
  238. //View account function gives the member some options to look into his/her account details like balance, Add_to_balance money and loging out
  239.  
  240. void view_account()
  241. {
  242. char option;
  243.  
  244. cout<<"\n1. Balance\n2. Add to my balance\n3. Return to Previous Menu\n4. Logout"<<endl;
  245. cin >> option;
  246.  
  247. switch (option)
  248. {
  249. case '1':
  250. {
  251. cout<<"\nYour Available Balance is RM "<< members[position].balance <<endl;
  252. view_account();
  253. }
  254. break;
  255. case '2':
  256. {
  257. Add_to_balance();
  258. }
  259. break;
  260. case '3':
  261. {
  262. options();
  263. }
  264. break;
  265. case '4':
  266. {
  267. logout();
  268. }
  269. break;
  270. default:
  271. {
  272. view_account();
  273. }
  274. }
  275. }
  276.  
  277.  
  278. //Add_to_balance function adds money to the member existing balance
  279. //We assume the member has a valid third party bank account
  280. //So all that is need to be done is to specify the amount and add to
  281. //his/her balance
  282.  
  283. void Add_to_balance()
  284. {
  285. float Add_to_balancement=0;
  286.  
  287. cout<<"The amount : ";
  288. cin>>Add_to_balancement;
  289.  
  290. members[position].balance += Add_to_balancement;
  291.  
  292. cout<<"The Add_to_balancement has been successful added :)"<<endl;
  293. cout<<members[position].member_name<<" current balance is RM "<< members[position].balance <<endl;
  294.  
  295. view_account();
  296. }
  297.  
  298.  
  299. void order()
  300. {
  301. //Gives member options to choose whic list to view
  302.  
  303. char option, choice;
  304. cout<<"\nChoose which list you would like to view"<<endl;
  305. cout<<"\n1. Buy car\n2. Rent car\n3. Return to Previous Menu"<<endl;
  306. cin >> option;
  307.  
  308. //The option chosen is passed to another function used to display the items
  309.  
  310. display_items(option);
  311.  
  312. cout<<"1.Add item to the order\n2.Retun to previous menu"<<endl;
  313. cin >> choice;
  314.  
  315. if (choice == '1')
  316. {
  317. //Option chosen passed on to another function to add to cart
  318. add_to_cart(option);
  319. }
  320. else
  321. {
  322. //Directs to the view the list option
  323. order();
  324. }
  325.  
  326. //After a member adds a item then he/she is immediately shown his/her cart
  327. view_cart();
  328. }
  329.  
  330.  
  331. //view_cart function shows the member his/her cart
  332.  
  333. void view_cart()
  334. {
  335. char choice;
  336. cout<<"\n"<<members[position].member_name<<" item(s) :\n"<<endl;
  337. cout<<"**********************************************************************"<<endl;
  338. cout<<"ID"<<"\t\t"<<" Item Name"<<"\t\t\t"<<"Price"<<endl;
  339. cout<<"**********************************************************************"<<endl;
  340.  
  341.  
  342. for (int i = 0; i < size; i++) //This loop prints out all items in cart
  343. {
  344. cout<<cart[i].id<<"\t\t"<<cart[i].name<<"\t\t"<<cart[i].price<<endl;
  345. }
  346.  
  347. //More options avaliable since use may want to check out right away
  348. cout<<"\n1.Checkout Item(s)\n2.Drop item(s)\n3.Add item(s)\n4.Return to previous menu"<<endl;
  349. cin >> choice;
  350.  
  351. switch (choice)
  352. {
  353. case '1':
  354. check_out();
  355. break;
  356. case '2':
  357. drop();
  358. break;
  359. case '3':
  360. order();
  361. break;
  362. case '4':
  363. options();
  364. break;
  365. default:
  366. cout<<"Invalid input"<<endl;
  367. view_cart();
  368. }
  369. }
  370.  
  371.  
  372. //Drop function drops last item added, since we are storing added items to cart in arrays
  373. //we have only enough knowledge to drop the last one entered
  374.  
  375. void drop()
  376. {
  377. //Since variable 'size' it what we use to store the number of elements in the cart array
  378. //all we need to to is rollback one step in order to remove the last item
  379. size -= 1;
  380. cout<<"You last item has been dropped succesfully :)"<<endl;
  381. options();
  382. }
  383.  
  384. //Display items function displays the items the member wants,
  385. //the function is passed a value which it acts on to show the required item
  386.  
  387. void display_items(char option)
  388. {
  389. switch (option)
  390. {
  391. case '1':
  392. {
  393. //Initializes file for reading n writing
  394. ifstream personal_cars_file ("personal cars.txt");
  395.  
  396. for(int i=0; i<20; i++) //loops through the whole file
  397. {
  398. //Stores the first value before a space in the line as 'id'
  399. personal_cars_file>>personal_cars[i].id;
  400.  
  401. //Stores the next after the space as name until it reaches a tab
  402. personal_cars_file.get(personal_cars[i].name, 100 ,'\t');
  403.  
  404. //Then stores the next as price
  405. personal_cars_file>>personal_cars[i].price;
  406.  
  407. //It then prints out what it just read to the screen
  408. cout<<personal_cars[i].id<<"\t"<<personal_cars[i].name<<"\t"<<personal_cars[i].price<<endl;
  409. }
  410. personal_cars_file.close(); //Closes the file
  411. }
  412. break;
  413.  
  414. //Same as above happens on the rest, exept it does it with different files
  415. case '2':
  416. {
  417. int days;
  418.  
  419. cout<<"How many day(s) you want to rent the car?"<<endl;
  420. cin>>days;
  421.  
  422. fstream rent_cars_file ("rent_cars.txt");
  423.  
  424. for(int i=0; i<10; i++)
  425. {
  426. rent_cars_file>>rent_cars[i].id;
  427. rent_cars_file.get(rent_cars[i].name, 100 ,'\t');
  428. rent_cars_file>>rent_cars[i].price;
  429. cout<<rent_cars[i].id<<"\t"<<rent_cars[i].name<<"\t"<<(rent_cars[i].price)*days<<endl;
  430. }
  431.  
  432. rent_cars_file.close();
  433. }
  434. break;
  435.  
  436. case '3':
  437. options();
  438. break;
  439.  
  440. default:
  441. {
  442. cout<<"\nInvalid Input"<<endl;
  443. order();
  444. }
  445. }
  446. }
  447.  
  448.  
  449. void add_to_cart(char option) //This function adds a selected item to the cart
  450. { //It is passed a value which determines which list the member is refereing to
  451. int id;
  452.  
  453. //The if statement is a validity checker that check if the cart is full or not
  454. if (size < 10)
  455. {
  456. switch (option)
  457. {
  458. case '1':
  459. {
  460. cout<<"Enter the item ID: ";
  461. cin >> id;
  462.  
  463.  
  464. cart[size] = personal_cars[id-1]; //This maps the selected item to the cart
  465. size++;
  466. cout<<"Your item has been added to "<<members[position].member_name<<" cart successfully :)"<<endl;
  467. }
  468. break;
  469. case '2':
  470. {
  471. cout<<"Enter the item ID: ";
  472. cin >> id;
  473.  
  474. cart[size] = rent_cars[id-1];
  475. size++;
  476. cout<<"Your item has been added to "<<members[position].member_name<<" cart successfully :)"<<endl;
  477. }
  478. break;
  479. default:
  480. cout<<"Invalid input"<<endl;
  481. order();
  482. }
  483. }
  484.  
  485. //This means the cart is full so it alerts the member
  486. else
  487. {
  488. cout<<"Cart full"<<endl;
  489. order();
  490. }
  491. }
  492.  
  493. //Checkout is like buying the item(s)
  494. void check_out()
  495. {
  496. char choice;
  497. double total = 0;
  498.  
  499.  
  500. for (int i = 0; i < size; i++) //This loop sums the total of the item(s) added to the cart
  501. {
  502. total += cart[i].price;
  503. }
  504.  
  505. if ( total > members[position].balance) //This statement checks whether the member has enouhgh balance
  506. {
  507. cout<<"\n\nSorry you have insufficient funds to continue the transaction"<<endl;
  508. cout<<"\n\n1.Add_to_balance\n2.Drop last item\n3.Order\n4.Logout"<<endl;
  509. cin >> choice;
  510.  
  511. switch (choice)
  512. {
  513. case '1':
  514. Add_to_balance();
  515. break;
  516. case '2':
  517. drop();
  518. break;
  519. case '3':
  520. order();
  521. break;
  522. case '4':
  523. logout();
  524. break;
  525. default:
  526. cout<<"Invalid input"<<endl;
  527. check_out();
  528. }
  529. }
  530. else
  531. {
  532. members[position].balance -= total; //It deducts the total sum of the items from his/her balance
  533.  
  534. cout<<members[position].member_name<<" cart have been checked out successfully :)"<<endl;
  535.  
  536. cout<<"The remaining balance is : "<< members[position].balance <<endl;
  537.  
  538. receipt(total);
  539. update();
  540. size=0;
  541. counter=0;
  542. position=0;
  543.  
  544. for (int i = 0; i < size; i++)
  545. {
  546. cart[i].id=('0');
  547. }
  548. main();
  549. }
  550.  
  551. }
  552.  
  553. //Update function writes all the edited information of the member back to the text file
  554.  
  555. void update()
  556. {
  557. fstream log_member;
  558. log_member.open ("members.txt");
  559.  
  560. //Loop used to get to the member info
  561. for (int i = 0; i <= position; i++)
  562. {
  563. log_member<< members[i].member_name <<" ";
  564. log_member<< members[i].member_pass <<" ";
  565. log_member<< members[i].balance <<" ";
  566. }
  567. log_member.close();
  568. }
  569.  
  570. void receipt(double total)
  571. {
  572. cout<<"\nPrinting "<<members[position].member_name<<" receipt.."<<endl;
  573. cout<<"***********************************************************************"<<endl;
  574. cout<<"\t\t\tSMW Company\n";
  575. cout<<"\t\t TEL: +60173784877"<<endl;
  576. cout<<"\t\t IIUM, Gombak"<<endl;
  577. cout<<"----------------------------------------------------------------------"<<endl;
  578. cout<<"ID"<<"\t\t"<<" Car Name"<<"\t\t\t"<<"Price"<<endl;
  579. cout<<"----------------------------------------------------------------------"<<endl;
  580.  
  581. for (int i = 0; i < size; i++)
  582. {
  583. cout<<cart[i].id<<"\t\t"<<cart[i].name<<"\t\t"<<cart[i].price<<endl;
  584. }
  585.  
  586. cout<<"***********************************************************************"<<endl;
  587. cout<<"Cart Total\t\t\t\t"<<total<<endl;
  588. cout<<"Tax 2%\t\t\t\t\t"<<(total*2)/100<<endl;
  589.  
  590. cout<<"Total\t\t\t\t\t"<<(total)+((total*2)/100)<<endl;
  591.  
  592. cout<<"\t\tTHANK YOU "<<members[position].member_name<<"\n\tIT WAS OUR PLEASURE SERVING YOU\n";
  593. }
  594.  
  595. //Logout finally updates the member info and then exits the program
  596.  
  597. void logout()
  598. {
  599. update();
  600. size=0;
  601. counter=0;
  602. position=0;
  603.  
  604. for (int i = 0; i < size; i++)
  605. {
  606. cart[i].id=('0');
  607. }
  608.  
  609. cout<<"\nYou have succesfully logged out\n\n\n\n"<<endl;
  610. main();
  611. }
Last edited by cscgal; Oct 16th, 2008 at 5:59 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: please help me in my project (urgent )

 
0
  #2
Oct 16th, 2008
Use code tags, and ask more specific question
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: please help me in my project (urgent )

 
0
  #3
Oct 16th, 2008
To build on what Sci@phy siad, narrow it down to a small section of code aswell. Don't expect us to read all of that when we may only need to look at 5 lines of it!

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: uae_uae99 is an unknown quantity at this point 
Solved Threads: 0
uae_uae99 uae_uae99 is offline Offline
Newbie Poster

Re: please help me in my project (urgent )

 
0
  #4
Oct 16th, 2008
guys iam still new
alright dont warry next time i will follow the stractures

NOW are you going to help me or just add some Comments
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: please help me in my project (urgent )

 
0
  #5
Oct 16th, 2008
Originally Posted by uae_uae99 View Post
guys iam still new
alright dont warry next time i will follow the stractures

NOW are you going to help me or just add some Comments
Next time is good but what about this time, If you take into consideration what we said then we can help you. Until then we are pretty much just taking radom stabs in the dark.

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 114
Reputation: sidatra79 is an unknown quantity at this point 
Solved Threads: 8
sidatra79's Avatar
sidatra79 sidatra79 is offline Offline
Junior Poster

Re: please help me in my project (urgent )

 
0
  #6
Oct 16th, 2008
Do what u were told and u will get some help for sure
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC