Q:

a. Using truth table prove that A+A’.B = A+B.[2]

- Draw AND gate and OR gate using only NAND gate. [2]
- See the following code:

int getHCF(int a, int b)

{

//assumming b >= a > 0

if(b%a == 0)

{

return a;

}

return getHCF(b%a, a);

}

What value will return by following function call?

i) getHCF(45, 100) [1]

ii) getHCF(40, 72) [1] - Differentiate between compile time and run time errors. [2]
- Explain the prefix and postfix increment operators. [2]

A:

(a) Truth table for the given Boolean statement:

A+A’B = A+B

A | B | A’ | A’.B | A+A’B | A+B |

0 | 0 | 1 | 0 | 0 | 0 |

1 | 0 | 0 | 0 | 1 | 1 |

0 | 1 | 1 | 1 | 1 | 1 |

1 | 1 | 0 | 0 | 1 | 1 |

Hence A+A’B = A+B

(b) AND Gate using NAND Gate:

OR Gate using NAND Gate:

(c) For the given code return value of the statements:

i) getHCF(45, 100) : 5

ii) getHCF(40, 72) : 8

(d) Compile time errors vs. Run time errors:

Compile time errors are the errors that can be found out at compile time like wrong syntax. Such errors do not let the program run at all.

However, the run time errors are those errors which may occur at run time and stops further execution of the program because of any unexpected condition arising at run time like division by zero, array out of bound etc.

(e) Increment operator is a unary operator applied in integers that increments the value of its operand by 1.

(i) Prefix increment operator (++i): It first increments the value of operand then uses its value in the expression or statement.

(ii) Postfix increment operator (i++): It first uses the value of operand in the expression and then increments it.

Q:

A:

(a) Indempotence Law:

It states that

X.X = X and X+X=X

i.e., ORing and ANDing of a boolean expression with itself results into the same boolean.

(b) Complementarity Law:

It states that

X+X’ = 1 and X.X’ = 0

i.e., ORing of a boolean with its complement is always 1 and ANDing of a boolean with its complement is always 0.

(c) Commutative Law:

It states that

X+Y = Y+X and X.Y = Y.X

i.e., the inputs of OR Gate and AND Gate can be interchanged.

(d) Distributive Law:

It states

X.(Y+Z) = X.Y +X.Z

and X + Y.Z = (X+Y).(X+Z)

(e) Associative Law:

It states

X+(Y+Z) = (X+Y)+Z

and X.(Y.Z) = (X.Y).Z

It states that

X.X = X and X+X=X

i.e., ORing and ANDing of a boolean expression with itself results into the same boolean.

(b) Complementarity Law:

It states that

X+X’ = 1 and X.X’ = 0

i.e., ORing of a boolean with its complement is always 1 and ANDing of a boolean with its complement is always 0.

(c) Commutative Law:

It states that

X+Y = Y+X and X.Y = Y.X

i.e., the inputs of OR Gate and AND Gate can be interchanged.

(d) Distributive Law:

It states

X.(Y+Z) = X.Y +X.Z

and X + Y.Z = (X+Y).(X+Z)

(e) Associative Law:

It states

X+(Y+Z) = (X+Y)+Z

and X.(Y.Z) = (X.Y).Z

Q:

(b)

A:

boolean isPrime(int n)

{ if(n == 1 || n == 2)

return true;

if( n == 0)

return false;

}

(b)

Q:

A:

(b)

(c)

Q:

(b)

A:

Q:

(b)

A:

(a) SOP expressions for sum and carry for full adder are:

sum = X’Y’Z+X’YZ’+XY’Z’+XYZ

carry = XZ+YZ+XY

truth table for full adder is:

sum = X’Y’Z+X’YZ’+XY’Z’+XYZ

carry = XZ+YZ+XY

truth table for full adder is:

A | B | C | Carry | Sum |

0 | 0 | 0 | 0 | 0 |

0 | 0 | 1 | 0 | 1 |

0 | 1 | 0 | 0 | 1 |

0 | 1 | 1 | 1 | 0 |

1 | 0 | 0 | 0 | 1 |

1 | 0 | 1 | 1 | 0 |

1 | 1 | 0 | 1 | 0 |

1 | 1 | 1 | 1 | 1 |

Circuit diagram for sum:

Q:

(b)

(c)

A:

Dual form of the expression:

A’+B+(A+B).B.(C+B’)

(b)

| | |

| | |

| | |

| | |

| | |

Q:

(b)

A:

(a) Half Adder: It is a logic circuit that adds two bits at a time and produces output as sum and carry.

The output of half adder, sum and carry are the functions of its input. They are:

Sum = A B

Carry = A.B

The output of half adder, sum and carry are the functions of its input. They are:

Sum = A B

Carry = A.B

Circuit diagram of the half adder:

Full adder is a logic circuit that adds three bits at a time. It can be derived from half adder by adding two bits using half adder and adding the third bit with the sum of first two bits using another half adder. Also by ORing carry of both these half adders we can derive the final carry.

Sum = (A B) C

Carry = AB + (AB)C

Circuit Diagram:

Q:

A:

Q:

A:

Class rectangle:

public class rectangle

public class rectangle

{

int length;

int height;

rectangle(int l, int h)

{

length = l;

height = h;

}

int surfaceArea()

{

return (length* height);

}

}

Class cube:

public class Cube extends rectangle

{

int width;

Cube(int l, int h, int w)

{

super(l, h);

width = w;

}

int surfaceArea()

{

return (super.surfaceArea() * width);

}

}

Q:

*Salary *with the following details.

A:

Class salary:

import java.io.*;

import java.io.*;

public class Salary

{

int basic;

Salary() throws IOException

{

InputStreamReader read = new InputStreamReader(System.in);

BufferedReader in = new BufferedReader(read);

System.out.print("Enter the basic salary: ");

basic = Integer.parseInt(in.readLine());

}

int cal()

{

int DA = 10*basic/100;

int HRA = 15*basic/100;

int totalSalary = DA + HRA + basic;

int PF = 8%totalSalary/100;

int CTC = PF + totalSalary;

return CTC;

}

}

Class Employee that inherits salary and implements main method:

public class Employee extends Salary

{

String empName;

int empId;

String empDg;

Employee(String n, int i, String d)throws Exception

{

super();

empName = n;

empId = i;

empDg = d;

}

public static void main()throws Exception

{

Employee obj = new Employee("Akshya", 48, "Developer");

System.out.println("Total salary of "+obj.empName+" is :

"+obj.cal());

}

}

Output:

Q:

A:

Q:

A:

Take your CBSE board preparation to another level with AI based and rich media animation on Extramarks - The Learning App.

Features of Learning App

- Learn with studybot “Alex”
- Personalized Learning journey
- Unlimited doubt Solving
- Quiz, challenge friends
- Leaderboard Ranking
- Academic Guru