Answer to Question #214423 in C++ for Hemambar

Question #214423

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


1
Expert's answer
2021-07-12T07:17:52-0400
#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();




}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS