By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

c++ help....i'm stuck in the middle...

P: n/a
JT
Help me the following C++ question:

Write a program to help a local bookshop automate its billing system.
The program should do the following:

(a)Let the user 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.
(b)Allow a customer to buy more than one item from the bookshop.
(c)Calculate and print the bill. The billing amount should include 5%
tax.

Sample Output:

Welcome to Billy'BookShop

Please enter the ISBN: 0128
The title is C++ How to Program
The Price is RM 108.90

Do you wish to continue? y/n
y

Please enter the ISBN: 0992
The title is Introduction to Java Programming
The Price is RM 89.60

Do you wish to continue? y/n
n

Your Receipt:

0128 RM 108.90
0992 RM 89.60
Total RM 198.50
Tax RM 9.92

Total RM 208.42

THANK YOU!!!

p/s: I would thanks for who solve this problems..i appreciate ur help..

Below...r some coding i hv done..not completed
hope some 1 will help me complete

Source Code<not Complete>

#include <iostream.h>
#include<stdlib.h>

struct bookshop
{
int ISDN;
char title;
int price;
}book[];

void printbook (bookshop book);

int main()

{
float amount, rate;
int year;
cout <<"Please enter the amount: ";
cin >> amount;
cout <<"Please enter the number of years to invest: ";
cin >> year;
cout <<"Please enter the interest rate per year: ";
cin >> rate;

for (int y=0;y<year;y++)
amount = amount + (amount*rate/100);

cout <<"The amount you have "<<year<< "year is:"
<< amount<<endl;

return 0;
}

Sep 11 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
* JT:
Help me the following C++ question:

Write a program to help a local bookshop automate its billing system.
The program should do the following:

(a)Let the user 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.
(b)Allow a customer to buy more than one item from the bookshop.
(c)Calculate and print the bill. The billing amount should include 5%
tax.
"Do my homework" is off-topic in this group.

#include <iostream.h>
Non-standard header.

#include<stdlib.h>

struct bookshop
Misleading name; use self-describing names.

{
int ISDN;
Don't use all uppercase names except for macros.

char title;
int price;
}book[];
Arrays must have sizes.

Anyway, use a std::vector instead of a raw array.

And don't use globals.
void printbook (bookshop book);
Probably not a good idea to pass by value.

int main()

{
float amount, rate;
int year;
cout <<"Please enter the amount: ";
cin >> amount;
cout <<"Please enter the number of years to invest: ";
cin >> year;
cout <<"Please enter the interest rate per year: ";
cin >> rate;

for (int y=0;y<year;y++)
amount = amount + (amount*rate/100);

cout <<"The amount you have "<<year<< "year is:"
<< amount<<endl;

return 0;
}


This code is totally unrelated to the problem.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 11 '05 #2

P: n/a
JT wrote:
Help me the following C++ question:

Write a program to help a local bookshop automate its billing system.
The program should do the following:

(a)Let the user 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.
(b)Allow a customer to buy more than one item from the bookshop.
(c)Calculate and print the bill. The billing amount should include 5%
tax.

Sample Output:

Welcome to Billy'BookShop

Please enter the ISBN: 0128
The title is C++ How to Program
The Price is RM 108.90

Do you wish to continue? y/n
y

Please enter the ISBN: 0992
The title is Introduction to Java Programming
The Price is RM 89.60

Do you wish to continue? y/n
n

Your Receipt:

0128 RM 108.90
0992 RM 89.60
Total RM 198.50
Tax RM 9.92

Total RM 208.42

THANK YOU!!!

p/s: I would thanks for who solve this problems..i appreciate ur help..

Below...r some coding i hv done..not completed
hope some 1 will help me complete

Source Code<not Complete>

#include <iostream.h>
#include<stdlib.h>

struct bookshop
{
int ISDN;
char title;
int price;
}book[];

void printbook (bookshop book);


Well really I would say you are stuck at the beginning. Presumably this
is the first substantial program you have had to write.

The most important advice is not to try and write the program all in one
go. Pick which every you think is the easiest part first, do that an get
it working, then go onto the next part.

