Answer to Question #213770 in C++ for Hemambar

Question #213770

Create a class called InputData. It has two private data members data_a and data_b. Set the

values of these two data members by using two public functions get_a() and get_b(). Derive a class

called Arith_Unit from InputData. It contains the functions add(),sub(), mul(),div() to perform

arithmetic operations on data_a and data_b. Derive a class Logic_Unit from InputData. It

contains the functions and(), or() and xor() to perform logical operations on data_a and data_b.

Finally derive a class called ALUnit from Arith_Unit and Logic_Unit classes. It has to perform

arithmetic and logical operations according to the given codes. Choose code 0 to code 6 to perform

the said seven operations. Write sample program to test the ALU class.


1
Expert's answer
2021-07-05T13:28:43-0400
#include <iostream>




using namespace std;




class InputData{
    private:
        int data_a;
        int data_b;
    public:
        int get_a(){
            data_a=45;
            return data_a;
        }
        int get_b(){
            data_b=45;
            return data_b;
        }
};




class Arith_Unit: public InputData{
    public:
        int add(){
            return (get_a()+get_b());
        }
        int sub(){
            return (get_a()-get_b());
        }
        int mul(){
            return (get_a()*get_b());
        }
        int div(){
            return (get_a()/get_b());
        }
};




class  Logic_Unit: public InputData{
    public:
        int and_(){
            return (get_a()&&get_b());
        }
        int or_(){
            return (get_a()||get_b());
        }
        int xor_(){
            return (!get_a()||get_b());
        }
};




class  ALUnit: public Arith_Unit, public Logic_Unit{


};
int main()
{
    InputData e;
    e.get_a();
    e.get_b();




    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