Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Sheet 2

A) In the following exercises, you will finish the uncompleted code in Gates project, without change to
the original code.
1. Complete the Gate class which represents a gate in a Logic circuit. This class stores the input
values in an array pointed to by input pointer. The number of inputs in variable n.
All variables are defined as private. Your job is to complete:
a) A constructor that creates the input array and initializes all its inputs to false.
b) A setInput function that sets the value of an input.
c) A getInput function that returns the value of an input.
d) A GetNumberOfInputs function that returns the number of inputs.

2. Complete the OR class which represents an OR gate in logic circuit. This class publically inherits
the Gate class. It stores no more data. Your job is to complete:
a) A constructor that constructs a gate with a given number of inputs.
b) An output function that returns the output of the OR gate.
3. Complete the AND class which represents an AND gate in logic circuit. This class publically
inherits the Gate class. It stores no more data. Your job is to complete:
a) A constructor that constructs a gate with a given number of inputs.
b) An output function that returns the output of the AND gate.
4. Complete the NOT class which represents an inverter gate in logic circuit. This class privately
inherits the Gate class. It stores no more data. Your job is to complete:
a) A constructor that constructs a gate with one input.
b) An output function that returns the output of the NOT gate.
5. A) Can we write?
NOT n;
cout << n. GetNumberOfInputs()<<endl;
B) Can we Write?
AND a(3);
cout << a. GetNumberOfInputs()<<endl;
6. Write a main function that prints the truth table of the following logic circuit using the above
classes.
B) In the following exercise, you will finish the uncompleted code in Series project, without change to
the original code.

1- Inherit Series to make an expSeries class that can calculate e x= 1+x/1! +x2/2! +x3/3! +x4/4!+…
2- Inherit Series to make a cosSeries class that can calculate cos(x)= 1- x 2/2! +x4/4!+…
3- Inherit Series to make a sinSeries class that can calculate cos(x)= x/1!- x 3/3! +x5/5!+…
4- Inherit Series to make a logSeries class that can calculate
ln(x)= 1+(x-1)/1+(x-1)2/2+(x-1)3/3+(x-1)4/4+…

You might also like