Friday, 22 June 2012

write a c++ program to create a class FDA accout containing member

/*
write a c++ program to create a class FDA accout containing member as:
-fdno
-name
-amt
-interest rate
-maturity amt
-number of months
use parameterised constructor to set appropiate details where interest rate
should be a default argument. calculate maturity amt using interest rate and
display all the details.
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class    FDA
{
    long int amt;
    int fno;
    char name[22];
    float interest_rate;
    float mat_amt;
    int no_of_months;
    public:
           FDA(int f,char *s,int a,int n,float r=0.15);
           void display()
           {
            cout<<"\n\nFix deposit number : "<<fno;
            cout<<"\n\nCustomer name : "<<name;
            cout<<"\n\nPrinciple amount : "<<amt;
            cout<<"\n\nInterest rate : "<<interest_rate;
            cout<<"\n\nNo_of_months : "<<no_of_months;
            cout<<"\n\nMaturity amount : "<<mat_amt;
           }
};
FDA::FDA(int f,char *s,int a,int n,float r)
{
    fno=f;
    strcpy(name,s);
    amt=a;
    no_of_months=n;
    interest_rate=r;
    mat_amt=0;
    for(int i=1;i<=n;i++)
    mat_amt=mat_amt+(amt*interest_rate);
}
int main()
{
    long int x;
    int f,nom,a;
    char n[20];
    float r;
    clrscr();
        cout<<"\n\nEnter Fix deposit number : ";
        cin>>f;
        cout<<"\n\nEnter Customer name : ";
        cin>>n;
        cout<<"\n\nEnter Amount : ";
        cin>>a;
        cout<<"\n\nEnter Number of months : ";
        cin>>nom;
        FDA FD(f,n,a,nom);
        FD.display();
        getch();
        return(0);
}
/*

Enter Fix deposit number : 12


Enter Customer name :
asd


Enter Amount : 12


Enter Number of months : 2


Fix deposit number : 12

Customer name : asd

Principle amount : 12

Interest rate : 0.15

No_of_months : 2

Maturity amount : 3.6
*/

No comments: