Create two classes MD and MR which store the value of currency. MD stores currency in Rupee and paise and MR in dollars and cents. Write a C++ Program that can read values for the class objects and perform the following operations using appropriate functions or conversions.
Answers
Program is given below.
Explanation:
#include<iostream>
using namespace std;
class MD{
private:
int rupee;
float paisa;
float total_inr;
public:
void getdata(){
cout<<"Enter the number of rupee: ";
cin>>rupee;
cout<<"Enter the number of paisa: ";
cin>>paisa;
total_inr=(float)rupee+paisa;
cout<<"Total amount = "<<total_inr<<endl;
}
};
class MR{
private:
int dollar;
float cents;
float total_usd;
public:
void getdata(){
cout<<"\nEnter the number of dollar: ";
cin>>dollar;
cout<<"Enter the number of cents: ";
cin>>cents;
total_usd=(float)dollar+cents;
cout<<"Total amount = "<<total_usd<<endl;
}
};
int main()
{
MD MD_class;
MR MR_class;
MD_class.getdata();
MR_class.getdata();
}
Refer the attached image for the output.
