Answer to Question #280906 in C++ for Muhammad Haris

Question #280906

Write a program that incorporates both the bMoney class from Exercise 8 and the sterling


class from Exercise 11. Write conversion operators to convert between bMoney and


sterling, assuming that one pound (£1.0.0) equals fifty dollars ($50.00). This was the


approximate exchange rate in the 19th century when the British Empire was at its height


and the pounds-shillings-pence format was in use. Write a main() program that allows


the user to enter an amount in either currency and then converts it to the other currency


and displays the result. Minimize any modifications to the existing bMoney and sterling


classes.

1
Expert's answer
2021-12-20T10:03:42-0500
#include<iostream>
#include <string>
using namespace std;
long double mstold(string s){
	
    long double x = stold(s);
    return x;
}
string ldtoms(long double s){
	string str = to_string(s);
	return str;
}
class bMoney
{
private:
    long double money;
public:
    bMoney(){


	}
    bMoney(string s){
    	
        money = mstold(s);
        
    }
    void madd(bMoney m1, bMoney m2){
    	
        money = m1.money + m2.money;
    }
    void getmoney(){
        string st;
        cin >> st;
        money = mstold(st);
        
    }
    
    void putmoney(){
        cout<<ldtoms(money)<<

int main()
{
    char ch;
    do{
    bMoney m1, m2;
    cout<<"Enter money string :";
    m1.getmoney();
    
    cout<<"Enter money string :";
    m2.getmoney();
    bMoney m3;
    m3.madd(m1, m2);
    m1.putmoney();
    m2.putmoney();
    cout<<"After addition: ";
    m3.putmoney();
  cout<<"Enter y to continue or n to stop\n";
  cin>>ch;	
    	
	} while(ch != 'n');
	cout<<"Terminated successfully\n";
    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