| | |
C++ Question...with uncompleted answer..anyone can solve it?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 0
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:
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:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { double ISDN ; char title; float price; int continues; char ans; cout<<"---Welcome To Billy's Bookshop---\n"; cout<<"Please enter the ISDN: "; cin>>ISDN; if (ISDN==1234) { cout<<"The Title is Introduction to Java Programming"<<endl<<"The Price is RM 99.50"<<endl; } if (ISDN==5678) { cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM 79.40"<<endl; } else { cout<<"Not Valid"<<endl; } do { cout<< "Do you want to continue (Y/N)?\n"; cout<< "You must type a 'Y' or an 'N'.\n"; cin >> ans; } while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n')); return 0; }
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
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
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?
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?
![]() |
Similar Threads
- A quick question about "rank" (DaniWeb Community Feedback)
- algorithm question (Computer Science)
- (Medicine Question) Death with Heparin? (Geeks' Lounge)
- A question on java script?(Please answer ASAP) (Java)
Other Threads in the C++ Forum
- Previous Thread: Creating Graphs
- Next Thread: Pointer, vector, and/or deque problem
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