For instance, above you have written

void printbook (bookshop book);

well why not write the printbook function? Forget about the rest of the
problem, write the printbook function, make up a couple of books to
print, and see if the function works. Keep going at that until it does
and then move onto the next part of the problem. Something like this

struct Book
{
int ISBN;
...
};

Book a_book = { 1234, "Programming in C++", ... };
Book another_book = { 5678, "Programming in Java", ... };

void printbook(Bookbook);

int main()
{
printbook(a_book);
printbook(another_book);
return 0;
}

void printbook(Bookbook)
{
...
}

You fill in the parts where I've written ...

This is the most important advice, do this in small steps and get each
step working before you move onto the next.

john
Sep 11 '05 #3

P: n/a
GB
John Harrison wrote:
void printbook(Bookbook);

int main()
{
printbook(a_book);
printbook(another_book);
return 0;
}

void printbook(Bookbook)
{
...
}

I'm sure the error above was a typo or posto, and not a thinko, but for
the sake of the OP, in the above,
void printbook(Bookbook);
should be
void printbook(Book book);


Gregg
Sep 12 '05 #4

P: n/a
You really should do your own homework.

Sep 12 '05 #5

P: n/a
> You really should do your own homework.


Or make your question don't look like a homework :)

ben
Sep 12 '05 #6

P: n/a
JT
i have do some....does it correct way to use it??
can show me next step ?

Coding:-
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
double ISDN ;
char title;
float price;

cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;

if (ISDN==12)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
if (ISDN==98)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
return 0;
}

Sep 12 '05 #7

P: n/a
JT wrote:

i have do some....does it correct way to use it??
can show me next step ?

Coding:-
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
double ISDN ;
char title;
float price;

cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;

if (ISDN==12)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
if (ISDN==98)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
return 0;
}


That is *not* what John suggested and his suggestion was a good one.

Start with writing down a data structure, which describes *one* book.
Forget the whole bookstore for the moment, just concentrate on *one* book.

struct Book
{
.... // use whatever data members you need to describe *one* book
};

Then write your first version of main(), which just allocates *one* book

int main()
{
Book TheBook( ..... ); // Initialize it. This depends entirely on the data structure
// you built up earlier
}

Then continue with operations you can already do now.
Eg. print out the complete description for *one* Book. In main() you
currently have *one* Book. Thus you can perfectly test your function:

struct Book
{
.... // use whatever data members you need to describe *one* book
};

void PrintBook( Book& book )
{
cout << ....... // do whatever you need to do to print
// out the description of *one* book that
// is passed to that function
}

int main()
{
Book TheBook( ..... ); // Initialize it. This depends entirely on the data structure
// you built up earlier

// now testing the print function
PrintBook( TheBook );
}

What else can you do with just *one* book? There would be various function
that could be written on just *one*, such as read and save from file. But
honestly I think you should takle the rest, before you even think of dealing
with files. So for now the answer is: nothing more.

OK. Now that everything that can be done with *one* book is finished, you should
think about how you would like to represent a collection of books. You could
use an array or a vector to store *multiple* books. So continue working in
this direction. Instead of *one* you want *multiple*. What to do with them?
Simple: You have a function that prints *one*, so it should be fairly easy
to enclose that function call in a loop and print all of them. This way
you can easily verify that your 'storage' works correctly. The books you
define in your program must be printed with the exact same information. If
it doesn't, you have a bug somewhere.

Only after that, you should start thinking about letting the user enter
a search phrase for a specific book. You then write a function which
loops through all the books and looks for that search string. If it is found,
you use eg. the already tested and working function 'PrintBook" to print out
its values.

So: Start simple and add more complicated things as you go along. Step back
and set some easy to reach goals. There is no point in starting to search
a database, when actually there is no database or you haven't verified that
your database actually works as expected. Otherwise you will never know where
a bug is located: Is it the database itself that is in error, is it the user
input or is the search code wrong?

--
Karl Heinz Buchegger
kb******@gascad.at
Sep 12 '05 #8

