English, asked by kp383674, 1 month ago

Define class Currencyhaving two integer data members rupee and paisa. A class has member functions enter() to get the data and show() to print the amount in 22.50 format. Define one member function sum() that adds two objects of the class and stores answer in the third objecti.e. c3=c1.sum (c2). The second member functionshould add two objects of type currency passed as arguments such that it supports c3.add(c1,c2); where c1, c2 and c3 are objects of class Currency. Also Validate your answer if paisa >100. Write a main( )program to test all the functions. Use concepts of Object as Function Arguments, function returning object and function overloading.

Answers

Answered by keyapatel1203
1

Answer:

#include<iostream>

using namespace std;

class Currency

{

   int rupee,paisa;

   public:

   Currency sum(Currency);

   Currency add(Currency, Currency);

   Currency op(Currency);

   void enter()

   {

       cout<<"Enter Rupee : ";

       cin>>rupee;

       cout<<"Enter Paisa : ";

       cin>>paisa;

   }

   void show()

   {

       if(paisa>100)

       {

           rupee=rupee+paisa/100;

             paisa=paisa%100;

       }

       cout<<"Currency is : "<< rupee<<"."<<paisa<<endl;

   }

};

Currency Currency :: sum(Currency o2)

{

   Currency temp;

   temp.rupee = rupee + o2.rupee;

   temp.paisa = paisa + o2.paisa;

   return temp;

}

Currency Currency :: add(Currency o1,Currency o2)

{

   Currency temp;

   temp.rupee = o1.rupee + o2.rupee;

   temp.paisa = o1.paisa + o2.paisa;

   return temp;

}

Currency Currency :: op(Currency o2)

{

   Currency temp;

   temp.rupee = rupee + o2.rupee;

   temp.paisa = paisa + o2.paisa;

   return temp;

}

int main()

{

   Currency c1,c2,c3;

   c1.enter();

   c2.enter();

    c3=c1.sum(c2);

    cout<<"Addition using with c3=c1.sum(c2)"<<endl;

    c3.show();

    c3.add(c1,c2);

    cout<<"Addition using with  c3.add(c1,c2)"<<endl;

    c3.show();

    c1.op(c2);

    cout<<"Addition using with c1.sum(c2)"<<endl;

    c3.show();

}

Explanation:

Similar questions