C++ Question...with uncompleted answer..anyone can solve it?

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

Join Date: Sep 2005
Posts: 16
Reputation: mysterio is an unknown quantity at this point 
Solved Threads: 0
mysterio mysterio is offline Offline
Newbie Poster

C++ Question...with uncompleted answer..anyone can solve it?

 
0
  #1
Sep 13th, 2005
1. User will enter the ISBN,
The system will trace the title and price of the book automatically.
The system should check whether the book is in the stock or not.
If it is not, please let the user to enter again.

2. Allow a customer to buy more than one item from the bookshop.

3. Calculate and print the bill.
The billing amount should include 5% tax.


Sample Output:

Welcome to Jack’BookShop

Please enter the ISBN: 1234
The title is Introduction to Java Programming
The Price is RM 99.50

Do you wish to continue? y/n
y

Please enter the ISBN: 5678
The title is C++ How to Program
The Price is RM 79.40

Do you wish to continue? y/n
n

Your Receipt:

1234 RM 99.50
5678 RM 79.40
Total RM 178.90
Tax RM 8.95

Total RM 187.85

Thank You!!!
Please Come Again!!!

Source Code..which i have do some..anyone can add or modify it??
and correct the mistakes if possible..


Help :cry: i cant solve it... :cry:


  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. double ISDN ;
  10. char title;
  11. float price;
  12. int continues;
  13. char ans;
  14.  
  15. cout<<"---Welcome To Billy's Bookshop---\n";
  16. cout<<"Please enter the ISDN: ";
  17. cin>>ISDN;
  18.  
  19. if (ISDN==1234)
  20. {
  21. cout<<"The Title is Introduction to Java Programming"<<endl<<"The Price is RM 99.50"<<endl;
  22. }
  23. if (ISDN==5678)
  24. {
  25. cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM 79.40"<<endl;
  26. }
  27. else
  28. {
  29. cout<<"Not Valid"<<endl;
  30. }
  31.  
  32.  
  33. do
  34. {
  35. cout<< "Do you want to continue (Y/N)?\n";
  36. cout<< "You must type a 'Y' or an 'N'.\n";
  37. cin >> ans;
  38. }
  39. while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));
  40.  
  41.  
  42. return 0;
  43. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 902
Reputation: chrisbliss18 is an unknown quantity at this point 
Solved Threads: 23
chrisbliss18's Avatar
chrisbliss18 chrisbliss18 is offline Offline
Posting Shark

Re: C++ Question...with uncompleted answer..anyone can solve it?

 
0
  #2
Sep 13th, 2005
You've got the right idea, and you are really close. Try moving the start of the "do" block to before requesting the ISDN number but after printing the title. After you fix up your loop, we can work on the totals if you need help with that.
Did we help you? Did we miss the point entirely? Update your thread and let us know.
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: C++ Question...with uncompleted answer..anyone can solve it?

 
0
  #3
Sep 13th, 2005
go for switch case rather than if-else blocks
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: C++ Question...with uncompleted answer..anyone can solve it?

 
0
  #4
Sep 13th, 2005
how do you know whats in stock? do you read that info from a file? you gotta enter it by hand?

You can use the STL to simplify your exercise.

I would probably use a sorted vector of structs(or a map) with 5 members(isbn,author,title,price,num_copies_instock) to represent the stock. If you keep it sorted by isbn you will get fast searches using a binary search algorithm. Then get entry by isbn and try find it in the vector. If entry exists then add to receipt. This can be another vector. If not say something like we dont have it etc.. At end of user input receipt can be printed by iterating thru the receipt vector.

You familiar with structs? std::string? std::vector? std::map?
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



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

©2003 - 2009 DaniWeb® LLC