P: n/a
On 12 Sep 2005 04:31:52 -0700, "JT" <ja*****@gmail.com> wrote:
double ISDN ;
[snip]
cin>>ISDN;

if (ISDN==12)

Comparing doubles to int's with the == operator is generally not a good idea.
Consider using an unsigned long (range 0 ~ 4294967295).

By the way, I think you want ISBN, which is the International Standard Book
Number, not ISDN, which is a kind of telephone service.

-dr
Sep 13 '05 #9

P: n/a
JT
can complete 4 me? and see wat is the mistake n wat to do next?

#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==12)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
if (ISDN==98)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<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;
}

Sep 13 '05 #10

P: n/a

"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
can complete 4 me? and see wat is the mistake n wat to do next?
can u spk Eng?

#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==12)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
if (ISDN==98)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<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'vebeen given plenty of good advice. Try using it, instead of just
writing a couple of lines of code and then asking us to do your homework for
you.

-Howard

Sep 13 '05 #11

P: n/a
"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
can complete 4 me? and see wat is the mistake n wat to do next?


Language of this newsgroup is english. Not whatever that was up there.

If I did this for you, what would you learn? Nothing. The object of this
homework is to get you to think about how to do it. I suggest you read your
textbook and look at the sample code in there to see how they do this type
of thing.
Sep 13 '05 #12

P: n/a
JT

Howard wrote:
"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
can complete 4 me? and see wat is the mistake n wat to do next?
can u spk Eng?


sure can speack english...

here the coding i done so far...at least u see wat is my error then i
know wat to do next...

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void bookshop();

void main()
{
char ans;
do
{
bookshop();

cout<< "Do you want to continue (Y/N)?";
cin >> ans;
}
while((ans !='N')&&(ans !='n'));
}

void bookshop()
{
float ISDN ;

cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;

if (ISDN==123)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
else if (ISDN==456)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
}

You'vebeen given plenty of good advice. Try using it, instead of just
writing a couple of lines of code and then asking us to do your homework for
you.

-Howard


i have tried but it not works...n hard to understand just look at the
coding...
that why i am here to ask for help..

Sep 14 '05 #13

P: n/a
JT wrote:
Howard wrote:
"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.google groups.com...
can complete 4 me? and see wat is the mistake n wat to do next?


can u spk Eng?

sure can speack english...

here the coding i done so far...at least u see wat is my error then i
know wat to do next...

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void bookshop();

void main()
{
char ans;
do
{
bookshop();

cout<< "Do you want to continue (Y/N)?";
cin >> ans;
}
while((ans !='N')&&(ans !='n'));
}

void bookshop()
{
float ISDN ;

cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;

if (ISDN==123)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
else if (ISDN==456)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
}
You'vebeen given plenty of good advice. Try using it, instead of just
writing a couple of lines of code and then asking us to do your homework for
you.

-Howard

i have tried but it not works...n hard to understand just look at the
coding...
that why i am here to ask for help..


I'm sure you are going nowhere with the above code. Even if you get it
to work it will not result in a worthwhile solution to the problem you
have been given.

Frankly, you are making the typical newbie mistake, which is to read the
problem you've been given, start at the beginning and work though to the
end.

Instead you should be trying to break the problem into smaller pieces.
Solve each piece independently, and then put the pieces back together at
the end.

Whatever approach you choose, the *first* thing you should be doing is
to define a data structure for a book. This problem is all about books.

struct Book
{
int isbn;
...
};

and then take it from there. The code above is going nowhere because it
lacks any concept of what a book is.

john
Sep 14 '05 #14

P: n/a

"JT" <ja*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Howard wrote:
"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
> can complete 4 me? and see wat is the mistake n wat to do next?
can u spk Eng?


sure can speack english...

here the coding i done so far...at least u see wat is my error then i
know wat to do next...


That's not English. There are no words "u", "wat", or "i" in English.
cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;

if (ISDN==123)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
else if (ISDN==456)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
}

You'vebeen given plenty of good advice. Try using it, instead of just
writing a couple of lines of code and then asking us to do your homework
for
you.

