473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
17 1999
* 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
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
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
You really should do your own homework.

Sep 12 '05 #5
> You really should do your own homework.


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

ben
Sep 12 '05 #6
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
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
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
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

"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
"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
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
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

"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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
6
by: Alan Silver | last post by:
Hello, I'm just taking my first steps at doing layout with CSS, and I'm having a few problems. This could be because I don't really understand what I'm doing yet!! I would really appreciate any...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
7
by: zoro | last post by:
how many recursive calls will quicksort make in the worst case for a file of N items? thank you
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
10
by: wazzup | last post by:
C++ is new to me and I'm trying solve this problem but get stuck. Please help me out. Below is the task and after that is what i got so far. Create a program to print nested squares Input:...
0
by: xprimus | last post by:
Can anyone help me with this, I have a linked image in a tale cell and whenever I click on the image it expands, not only that I have to click on it again to get the link to go. These are the...
4
by: glbdev | last post by:
Hi, I posted this question yesterday but didn't get the answer I needed. I am DESPERATE to get this working so I'm re-posting it because I don't think I worded it correctly. I have a GridView...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.