Answer to Question #213014 in C++ for Hemambar

Question #213014

 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 performarithmetic 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 performarithmetic and logical operations according to the given codes. Choose code 0 to code 6 to performthe said seven operations. Write sample program to test the ALU class.

1
Expert's answer
2021-07-07T06:15:20-0400
#include<iostream>
using namespace std;
class  InputData{
	private:
		int	data_a, data_b;
		
	public:
		InputData(int a, int b){
			data_a = a;
			data_b = b;
		}
		int get_a(){
			return data_a;
		} 
		int get_b(){
			return data_b;
		}
};
class Arith_Unit: public InputData{
	public:
	double add(){
	return	get_a() + get_b();
	}
	double sub(){
		return	get_a() - get_b();
	}
	double mul(){
	return	get_a() * get_b();	
	} 
	double div(){
		return	get_a() / get_b();	
	}
};
class Logic_Unit: public InputData{
	public:
	int n = get_a();
	int bin[100], number=n;
   int i = 0;
   while (n > 0) {
      bin[i] = n % 2;
      n = n / 2;
      i++;
   }
   int arr_a[i];
   for (int j = i - 1; j >= 0; j--){
   arr_a[j] =  bin[j];
   }
   for (int j=0; j<i; j++){
   cout << arr_a[j];
   
   }
   int m = get_b();
   int bina[100], number1=m;
   int x = 0;
   while (m > 0) {
      bina[x] = m % 2;
      m = m / 2;
      i++;
   }
   int arr_b[x];
   for (int j = x - 1; j >= 0; j--){
   arr_b[j] =  bina[j];
   }
	
	
	
	
	
	
	void and1(){
	for(int y= 0; y<=i; y++){
		cout<<arr_b[y]<<endl;
	}
   


   
   
	}
	void or1(){
		
	} 
	void xor1(){
		
	}
	
};
int main(){
	


}

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