Hello! I am stuck on a question. I can figure out how to ask the user and calcul
ID: 3673112 • Letter: H
Question
Hello! I am stuck on a question. I can figure out how to ask the user and calculate the right interest . But adding a loop has me thrown off . any ideas ? Here is the problem :
Simple interest can be calculated as follows:
Interest = P*r*t where P = the principle, r = the interest rate, and t = time in years
For example, if a person starts with a principle = $100.00 at an interest rate = 0.04 where time = 3 years. The amount of interest is 12 dollars or 100.0 * 0.04 * 3 = 12
Design a class called Interest whose constructor accepts three arguments. The principle (in dollars), the rate (in decimal format), and the number of years represented as a variable called time (an integer). Besides the appropriate gets (accessors) and sets (mutators), it should have a method named getInterest that returns the interest, in dollars that the investment has earned.
Demonstrate the class in a program that uses a while loop (period < = time) to display the interest earned for each year of a time specified by the user. For example, if principle is $100.00, the interest rate is 0.04 for a three-year time period, it should display a report similar to the one shown here.
Year Interest Earned
14 28 3 12
Input Validation: Do not accept a negative number for principle and rate, and do not accept any value less than one for time traveled (use while loops to test for principle > = 0, and rate > = 0, and another while loop to test for time > 1).
Explanation / Answer
#include <iostream.h>
#include<conio.h>
class getinterest
{
int p,t;float r;
public:
getinterest(int i, float j,int k)
{
p=i;
r=j;
t=k;
while(p!=0&&r!=0&&t>1)
{
float d=p*r*t;
cout<<"the simple interest is"<<d;
}
}
void show()
{
cout<<"The principle amount is " <<p ;
cout<<"The rate of interest is" <<r;
cout<<"The time is in years " << t;
}
};
void main()
{
clrscr();
int x,y;float z;
cout<<"Enter the principle amount is ";
cin>>x;
cout<<"Enter the rate of interest is";
cin>z;
cout<<"Enter the time is in years ";
cin>>y;
getinterest ob(x,y,z);
ob.show();
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.