65 834
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #26934 in C++ for leslie ochieng

Question #26934
write a class with method(member function)that calculates and return simple interest .the class stores the principal,time and the rate in data members with the rate as a constant of 12% , simple interest=principal X rate X time
Expert's answer
#include <iostream>
using namespace std;
class MyClass {
public :
& MyClass() {
& principal = 0;
& time = 0;
& }
& MyClass(double principal, double time) {
& this->principal = principal;
& this->time = time;
& }
& ~MyClass() {
& }
& double calc_simple_interest() const{
& return principal * time * rate / 100;
& }
& void show() {
& cout << "principal = " << principal << endl;
& cout << "time = " << time << endl;
& cout << "rate = " << rate << "%" << endl;
& }
&
private :
& double principal;
& double time;
& static const int rate = 12;
};

int main()
{
cout << "Creating object of MyClass with random principal and time..." << endl;
MyClass * New_obj = new MyClass(double(rand()%(100)) / 10, double(rand()%(100)) / 10);
New_obj->show();
cout << "Calculating simple interst..." << endl;
cout << "simple interest = " << New_obj->calc_simple_interest() << endl;
system("PAUSE");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions