1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstddef>
#include <iomanip>
using namespace std;
class Money
{
public:
friend bool operator >= (const Money& amount1, const Money& amount2);
friend ostream& operator << (ostream& outs, Money& amount);
friend istream& operator >> (istream& ins, Money& amount);
Money mon (Money& amount1);
Money year (Money& amount1);
Money pay (Money& amount1);
Money give (Money& amount1);
Money ();
Money(int size1);
Money(const char a[]);
Money(const Money& money_object);
~Money();
int lenght() const;
void input(istream& ins);
void output();
private:
char *name;
int size;
double value;
double a_month;
double a_year;
double total_pay;
double total_give;
double m;
};
Money::Money(const char a[]): size(strlen(a))
{
name= new char[size+1];
strcpy(name, a);
}
Money::Money(const Money& money_object):size(money_object.lenght())
{
name= new char[size+1];
strcpy(name, money_object.name);
}
bool operator >= (const Money& amount1, const Money& amount2)
{
return (amount1.value >= amount2.value);
}
Money Money::mon ( Money& amount1)
{
Money temp;
temp.a_month= amount1.value * 0.4;
return temp;
}
Money::Money(): size(500)
{
name= new char[size+1];
name[0]='\0';
}
int Money::lenght() const
{
return strlen(name);
}
Money::Money(int size1): size(size1)
{
name= new char[size+1];
name[0]='\0';
}
Money::~Money()
{
delete[] name;
}
void Money::input(istream& ins)
{
ins.getline(name, size+1);
}
Money Money::year (Money& amount1)
{
Money temp;
temp.a_year= amount1.a_month * 12.0;
return temp;
}
Money Money::pay (Money& amount1)
{
Money temp;
temp.total_pay= amount1.a_year * 7.0;
return temp;
}
Money Money::give (Money& amount1)
{
Money temp;
total_give= amount1.total_pay - 50000.0;
return temp;
}
void Money::output()
{
cout<< "You will pay a month " <<"RM "<<a_month<< endl << endl;
cout<<"So the total amount that you will pay a year is"<<"RM "<<a_year<<endl;
cout<< "You will continue to pay for 7 years" << endl << endl;
cout<<"The total amount of money you pay all the 7 years is"<<"RM "<<total_pay<<endl;
cout<< "The amount of interest money the Bank take is RM 50,000"<<endl;
cout<<"So the Total amount of money the Bank will give you is"<<"RM "<<total_give<<endl;
}
ostream& operator << (ostream& outs, Money& amount)
{
outs<< amount.name;
return outs;
}
istream& operator >> (istream& ins, Money& amount)
{
ins >> amount.value;
return ins;
}
int main()
{
system ("color 5");
Money com, salary(500), our("Bello maimaje"), min, h;
cout<< "Hello\n" << "welcome to " ;
cout<< our;
cout<<" Bank"<<endl;
cout<<"This a program to help you if you want to take a loan from a Bank.\n"
<< "You can know the following:\n" << "1- If your salary allows you to take a loan.\n"
<< "2- The toltal amout of money the Bank will give you.\n"
<< "3- The total amount of money you will pay a month and a year.\n"
<< "4- The Total money you will pay all the years\n"
<< "5- The interect the Bank will take from you\n" << endl;
cout<< "What is your name?\n";
salary.input(cin);
system ("cls");
system ("color 3");
cout<< "OK " ;
cout<< salary;
cout<< endl;
cout<< "What is your salary?\n" ;
salary.input(cin);
system ("cls");
system ("color 2");
cout<< "Your Salary is : " ;
cout<< salary;
cout<< endl;
if(salary >= 10000)
{
salary=salary.mon(salary);
salary=salary.year(salary);
salary=salary.pay(salary);
salary=salary.give(salary);
system ("cls");
system ("color 3");
salary.output();
}
else
{
cout<<"Sorry, your salary is not enough to have a loan\n"<<endl;
}
cout<< "Thank you ";
cout<< salary;
char c;
cin>>c;
return 0;
}
|