Tuesday, July 14, 2009

C++ Programming In need of your Help Guys?

Imagine a publishing company that markets both books and audio cassettes versions of its works. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class, derive two classes: book, which adds page count (type int; and tape, which adds a playing time (type int) in minutes. Each of these classes should have a getdata() function to get its data from the user and a putdata() function to display its data.





Write a main() function to test the book and tape classes by creating instances of , asking the user to fill data with getdata(), and then displaying with putdata() through menus.

C++ Programming In need of your Help Guys?
This looks like a homework assignment and not a very difficult one. Maybe you should put your work here first and we could review it and make suggestions. You'll never be a good programmer if you don't learn the language.
Reply:Hmmmm..You have got this one from NIIT right? I've solved it.Its damn easy. Try it and ask doubt.
Reply:I agree with the comment above this does look like homework.





Here is a hint on how to solve this:





The Publication class is to be treated like a base class from which you derive the book and tape class. Both these children must inherit from the publication class so as to be able to set the price of a certain book or tape.





Then in your main() function instantiate the book and tape class by using them





example:


Book b1;


Book b2;


Tape t1;


Tape t2;





set the data of these books and tape by using the putData() function





example: putData(string bookName, float price, int playingTime = 0, int pageCount = 0)





the reason there are 0's next to payingTime and pageCount is because if you do not send a value pageCount will be giving the default value of 0.





Now go do your homework and get that A


No comments:

Post a Comment