6.1

Design constructors for the classes designed in Programming Exercise 5.1 through 5.5 of Chapter 5.

Answer

Study on Constructor and then see solution of chapter 5.

6.2

Define a class String that could work as a user-defined string type. Include constructors that will enable us to create an uninitialized string:

String s1; // string with length 0
And also initialize an object with a string constant at the time of creation like
String s2(“Well done!”);
Include a function that adds two strings to make a third string. Note that the statement
S2 = s1;
will be perfectly reasonable expression to copy one string to another.
Write a complete program to test your class to see that it does the following tasks:

  • (a) Creates uninitialized string objects.
  • (b) Creates objects with string constants.
  • (c) Concatenates two strings properly.
  • (d) Displays a desired string object.
Answer

OUTPUT

Well done
Badly done
Well done Badly done

6.3

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise “Required copies not in stock” is displayed.
Design a system using a class called books with suitable member functions and constructors. Use new operator in constructors to allocate memory space required.

Answer

OUTPUT

Enter author name : shahani

and title of book in small latter : computer algorithm

*********book detail *********

Title                                  Author Name                    Stock copy

computer algorithm          shahani                             80

How many copies of this book is required : ?  78

Total price = 14079 TK

6.4

Improve the system design in Exercise 6.3 to incorporate the following features:

  • (a) The price of the books should be updated as and when required. Use a private member function to implement this.
  • (b) The stock value of each book should be automatically updated as soon as a transaction is completed.
  • (c) The number of successful and unsuccessful transactions should be recorded for the purpose of statistical analysis. Use static data members to keep count of transactions.
Answer

OUTPUT

Enter author name in small letter  :  abdus sattar

title of book in small letter  :  complete solution of balagurusamy(c++)

*********book detail **********

Title                                                          Author Name                   Stock copy

complete solution of balagurusamy(c++) abdus sattar                 300

How many copies of this book is required : ? 100

Total price = 12000  TK

Title                                             stock copy                Price per book

object oriented programming with c++ 200              120.5

programming in ANCI              150                                115.75

electronic circuit theory            50                                  140

computer algorithm                   80                                 180.5

complete solution of balagurusamy(c++)  200          120

Successful transaction                            unsuccessful transaction

1                                                                            0

To edit price Enter author name in small letter : shahani

title of book in small letter : computer algorithm

Enter new price : 200

************details after edit price*****************

Title                                              stock copy                  Price per book

object oriented programming with c++   200                   120.5

programming in ANCI                150                                     115.75

electronic circuit theory              50                                       140

computer algorithm                     80                                       200

complete solution of balagurusamy(c++)    200                 120


Next Previous