-Howard


i have tried but it not works...n hard to understand just look at the
coding...
that why i am here to ask for help..


It doesn't work because it just outputs a title and price for either of
those two books. That wasn't your assignment, and no amount of "correction"
will make this do what your assignment says to do. I think you need to
actually pay attention in class, and read your books. We're simply _not_
going to do your homework for you.

-Howard

Sep 14 '05 #15

P: n/a
"JT" writes:
Help me the following C++ question:

Write a program to help a local bookshop automate its billing system.
The program should do the following:

(a)Let the user 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.
(b)Allow a customer to buy more than one item from the bookshop.
(c)Calculate and print the bill. The billing amount should include 5%
tax.

Sample Output:

Welcome to Billy'BookShop

Please enter the ISBN: 0128
The title is C++ How to Program
The Price is RM 108.90

Do you wish to continue? y/n
y

Please enter the ISBN: 0992
The title is Introduction to Java Programming
The Price is RM 89.60

Do you wish to continue? y/n
n

Your Receipt:

0128 RM 108.90
0992 RM 89.60
Total RM 198.50
Tax RM 9.92

Total RM 208.42


The problem is pretty vague. It alludes to this "system", a kind of a
phantom thing. It doesn't say that a file will be provided by the
instructor. Or that you should write a program that creates a file. But
clearly a file is required. The easiest way to proceed is to create a
simple file with a text editor. Having done that, you can actually write
the program described.

From the sample you can see that each record requires three "fields". An
ISBN number, a book name and a price. You could type this on three lines
with your favorite text editor. Follow that with three lines for the next
book and three lines for the third and final book. (I would like to see at
least three entries (records) to prove that your program indeed works.)
Note that the price, which is a string, will have to be converted to a
number to compute the tax. I would convert to a double and let the pendants
bitch. After all it is only a problem for a beginning student.

You program has the choice of working directly from the file or from an
internal representation, an array of structures would be usable. I would
work directly from the raw file. You can "rewind" it before each search
with the seekg() function.

Create the text file as described above. The write a program to open the
file and read and print the first three lines. Continue in this fashion in
VERY SMALL STEPS. Do not be reluctant to write little asides that are throw
away bits of code. It is much easier to type than it is to think.
Eventually you will get it working, give up, or die. When you have a
program that compiles or almost compiles you can post further questions
here.

Please be aware of the distinction between a chat room and a Usenet
newsgroup. Chat room thrive on the kinds of "cute" spellings that you have
been using, in a NG such as this it only causes revulsion. Most of us are
over 14 years old and we no longer think of this as cute - if we ever did.
Sep 14 '05 #16

P: n/a
osmium wrote:


The problem is pretty vague. It alludes to this "system", a kind of a
phantom thing. It doesn't say that a file will be provided by the
instructor. Or that you should write a program that creates a file. But
clearly a file is required. The easiest way to proceed is to create a
simple file with a text editor. Having done that, you can actually write
the program described.


From what I have seen from 'JT', he is nowhere near starting to work
with files. The easiest solution for him at his stage of knowledge would
IMHO be to have a predefined array of structures in his program wich holds
his data. JT has so many other problems that pushing him into files is
a sure way to create desaster.

--
Karl Heinz Buchegger
kb******@gascad.at
Sep 15 '05 #17

P: n/a
"Howard" <al*****@hotmail.com> wrote in message
news:6h*******************@bgtnsc04-news.ops.worldnet.att.net...

"JT" <ja*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Howard wrote:
"JT" <ja*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
> can complete 4 me? and see wat is the mistake n wat to do next?

can u spk Eng?


sure can speack english...

here the coding i done so far...at least u see wat is my error then i know wat to do next...


That's not English. There are no words "u", "wat", or "i" in English.


Hehehe. Well, two out of three...

Oh, "I" get it - Capitalization Police!

How about extending into Phrase Cop: "i done" is not a phrase, "then I
know what to do" is incorrect.

etc. ad infinitum

Whee!

--
Mabden
Sep 27 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.