#include <iostream>
using namespace std;
class SI
{
float pple;
float rate;
float n;
public:
//
// We have written only parameterized CTOR
// In this case, C++ DOES NOT PROVIDE US WITH
// default constructor.
//
SI(float rate, float n)
{
this->rate = rate;
this->n = n;
}
void SetInput(float pple);
void SetInput(float pple, float n, float r);
float CalculateSI();
};
void SI::SetInput(float pple)
{
this->pple = pple;
}
void SI::SetInput(float pple, float n, float rate)
{
this->pple = pple;
this->rate = rate;
this->n = n;
}
float SI::CalculateSI()
{
return (pple *rate * n) /100;
}
int main()
{
SI s1;
s1.SetInput( 1000);
s1.SetInput(1000, 6.7, 4);
cout << endl <<"\t Simple intereset = "<< s1.CalculateSI()<< endl;
return 0;
}
/*
ctor_only_param.cpp:44: error: no matching function for call to ‘SI::SI()’
ctor_only_param.cpp:16: note: candidates are: SI::SI(float, float)
ctor_only_param.cpp:5: note: SI::SI(const SI&)
*/
Sunday, December 18, 2011
Only parameterized CTOR: Demo (along with error by g++)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment