Create a class called bMoney. It should store money amounts as long doubles. Use the function ms_to_ld() to convert a money string entered as input into a long double, and the function ld_to_ms() to convert the long double to a money string for display. You can call the input and output member functions getmoney() and putmoney(). overload the operators +,-,*,and / appropriately
#include<iostream>
#include <sstream>
using namespace std;
class bMoney{
private:
string money;
public:
string getmoney(){
cout<<"Enter them money\n";
cin>>money;
return money;
}
long double ms_to_ld(){
long double x;
x = stold(getmoney());
return x;
}
string ld_to_ms(){
stringstream stream;
stream << ms_to_ld();
return stream.str();
}
void putmoney(){
cout<<"The money is\t"<<ld_to_ms()<<endl;
}
bMoney operator +(bMoney b){
bMoney y;
y.money = this->ms_to_ld() + b.ms_to_ld();
return y;
}
bMoney operator -(bMoney b){
bMoney y;
y.money = this->ms_to_ld() - b.ms_to_ld();
return y;
}
bMoney operator *(bMoney b){
bMoney y;
y.money = this->ms_to_ld() * b.ms_to_ld();
return y;
}
bMoney operator /(bMoney b){
bMoney y;
y.money = this->ms_to_ld() / b.ms_to_ld();
return y;
}
};
int main(){
bMoney b;
b.putmoney();
}
Comments
Leave a comment