Question

In: Computer Science

C++(OOP)plz SOLVE THE PROBLEM ACCORDING TO INSTRUCTIONS Imagine you are on a trip around Europe and...

C++(OOP)plz SOLVE THE PROBLEM ACCORDING TO INSTRUCTIONS
Imagine you are on a trip around Europe and have collected currencies from
the different countries that you have travelled.
You are to write a simple money counting program. Your program will be able
to deal in the following three currencies
a) Pakistani Rupee
b) Turkish Lira
c) Pound Sterling
 You must make a class called Currency. Create its data members and any
member functions you require. Your class should be written such that you
are able to execute statements like these in your main function:
C_Sum =100 C1 + 11 (C2) + 56 (C3)
where C1, C2 and C3 represent different currency bank notes.
% C1 - displays C1 amount in all three currencies.
C1 [“pkr”]– displays the C1 amount in PKR along with the date and current
exchange rate of the input currency with pkr.
C1 [“gbp”]– displays the C1 amount in Pound Sterling along with the date and
current exchange rate between the input currency and pounds.
A FEW GUIDELINES
 This question involves operator overloading and needs to be
accomplished using classes.
 Your main function must be as small as possible. This implies you must
use class constructors and class functions to accomplish everything in assignment
Make a separate class called Conversion_Rate. Use constructors to take
inputs for the exchange rate for the day. Display them every time you
display the total sum.
 Every time you perform a money conversion, your program must contact
the Conversion_Rate class class to provide the exchange rates for the
given day. You are to apply the concept of friend functions/ friend
classes (as you need) to allow this class to share its information.

Solutions

Expert Solution

We cannot overload binary operator '%' as unary operator as given in the question, therefore, I have used - (minus) operator for the function of %C1

Output:

Raw Code:

#include<iostream>
#include<ctime>
using namespace std;
class Currency
{
   private:
       string type;   // currency type
       float val;       // amount
   public:
   Currency(string typ="",float v=0)   // constructor  
   {   type=typ;   val=v;   }
  
   void print()       // print data
   { cout << val << " " << type << endl<<endl; }
  
   Currency operator + (Currency const &);
   void operator - ();
   void operator [] (string);
      
   friend class Conversion_Rate;   // friend class
};

class Conversion_Rate{
   public:
   float convert(Currency const &obj,string type)   // convert currency
   {
       if(obj.type=="pkr")
       {
           if(type=="tl")
               return 0.052 * obj.val;
           else if(type=="gbp")
               return 0.0048 * obj.val;
           return obj.val;
       }
       else if(obj.type=="tl")
       {
           if(type=="pkr")
               return 19.22 * obj.val;
           else if(type=="gbp")
               return 0.093 * obj.val;
           return obj.val;
       }
       else if(obj.type=="gbp")
       {
           if(type=="pkr")
               return 207.7 * obj.val;
           else if(type=="tl")
               return 10.8 * obj.val;
           return obj.val;
       }
       return 0.0;
   }
};
  
Currency Currency:: operator + (Currency const &obj)   // add different currencies
{
   Conversion_Rate object;
Currency res;
res.type = type;
res.val = val + object.convert(obj,type);

return res;
}

void Currency:: operator - ()
{
   Conversion_Rate object;
   // convert to all currencies
cout<<val<<" "<<type<<" = "<<object.convert(*this,"pkr")<<" pkr"<<endl;
cout<<val<<" "<<type<<" = "<<object.convert(*this,"tl")<<" tl"<<endl;
cout<<val<<" "<<type<<" = "<<object.convert(*this,"gbp")<<" gbp"<<endl<<endl;
}
  
void Currency:: operator [] (string t)
{
   Conversion_Rate object;
  
   // convert to specified currency
cout<<object.convert(*this,t)<<endl;
  
// date
time_t now = time(0);
cout<<"Date: "<<ctime(&now);
  
// Exchange rate
Currency obj(type,1);
cout<<"Exchange rate: 1 "<<type<<" = "<<object.convert(obj,t)<<" "<<t<<endl<<endl;
}
int main()
{
   // "pkr" => Pakistani Rupee
   // "tl" => Turkish Lira
   // "gbp" => Pound Sterling
  
Currency C1("pkr",12), C2("tl",11), C3("gbp",10);
  
// overloading + operator
Currency C4 = C1+C2+C3;
C4.print();
  
// overloading - operator to convert to all currencies
-C1;
  
// convert the object to specified currency along with date and exchange rate
C2["pkr"];
  
}


