MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Friday, September 27, 2013

dinamic initialization of constructor

#include <iostream>

using namespace std;
class student
{
    private:
    int year;
    int amount;
    float total;
    public:
    student(int a,int y,float r=.12);
    student(int a,int y,int d);
    void display();
};
 student::student(int a,int y,float r)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+total*r;
    }
}
 student::student(int a,int y,int d)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+amount*((float)(d)/100);
        amount=total;
    }
}
void student::display()
{
    cout<<"The resultant value is "<<total<<endl;
}
int main()
{
    int a,b,c;
    float f;
    while(cin>>a>>b>>c)
    {
        student ob(a,b,c);
        ob.display();
        cin>>a>>b>>f;
        student ob1(a,b,f);
        ob1.display();
        cin>>a>>b;
        student ob2(a,b);
        ob2.display();
    }
    return 0;
}

No comments:

Post a Comment