Slip 24 - A) Create a C++ class Fix Deposit with data members FD_No, Cust_Name, FD_Amt, Interest rate, Maturity amt, Number_of_months. Create and Initialize all values of FixDeposit object by using parameterized constructor with default value for interest rate. Calculate maturity amt using interest rate and display all the details.

Solution:

 #include<iostream.h>

#include<string.h>

#include<math.h>

#include<conio.h>

#include<stdio.h>

class fd

{

int fdno,mnth;

float amt, rate, m_amt;

char nm[20];

public:

fd(int fno, int mnt, float am, float rt, char *name)

{

fdno=fno;

mnth=mnt;

amt=am;

rate=rt;

strcpy(nm, name);

}

void accept()

{

cout<<"\n Enter Details : \n";

cout<<"\n Enter FD No. :  ";\

cin>>fdno;

cout<<"\n Enter Amount :  ";

cin>>amt;

cout<<"\n Enter Month  :  ";

cin>>mnth;

cout<<"\n Enter Name   :  ";

cin>>nm;

}

void display()

{

cout<<"\n FdNo.           :  "<<fdno;

cout<<"\n Month           :  "<<mnth;

cout<<"\n Amount          :  "<<amt;

cout<<"\n Maturity Amount :  "<<m_amt;

cout<<"\n Name            :  "<<nm;

}

void calculate(int rate=20)

{

double yr;

yr=mnth/12.0;

m_amt=amt*pow((1+rate/100), yr);

cout<<"Maturity Details Rs."<<m_amt;

}

};

void main()

{

int fdno,mnth,rate,amt;

char *nm;

fd w(fdno, mnth, amt, rate, nm);

clrscr();

w.accept();

w.calculate();

w.display();

getch();

}        

Post a Comment

0 Comments