Related Solutions

you have just returned from a long trip to Europe. He started the trip with $6,300...
you have just returned from a long trip to Europe. He started the trip with $6,300 in his pocket. He spent 2,120 traveling throughout euroland, 4,900NKr in Norway, and £1,760 in the U.K. The exchange rates were $1 = .8912, 1NKr = $.1219, and £1 = $1.3234. How many dollars did he have left by the time he returned to the U.S.? $994.69 $1,018.72 $1,143.67 $1,255.30 $1,345.88
You are a freshman in college and are planning a trip to Europe when you graduate...
You are a freshman in college and are planning a trip to Europe when you graduate from college at the end of four years. You plan to save the following amounts annually, starting today: $550, $720, $720, and $800. If you can earn 7.15 percent annually, how much will you have at the end of four years? (Round answer to 2 decimal places, e.g. 15.25. Do not round factor values.)
Instructions to solve the problem: You are required to use a financial calculator or spreadsheet (Excel)...
Instructions to solve the problem: You are required to use a financial calculator or spreadsheet (Excel) to solve the problem related to the cost of capital. You are required to show the following 3 steps for the problem. (i) Describe and interpret the assumptions related to the problem. (ii) Apply the appropriate mathematical model to solve the problem. (iii) Calculate the correct solution to the problem. Submit all answers as percentages and round to two decimal places. Problem: Cosa Nostra...
You want to take out a personal loan to finance a trip to Europe. You estimate...
You want to take out a personal loan to finance a trip to Europe. You estimate that you will need $7500 and the bank offers you a 4-year term at 1.98%, compounded quarterly.What will your payments be each month?
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
2. You are planning a trip to Europe and Japan and want to change U.S. dollars...
2. You are planning a trip to Europe and Japan and want to change U.S. dollars into euros and yen. Your bank provides the following quotes: Currency Bid Ask Euros $1.194 $1.245 Yen $0.009245 $0.00967 (a) What are the bank's relative bid/ask spreads for the two currencies? (b) How much would you lose if you converted $500 into euros and $500 into yen respectively, and then back into dollars? (c) If you need to convert €1,000 Euros into Japanese Yen,...
YOU WON A TRIP TO LONDON AND PARIS...TRAVEL THE WHOLE OF EUROPE WITH A TRAVEL PASS...
YOU WON A TRIP TO LONDON AND PARIS...TRAVEL THE WHOLE OF EUROPE WITH A TRAVEL PASS AND TAKE THE FAMOUS BULLET TRAIN "EUROSTAR"? THE AWARD IS $20,000.00 AND YOU HAVE ONE MONTH TO SEE THE MAJOR CITIES IN EUROPE, WHERE WOULD YOU GO AND WHY? INCLUDE YOUR BUDGET AND DISCUSS YOUR REASON WITH REAL LIFE EXAMPLES.
Hide Assignment Information Instructions In this assignment, you will be practicing the Java OOP skills we've...
Hide Assignment Information Instructions In this assignment, you will be practicing the Java OOP skills we've learned this week in implementing a customized mutable Array class. Please read the following requirements carefully and then implement your own customized Array class: === 1) Basic (100' pts total) === Your Array class must provide the following features: --1.1) (20' pts) Two constructors. One takes the input of the initialized capacity (int) and create the underlying array with that capacity; the other takes...
Imagine you are a physician in Europe during an outbreak of the Black Death. In at...
Imagine you are a physician in Europe during an outbreak of the Black Death. In at least 200 words describe what you think is the cause of the disease you are witnessing and your favorite method(s) of treating this disease.
A program must execute 1012 instructions to solve a problem. A single processor system can solve...
A program must execute 1012 instructions to solve a problem. A single processor system can solve the problem in 106 seconds. Thus on average the single processor system executes 106 or 1-million instructions per second. We have a new program that has been parallelized for execution on a distributed-memory system. This parallel program uses (p) processors. Here each processor will execute 1012/p instructions and each processor must send 109(p-1) messages. We will assume there is not additional overhead for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT