Answer to Question #214851 in C++ for Charan

Question #214851

Create a class called InputData. It has two private data members data_a (int) and data_b (int). Write a function input() to get input for the attributes from the user and a function display() to display the values of the attributes. The values of these two data members can be returned 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 bitwise operations on data_a and data_b.

Write a main() to test functionalities of the Arith_unit and Logic_unit classes.


1
Expert's answer
2021-07-07T18:04:39-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