Practical File Programs Sem-04 BCA KUK

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

C++ programs for the practical file (Sem-04)

1. Write a program to convert Dollar type to Rupees type, where Dollar is a class having the dollar as an instance
variable and Rupees is a class having rupees as an instance variable using the casting operator function.
2. Write a program to convert Dollar type to Rupees type, where Dollar is a class having the dollar as an instance
variable and Rupees is a class having rupees as an instance variable using the constructor function.
3. Assume that a bank maintains two kinds of accounts for customers, one called a savings account and the other as
a current account. Both accounts provide deposit and withdrawal facilities. Maximum withdrawal at a time in
case of a saving account is not more than 10,000 Rs. and in the current account, it is 50,000 Rs. The account
holders should also maintain a minimum balance (5,000 Rs. in the case of a savings account and 10,000 Rs. in
the case of a current account) and if the balance falls below this level, a service charge is imposed. The service
charge in the case of the saving account is 500 Rs. but in the case of the current account, it is 1000 Rs.
Create a class account that stores customer name, account number, balance and type of account. From this device
the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member
functions in order to achieve the following tasks:
(a) Accept deposit from a customer and update the balance.
(b) Display the balance.
(c) Permit withdrawal and update the balance.
(d) Check for the minimum balance, impose penalty, necessary, and update the balance.

Design the main() method to implement this hierarchical inheritance.


4. The class master derives information from both account and admin classes which in turn derive information from
the class person. Define all four classes and write a program to create, update, and display the information
contained in master objects. (Multipath Inheritance).
The person class has instance variables- name and code. The account has an instance variable- pay. The admin
class has instance variables- experience.
Note: Use constructors for initialization of instance variables.
5. Design a Person class having two instance variables- name and age. Write a program to find the elder person out
of two persons by designing an elder member function. Pass the object (second person) to this function and
return the object who is elder from the elder function. Use this pointer inside the elder function to return the
called object.
6. Consider a book shop that sells both books and video-tapes. Design a class media and derive two classes- book
and tape from media class. The class media have instance variables- title and price of a publication. The class
book has an instance variable playtime. A function display() is defined in each class to display the contents of the
class. The display() function is defined as a virtual function in the media class.
7. Create an abstract base class called shape. Use this class to store two double-type values that could be used to
compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add to
the base class, a member function get_data() to initialize base class data members and another member function
display_area() to compute and display the area of figures. Make display_area() as a pure virtual function and
redefine this function in the derived classes to suit their requirements.
Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively,
and display the area.
Remember the two values given as input will be treated as lengths of two sides in the case of rectangles and as
base and height in the case of triangles, and used as follows:
Area of rectangle = x * y
Area of triangle = ½ * x * y
8. Write a program to design two manipulators- currency and form. The currency manipulator display Rs and the
form manipulator sets -trailing zeros, positive sign for positive numbers, precision upto 2 places, width of 10 and
use * to fill vacant places.
9. Write a function template for sorting an array using Bubble sort.
10. Design a Stack template class and implement basic stack operations.
11. Design a Queue template class and implement basic queue operations.
12. Write a class template to represent a generic vector. 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 following form (10, 20, 30 …)
13. Write a program with the following:
(a) A function to read two double-type numbers from the keyboard.
(b) A function to calculate the division of these two numbers.
(c) A try block to throw an exception when a wrong type of data is keyed in.
(d) A try block to detect and throw an exception if the condition “divide by zero” occurs
(e) Appropriate catch block to handle the exceptions thrown
14. Write a program to design and implement user-defined exceptions. Design a function to find the square root of
the passed parameter but when the parameter value is below 0.0001 then pass a user-defined exception with the
message “number is too small”.
15. Write a program to design and implement a catch-all block (catch(…)). Take an example to design a function
test that receives an int type parameter and throws int, float, char, and double type exceptions based on parameter
values 1,2,3, and 4 respectively. Design a catch-all block to catch all exceptions.
16. Write a program that reads a text file and creates another identical file except that every sequence of consecutive
blank spaces is replaced by a single space.
17. Write a program that reads a text file and counts the total number of characters, vowels, consonants, words,
blanks, lines, tabs, lowercase alphabets, uppercase alphabets, special symbols, and digits.
18. Design a program to implement a Random access file with operations – inserting a record, deleting an existing
record, updating an existing record, retrieving a particular record, and displaying all records. Implement by
taking the example of an employee.

You might also like