Programs (2)
Programs (2)
UNIT-2
1. Write a program to read a matrix of size m*n from the keyboard and display the same on the
screen using function
2. Write a function power() to raise a number m to power n. The function takes a double
value for m and int value for n and returns the result correctly. Use a default value of 2 for n
to make the function to calculate the squares when this argument is omitted. Write a main
that gets the values of m and n from the user to test the function.
3. Define a class to represent a bank account. Include the following members:
Data members: 1. Name of the depositor. 2. Account number. 3. Type of account. 4. Balance
amount in the account.
Member functions: 1. To assign initial values. 2. To deposit an amount. 3. To withdraw an
amount after checking the balance. 4. To display the name and balance. Write a main
program to test the program.
4. Write a class to represent a vector (a series of float
values). Include member functions to perform the
following tasks:
(a) To create the vector.
(b) To modify the value of a given element.
(c) To multiply by a scalar value.
(d) To display the vector in the form (10, 20, 30 …) Write a program to test your class.
5. Create two classes DM and DB which store the value of distances. DM stores distances in
meters and centimeters and DB in feet and inches. Write a program that can read values
for the class objects and add one object of DM with another object of DB. Use a friend
function to carry out the addition operation. The object that stores the results may be a DM
object or DB object, depending on the units in which the results are required. The display
should be in the
format of feet and inches or meters and centimeters depending on the object on display.
UNIT-3
1. 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