Wednesday 12 October 2011


CALCULATION OF BANK INTEREST USING DEFAULT ARGUMENT

AIM:
            To calculate bank interest using the concept of default arguments


ALGORITHM:
1.      Start the process.
2.      Create a class with sufficient data members and two member functions.
3.      The default values are specified in the class
4.      The two member functions are defined outside the class.
5.      The object is created for the class and the member function is called from the main function.
6.      The function assigns a default values to the parameter which does not have a matching argument and function call.
7.      If the values for the parameter are specified then the default value is not taken.
8.      The bank interest is calculated.
9.      Display the result.
10.  Stop the process.

PROGRAM:
#include<iostream.h>
#include<conio.h>
class arg
{
            float sum,amount,p,n,r;
            public:
                        float value(float p,int n,float r=0.15);
                        void print(char ch='*', int len=13);
};
float arg::value(float p,int n, float r)
{
            int year=1;
            float sum=p;
            while(year<=n)
{
                        sum=sum*(1+r);
                        year=year+1;
            }
            return(sum);
}
void arg:: print(char ch, int len)
{
            for(int i=1;i<=len;i++)
            cout<<ch;
            cout<<"\n";

void main()
{
            arg a1;
            float tot, res;
            clrscr();
            a1.print();
            tot=a1.value(5000,5);
            cout<<tot<<endl;
            a1.print();
            cout<<endl;
            res=a1.value(5000,1,0.20);
            cout<<res;
            getch();
}


OUTPUT:
            ****************************
            10056.786133
            ****************************
            6000

RESULT:
Thus the program for calculation of simple interest using default arguments was executed.

0 comments:

Post a Comment