Untitled Document 6
Untitled Document 6
BRANCH:CO3K
Practical:8
#include <iostream>
using namespace std;
class SimpleInterest {
private:
float principal;
float duration;
static float rate_of_interest;
public:
void readData() {
cout << "Enter Principal amount: ";
cin >> principal;
cout << "Enter Duration (in years): ";
cin >> duration;
}
static void setRateOfInterest(float rate) {
rate_of_interest = rate;
}
// Function to calculate simple interest
float calculateInterest() {
return (principal * duration * rate_of_interest) / 100;
}
void display() {
cout << "Principal: " << principal << endl;
cout << "Duration: " << duration << " years" << endl;
cout << "Rate of Interest: " << rate_of_interest << "%" << endl;
cout << "Simple Interest: " << calculateInterest() << endl;
}
};
float SimpleInterest::rate_of_interest = 0;
int main() {
SimpleInterest si;
si.readData();
SimpleInterest::setRateOfInterest(5.5); // Set the rate of interest
si.display();return 0;