Answer to Question #248610 in C++ for John

Question #248610
Create a class called bMoney. It should store money amounts as long doubles. Use the
function mstold() to convert a money string entered as input into a long double, and
the function ldtoms() to convert the long double to a money string for display. (See
Exercises 6 and 10.) You can call the input and output member functions getmoney()
and putmoney(). Write another member function that adds two bMoney amounts; you can
call it madd(). Adding bMoney objects is easy: Just add the long double member data
amounts in two bMoney objects. Write a main() program that repeatedly asks the user to
enter two money strings, and then displays the sum as a money string. Here’s how the
class specifier might look:
class bMoney
{
private:
long double money;
public:
bMoney();
bMoney(char s[]);
void madd(bMoney m1, bMoney m2);
void getmoney();
void putmoney();
};
1
Expert's answer
2021-10-10T01:49:00-0400
#include <iostream>
#include <string>


using namespace std;


class bMoney{
private:
	long double money;
public:
	bMoney();
	bMoney(char s[]);
	void madd(bMoney m1, bMoney m2);
	void getmoney();
	void putmoney();
};


bMoney::bMoney(){


}
bMoney::bMoney(char s[]){
	//convert a money string entered as input into a long double
	this->money=stold(s);
}
void bMoney::madd(bMoney m1, bMoney m2){
	long double sum=m1.money+m2.money;
	cout<<"Sum = "<<sum<<"\n";
}
void bMoney::getmoney(){
	cout<<"Enter money: ";
	cin>>money;
}
void bMoney::putmoney(){
	cout<<"Money: "<<money<<"\n";
}




int main()
{


	bMoney b1,b2;
	b1.getmoney();
	b2.getmoney();


	b1.putmoney();
	b2.putmoney();
	b1.madd(b1,b2);
	


	int k;
	cin>>k;


	return 0;
}

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