Interest Calculation [munie,azam,haniff]
Page 1 of 1
Interest Calculation [munie,azam,haniff]
- Code:
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
//base class..
class interest
{
public:
int x, y, z;
public:
interest(); //constructor..
double rate, loan;
int time, user;
void nilai(double x, int y, double z); //declaration inline..
virtual void message(void)
{
cout <<"\n *******************************\n";
cout <<" * THE INTEREST CALCULATIONS *\n";
cout <<" *******************************\n\n";
cout <<" SILA PILIH JENIS BAYARAN:\n";
cout <<"\n 1.Tahunan\n 2.Bulanan\n 3.Harian";
cout <<"\n\n Masukkan no pilihan anda: ";
cin >>user;
cout <<" ********************************";
}
};
//implement interest constructor..
interest::interest()
{
x = y = z = 0;
}
//inline statements..
inline void interest::nilai(double x, int y, double z)
{
loan = x;
time = y;
rate = z;
}
//derived class..
class calInterest:public interest
{
public:
double kira(int user)
{
if (user==1)
return (loan * rate * time)/100;
else if (user==2)
return (loan * rate * time /12)/100;
else if (user==3)
return (loan * rate * time /365)/100;
}
double kiraCom(int user)
{
return loan* pow(1 + rate/100,time);
}
void tunjuklah()
{
double x, z;
cout <<"\n\n Masukkan jumlah pinjaman:RM";
cin >> x;
cout << "\n Kadar peratusan(%): ";
cin >> z;
cout << "\n Tempoh bayaran: ";
cin >> y;
nilai(x, y, z);
cout <<"\n ********************************";
cout <<"\n Interest ialah RM "<<kira(user);
cout <<"\n ********************************";
cout <<"\n Compound ialah RM "<<kiraCom(user);
cout <<"\n ********************************\n\n";
}
};
int main()
{
string d;
string t = "tidak";
//do statements..
do
{
calInterest *tajuk; //declare pointed object
tajuk=new calInterest; //create memory for class calInterest
tajuk->message(); //object access to message()
tajuk->tunjuklah(); //object access to display()
delete tajuk; //delete memory created on tajuk
cout <<" Mau cuba lagi!!!!!.....\n";
cout <<" ****************************************************\n";
cout <<" Taip 'ya' untuk teruskan atau 'tidak' untuk berhenti: ";
cin >> d;
cout <<endl<<endl;
}
//while statements..
while (d!= t); //if true the program will be return..if not the program will close..
{
cout <<" Terima kasih kerana mencubanya!!....\n\n";
}
system("pause");
return 0;
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|