5.1

Define a class to represent a bank account. Include the following members:

Data members:

  • Name of the depositor.
  • Account number.
  • Type of account.
  • Balance amount in the account.
    Member functions:
  • To assign initial values.
  • To deposit an amount.
  • To withdraw an amount after checking the balance.
  • To display the name and balance.
    Write a main program to test the program.
Answer

OUTPUT

You have to pay 500 TK to open your account
You have to store at least 500 TK to keep your account active
Would you want to open a account????
If Yes press 1
If No press 0 : 0
Thank you ,see again

5.2

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.

Answer

OUTPUT

enter size of vector : 5

enter 5 elements one by one :

11     22     33     44     55

Now contents p[5] = ( 11  ,  22  ,  33  ,  44  ,  55)

to multiply this vector by a scalar quantity enter this scalar quantity : 2

Now contents :

p[5] = ( 22  ,  44  ,  66  ,  88  ,  110)

to edit a given element enter position of the element : 3

Now enter new value of 3th element : 100

Now new contents :

p[5] = ( 22  ,  44  ,  100  ,  88  ,  110)

to delete an element enter position of the element :2

New contents :

p[4] = ( 22  ,  100  ,  88  ,  110)

5.3

Modify the class and the program of Exercise 5.1 for handling 10 customers.

Answer

Note: Here we will show output only for Three customers. But when you run this program you can see output for 10 customer.

OUTPUT

Enter information for FIRST customer :
You have to pay 500 TR to open your account
You have to store at least 500 TR to keep your account active Would you want to open a account????
If Yes press 1
If No press 0 : 0
Thank you , see again
Enter information for SECOND customer :
You have to pay 500 TR to open your account
You have to store at least 500 TR to keep your account active Would you want to open a account????
If Yes press 1
If No press 0 : 1
Enter name ,account number & account type to create account :
Robin 11123 saving
Would you want to deposit: ?
If HO press 0(zero)
If YES enter deposit amount :
0
Would you want to with draw : ?
If HO press 0(zero)
If YES enter withdrawal amount :
0
Enter information for 3rd customer :
You have to pay 500 TK to open your account
You have to store at least 500 TK to keep your account active Would you want to open a account????
If Yes press 1
If No press 0 : 1
Enter name ,account number & account type to create account :
Billal 11123 fixed
Would you want to deposit: ?
If HO press 0(zero)
If YES enter deposit amount :
1000000
Would you want to with draw : ?
If HO press 0(zero)
If YES enter withdrawal amount :
100000

see details :

Name          Account type          Balance

Account has not created

Robin           saving                       500

Billal            fixed                         900500

5.4

Modify the class and the program of Exercise 5.12 such that the program would be able to add two vectors and display the resultant vector. (Note that we can pass objects as function arguments)

Answer

OUTPUT

Enter 8 elements of FIRST vector :  4  7  8  2  4  3  2  9

Enter 8 elements of SECOND vector :  1  2  3  4  5  6  7  8

sum[8] = (5 , 9 , 11 , 6 , 9 , 9 , 9 , 17)

5.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.

Answer

OUTPUT

Press 1 to display result in meter
Press 2 to display result in feet
What is your option ? 1
Distance = 14.24904 meter or 1424.903931 centimeter


Next Previous