web viewwrite the equivalent boolean expression for the following logic circuit

67
Y X OR AND Topic: Boolean Algebra QUESTION BANK WITH SOLUTION FOR BRILLIANT LEARNERS Brilliant learners Q1: Prove (x+y)(x+z) = x+yz algebraically. L.H.S. = (x+y).(x+z) =Xx+xz+xy+yz BECAUSE XX = X (FROM IDEMPOTENCE LAW) SO =X+XZ+XY+YZ =X+XY+XZ+YZ =X(1+Y)+Z(X+Y) BECASE 1+Y = 1 (PROPERTY OF 0 AND 1) SO =X.1+Z(X+Y) BECASE 1.X = X (PROPERTY OF 0 AND 1) SO =X+XZ+YZ BECASE 1+X = 1 (PROPERTY OF 0 AND 1) SO =X(1+Z)+YZ =X.1+YZ BECAUSE X.1 = X (PROPERTY OF 0 AND 1) SO =X+YZ Q2: Prove x’.y’+y.z = x’yz+x’yz’+xyz+x’yz algebraically. Ans: L.H.S.= x’y +y.z =x’y.1+1.y.z =x’y(z+z’)+(x+x’)y.z =x’yz+x’yz’+xyz+x’yz =RHS Q3: Write the equivalent Boolean Expression for the following Logic Circuit. Ans: X’+X.Y+(X.Y)’ Q4. Interpret the following logical circuit as Boolean expression

Upload: phamdat

Post on 30-Jan-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Y

X

ORAND

Topic: Boolean Algebra

QUESTION BANK WITH SOLUTION FOR BRILLIANT LEARNERS

Brilliant learnersQ1: Prove (x+y)(x+z) = x+yz algebraically.L.H.S. = (x+y).(x+z)=Xx+xz+xy+yzBECAUSE XX = X (FROM IDEMPOTENCE LAW) SO=X+XZ+XY+YZ=X+XY+XZ+YZ=X(1+Y)+Z(X+Y)BECASE 1+Y = 1 (PROPERTY OF 0 AND 1) SO=X.1+Z(X+Y)BECASE 1.X = X (PROPERTY OF 0 AND 1) SO=X+XZ+YZBECASE 1+X = 1 (PROPERTY OF 0 AND 1) SO=X(1+Z)+YZ=X.1+YZBECAUSE X.1 = X (PROPERTY OF 0 AND 1) SO=X+YZQ2: Prove x’.y’+y.z = x’yz+x’yz’+xyz+x’yz algebraically.Ans: L.H.S.= x’y +y.z=x’y.1+1.y.z =x’y(z+z’)+(x+x’)y.z=x’yz+x’yz’+xyz+x’yz =RHSQ3: Write the equivalent Boolean Expression for the following Logic Circuit.

Ans: X’+X.Y+(X.Y)’Q4. Interpret the following logical circuit as Boolean expression

Ans: ab+b’c+c’e’Q5: Express the F(X,Z)=X+X’Z into canonical SOP form.Ans: F(X,Z)=X+X’Z =X(Y+Y’)+X’(Y+Y’)Z =XY+XY’+X’YZ+X’Y’Z

Page 2: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

=XY(Z+Z’)+XY’(Z+Z’)+X’YZ+X’Y’Z =XYZ+XYZ’+XY’Z+XY’Z’+X’YZ+X’Y’ZQ6: Write the POS and the SOP form of a Boolean function F, which is represented in a truth table as follows:

W X Y Z F0 0 0 0 00 0 0 1 10 0 1 0 00 0 1 1 10 1 0 0 10 1 0 1 00 1 1 0 10 1 1 1 11 0 0 0 01 0 0 1 11 0 1 0 01 0 1 1 11 1 0 0 11 1 0 1 01 1 1 0 01 1 1 1 1

Ans :

W X Y Z F MINTERM MAXTERM0 0 0 0 0 W+X+Y+Z0 0 0 1 1 W’X’Y’Z0 0 1 0 0 W+X+Y+Z’0 0 1 1 1 W’X’YZ0 1 0 0 1 W’XY’Z’0 1 0 1 0 W+X’+Y+Z’0 1 1 0 1 W’XYZ’0 1 1 1 1 W’XYZ1 0 0 0 0 W’+X+Y+Z1 0 0 1 1 WX’Y’Z1 0 1 0 0 W’+X+Y’+Z1 0 1 1 1 WX’YZ1 1 0 0 1 WXY’Z’1 1 0 1 01 1 1 0 0 W’+X’+Y’+Z1 1 1 1 1 WXYZ

SOP :W’X’Y’Z + W’X’YZ+W’XY’Z’+ W’XYZ’+ W’XYZ+ WX’Y’Z+ WX’YZ+ WXY’Z’+ WXYZPOS :(W+X+Y+Z).( W+X+Y+Z’).( W+X’+Y+Z’ ).( W’+X+Y+Z).(W’+X+Y’+Z).(W’+X’+Y’+Z)

Q7: Prove that (a’+b’)(a’+b)(a+b’)=a’b’.Ans: LHS=(a’+b’)(a’+b)(a+b’)=(a’a’+a’b+a’b’+b’b)(a+b’)=(a’+a’b+a’b’+0)(a+b’)=aa’+a’b’+aa’b+a’bb’+a’ab’+a’b’b’=0+a’b’+0+0+0+0+a’b’=a’b’=RHSQ8: Simplify the following Boolean Expression using Boolean postulates and laws of Boolean Algebra.Z=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)Ans: Z=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)RHS=(a’+a).b’.c+a.b’.c’+a.b.(c+c’)=a’bc+ab’c+ab’c’+ab.1=a’bc+ab’c’+ab’c=ab’(c+c’)+ab’c=ab’+ab’c=ab’(1+c)

Page 3: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

=ab’Q9: Reduce the following Boolean Expression using K-MapF(UVWZ) = ∏ (0,1,2,4,5,6,8,10) Ans: =∑(3,7,9,11,12,13,14,15)After that Draw the K map and solve using SOP form

Q10: Reduce the following Boolean expression using K – MapF (A, B, C, D) = (0,2,3,4,6,7,8,10,12)

Ans:

F= C’.D’ + A’.C + B’.D’Q11: If F(a,b,c,d) = ∑ (0,1,3,4,5,7,8,9,11,12,13,15), obtain the simplified form using K-MapAns:

C’D’+CD+BD+AD

Page 4: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Topic : Communication and Technology

HOTS QUESTION BANK(COMM TECHNOLOGY)1.(a) Give two examples of PAN and LAN type of networks.

1(b)Which protocol helps us to browse through web pages using internet browsers? Name any one internet browser.

1(c) Write two advantages of 4G over 3G Mobile Telecommunication Technologies in terms of speed and services.

1(d) Write two characteristics of Web 2.0.

1(e) What is the basic difference between Trojan Horse and Computer Worm ?

1(f) Categorise the following under Client Side and Server Side script category :

1(i) VB Script(ii) ASP(iii) JSP(iv) JavaScript

(g) Uplifting Skills Hub India is a knowledge and skill community which has an aim to uplift the standard of knowledge and skills in the society. It is planning to setup its training centers in multiple towns and villages pan India with its head offices in the nearest cities. They have created a model of their network with a city, a town and 3 villages as follows. As a network consultant, you have to suggest the best network related solutions for their issues/problems raised in (i) to (iv) keeping in mind the distances between various locations and other given parameters.

Answer: 7 (a)

PAN Examples LAN ExamplesConnecting two cell phones to transferdata

Connecting computers in a school

Connecting smartphone to a smart watch Connecting computers in an officeNote: Any one example of eachORAny other one/two correct examples for each of PAN and LAN(b) Protocol: HTTP ORTCP/IP Browser: Chrome OR Internet Explorer OR Firefox OR OPERA OR SAFARI OR any other correct Browser

Page 5: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Name(c)

4G 3G

Speed approximately 100 mbps Speed approximately 2 mbps

LTE True mobile broadband Data services with multimediaORAny other two correct advantages of 4G over 3G in terms of speed and services(d)● Makes web more interactive through online social media● Supports easy online information exchange● Interoperability on the internet● Video sharing possible in the websitesORAny two of the above or any other two correct characteristics of Web 2.0

1

(e)1

Trojan horse: It is a "Malware" computer program presented as useful or harmless in order to induce the user to install and run them.Computer Worm: It is a self-replicating computer program. It uses a network to send copies of itself to other nodes (computers on the network) and it may do so without any user intervention.

ORAny other correct difference between Trojan Horse and Computer Worm

(f)1

Client Side Scripts Server Side ScriptsVB Script ASPJava Script JSP

(g) (i) B_TOWN. Since it has the maximum number of computers and is closest to all other locations.1

(g) (ii) Best Wired Medium : Optical Fibre1

(g) (iii) Switch OR Hub1

Page 6: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

(g) (iv) Videoconferencing OR VoIP OR any other correct service/protocol 1

Q(2)(a) lustrate the layout for connecting 5 computers in a Bus and a Star topology of Networks.(b) What is a spam mail ?(c) Differentiate between ftp and http.(d) Out of the following, which is the fastInfrared, Coaxial Cable, Ethernet Cable, Microwave, Optical Fiber(e) What is Worm ? How is it removed ?(f) Out of the following, which all comes under cyber crime ?

(i) Stealing away a brand new computer from a showroom.(ii) Getting in someone’s social networking account without his consent and posting pictures on his behalf to harass him.

(iii)Secretly copying files from server of a call center and selling it to the o(iv) Viewing sites on an internet browser.(g) Perfect Edu Services Ltd. is an educational organization. It is planning to setup its India campus atChennai with its head office at Delhi. The Chennai campus has 4 main buildings ADMIN,ENGINEERING, BUSINESS and MEDIA.You as a network expert have to suggest the best network related solutions for their problems raised in (i) to (iv), keeping in mind the distances between the buildings and other given parameters.

Shortest distances between various buildings:ADMIN to ENGINEERING 55 MADMIN to BUSINESS 90 MADMIN to MEDIA 50 MENGINEERING to BUSINESS 55 MENGINEERING to MEDIA 50 MBUSINESS to MEDIA 45 MDELHI Head Office to CHENNAI Campus 2175 km

Number of Computers installed at various buildings are as follows :ADMIN 110ENGINEERING 75BUSINESS 40MEDIA 12DELHI Head Office 20i. Suggest the most appropriate location of the server inside the CHENNAI campus (out of the 4 buildings), to get the best connectivity for maximum no. of computers. Justify your answer.

1

Page 7: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

ii. Suggest and draw the cable layout to efficiently connect various buildings within the CHENNAI campus for connecting the computers.

1iii. Which hardware device will you suggest to be procured by the company to be installed to protect and control the internet uses within the campus ?

1iv. Which of the following will you suggest to establish the online face-to-face communication between the people in the Admin Office of CHENNAI campus and DELHI Head Office ?

11. Cable TV2. Email3. Video Conferencing4. Text Chat

Q(3) (a) Write any two differences between twisted pair and coaxial pair cable. 2

(b) Define the following : 2

(i) Firewall(ii) VoIP(c) Write any two examples of Server side Scripts.

1(d) What is cloud computing ?

1(e) Vidya Senior Secondary Public School in Nainital is setting up the network between itsdifferent wings. There are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and HOSTEL(H).

4Distance between various wings are given below :

(i) Suggest a suitable Topology for networking the computers of all wings.(ii) Name the most suitable wing where the Server should be installed. Justify your answer.(iii) Suggest where all should Hub(s)/Switch(es) be placed in the network.

Page 8: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

(iv) Which communication medium would you suggest to connect this school with its main branch in Delhi ?

Page 9: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Topic: Data StructureHOTS QUESTION BANK WITH SOLUTION

UNIT 2 (DATA STRUCTURE) CS CLASS XII

Q1. An array ARR[5][25] is stored in the memory with each element occupying 4 bytes of space. Assuming the base address of ARR to be 1000, compute the address of ARR[5][7], when the array is stored as : (i) Row wise (ii) Column wise.

Ans: (i) Row wise :Given, W = 4, N = 5, M = 25, Base(ARR) = 1000Row Major Formula:Loc(ARR[5][7])= Base(ARR)+W*(M*I+J) = 1000 + 4*( 25*5 + 7) = 1000 + 4 * 132 = 1000 + 528 = 1528

(ii) Column wise :Given, W = 4, N = 5, M = 25, Base(ARR) = 1000Column Major Formula:Loc(ARR[5][7])= Base(ARR)+W*(N*J+I) = 1000 + 4*( 5*7 + 5) = 1000 + 4 * 40 = 1000 + 160 = 1160

Q2. An array S[40][30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the memory location for the element S[20][10], if an element S[15][5] is stored at the memory location 5500.

Ans. Given, W=2, N=40, M=30, Loc(S[15][5])=5500Row Major Formula:

Loc(S[I][J]) =Base(S)+W*(M*I+J)Loc(S[15][5]) =Base(S)+2*(30*15+5)

5500 =Base(S) + 2*(450+5)Base(S) =5500 –910 = 4590

Loc(S[20][10]) =4590+2*(30*20+10)=4590+2*(600+10)=4590+1220 = 5810

Q3. Write a function in C++ to find sum of rows from a two dimensional array.Ans : void MatAdd(int A[ ][ ],int N, int M)

{for (int R=0;R<N;R++){

intSumR=0;for (int C=0;C<M;C++)

SumR+=A[C][R];cout<<SumR<<endl;

}}

Q4. Write a function in C++ to find the sum of both left and right diagonal elements from a two dimensional array (matrix).

Ans : void DiagSum(int A[ ][ ], int N){

int SumD1=0,SumD2=0;for (int I=0;I<N;I++)

Page 10: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

{SumD1+=A[I][I];SumD2+=A[N-I-1][I];

}cout<<”Sum of Diagonal 1:”<<SumD1<<endl;cout<<”Sum of Diagonal 2:”<<SumD2<<endl;}

Q5. Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value. eg:

if the array contains : 3, 4, 5, 16, 9 then the function should be rearranged as 6, 2,10,8, 18

Ans: void calc(int x[ ], int m){

for(int i=0; i<m; ++i){

if(x[i]%2==0)x[i]=x[i]/2;

elsex[i]=x[i]*2;

}}

Q6. Write a user defined function in C++ which intakes one dimensional array and size of array as argument and display the elements which are prime.If 1D array is 10 , 2 , 3 , 4 , 5 , 16 , 17 , 23 Then prime numbers in above array are: 2 , 3 , 5, 17, 23

Ans: void primedisp(int x[ ], int m){

intnf;for(int i=0; i<m; ++i){

nf=0;for(int j=1; j<=x[i]; j++)

if(x[i] % j == 0)nf++;

if(nf == 2)cout<<”\n”<<x[i];

}}

Q7. Write a function in C++ which accepts an integer array and its size as arguments/parameters and exchanges the values at alternate locations. example : if the array is 8,10,1,3,17,90,13,60 then rearrange the array as 10,8,3,1,90,17,60,13

Ans : void exchange(int x[ ], int m){

int y; for(int i=0; i<m; i= i+2){

if(m-i == 1) // if m (no. of element ) is odd last elementi = m; // should not alter its position.

else{

y= x[i];x[i] = x[i+1];x[i+1] = y;

Page 11: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

}}

}

Q8. Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.

Ans: void MERGE(int A[ ], int B[ ], int C[ ], int M, int N, int&K){

int I,J, K;for(I=0, J=N – 1, K=0; I<M && J>=0;) {

if (A[I]<=B[J])C[K++]=A[I++];

elseC[K++]=B[J--];

} for (int T=I;T<M;T++)C[K++]=A[T];for (T=J;T>=0;T--)C[K++]=B[T];

}

Q9. Write function SORTPOINTS() in c++ to sort an array of structure Game in descending order of points using Bubble Sort Note: Assume the following definition of structure Game struct Game { longPNo; // Player Number charPName[20]; long points; };

Ans: void SORTPOINTS(Game gm[ ], int n ) {

Game temp; /*Points to note in bubble sort logic1. Compare with the adjacent elements ie j and j+1 2. Bigger element goes to the top because the elements in the descending order. 3. Each iteration the smaller elements comes in the bottom.*/

for(i=0; i<n; i++) {

for(j=0; j<(n-1)-i; j++) // j< (n-1)-i , subtracting i to avoid the last elements // which are in the correct order after each loop execution. {

if(gm[j].points <gm[j+1].points) {

temp=gm[j]; gm[j]=gm[j+1]; gm[j+1]=temp;

} }

Page 12: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

}Q10. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements

into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 if the array is 1,2,3 The resultant 2D array is The resultant 2D array is 1 2 3 4 5 6 1 2 3 0 1 2 3 4 5 0 1 2 0 0 1 2 3 4 0 0 1 0 0 0 1 2 3 0 0 0 0 1 2 0 0 0 0 0 1

Ans: //Logic : Condition for putting the value is the position (i<=j) of 2D array otherwise put zero void Change2Darray(int x[], int size) {

for(i=0; i<size; i++) {

int k=0; for(int j=0; j< size; j++) { if(i<=j) { y[i][j]=x[k];

k++; }else

y[i][j]=0; }

} for(i=0; i< size; i++) {

cout<<”\n”;for(int j=0; j< size; j++) cout<<y[i][j]<<" ";

} }

Q11. Write a function in C++ which accepts an integer array of double dimensional with its size as arguments and displays the total numbers of odd, even and prime numbers in the array. Example : if the following integer array will be passed to the function, i.e.6 4 13 19 57 3 8 11 519 12 23 4 621 29 18 9 1028 5 12 2 6Then the output should be : The total odd numbers are : 13

The total odd numbers are : 12The total odd numbers are : 10

Ans : void numcheck( intarr[ ][ ], int m, int n){

int i, j, oddt=0, event=0, primet=0, nf, k;for(i=0; i<m; i++){

for(j=0; j<n; j++){

Page 13: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

if(arr[i][j] % 2 = = 0)event++;

elseoddt++;

nf=0;for(k=1; k<=arr[i][j]; k++){

if(arr[i][j] % k = = 0)nf++;

}if(nf = = 2)

primet++;}

}cout<<”\n The total odd numbers are : “<<oddt;cout<<”\n The total even numbers are : “<<event;cout<<”\n The total prime numbers are : “<<primet;

}

Q12. Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in descending order.Example: If an array of nine elements initially contains the elements as4 2 5 1 6 7 8 12 10Then the function should rearrange the array as12 10 8 7 6 5 4 2 1#include<iostream.h>#include<conio.h>voidselect_sort(int a[ ], int n){int i, j, p,large;for(i=0;i<n-1;i++){large=a[i];p=i;for(j=i+1; j<n; j++){if(a[j]>large){large=a[j];p=j;}}a[p]=a[i];a[i]=large;}}

Q13 Write a function in C++ to print the product of each column of a two dimensional array passed as thearguments of the function.Example: If the two dimensional array containsThen the output should appear as:Product of Column 1 = 24

Page 14: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Product of Column 2 = 30Product of Column 3 =240}AnsvoidswapElement(intarr[ ], int no){int temp;for(int i=0;i<no-1;i+=2){temp=arr[i];arr[i]=arr[i+1];arr[i+1]=temp;}cout<<"\nThe elements after completed the alterations";for(i=0;i<no;i++)cout<<arr[i]<<" ";}Q14 Write a function in C++, which accepts an integer array and its size as arguments and swap the elements ofevery even location with its following odd location.Example: If an array of nine elements initially contains the elements as2 4 1 6 5 7 9 23 10then the function should rearrange the array as4 2 6 1 7 5 23 9 10Ans :-void swapElement(intarr[ ], int no){int temp;for(int i=0;i<no-1;i+=2){temp=arr[i];arr[i]=arr[i+1];arr[i+1]=temp;}cout<<"\nThe elements after completed the alterations";for(i=0;i<no;i++)cout<<arr[i]<<" ";}

Q15 Write function in C++ which accepts an integer array and size as arguments and replaces elements havingodd values with thrice its value and elements having even values with twice its value.Example :if an array of five elements initially contains elements as3 4 5 16 9The function should rearrange the content of the array as9 8 75 32 27Ans void manipulate(int a[],int size){for(int i=0;i<size;i++){if (a[i]%2==1)a[i]=a[i]*3;elsea[i]=a[i]*2;cout<<a[i]<<',';}

Page 15: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

}

Q16 Write a function in C++ which accepts a 2D array of integers and its size asarguments and displays the elements of middle row and the elements of middle column.[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3x3, 5x5, 7x7etc…]Example :If the array content is3 5 47 6 92 1 8Output through the function should be :Middle Row : 7 6 9Middle Column : 5 6 1void accept(int a[3][3],int size){cout<<"Middle Row:";for(int i=0;i<size;i++)for(int j=0;j<size;j++)if(i==size/2)cout<<a[i][j]<<'\t';cout<<"\n Middle Column:";for(i=0;i<size;i++)for(j=0;j<size;j++)if(j==size/2)cout<<a[i][j]<<'\t';}

Q17 Write a function in C++ which accepts an integer array and its size as argumentsand exchanges the values of first half side elements with the second half side elementsof the array.Example :If an array of 8 elements initial content as2 4 1 6 7 9 23 10The function should rearrange array a7 9 23 10 2 4 1 6void modify(int a[],int size){Inti,j,temp;for(i=0,j=size/2; j<size; i++,j++){temp=a[i];a[i]=a[j];a[j]=temp;}for(i=0;i<size;i++){cout<<a[i]<<" ";}Q18. Write a function in C++ to print sum of all values which either are divisible by 2 ordivisible by 3 present in a 2D array passed as the argument of the function.

Page 16: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

void Sum(int A[3][3],intR,int C){inti,j,S=0;for(i=0;i<R;i++)for(j=0;j<C;j++)if(A[i][j]%2==0||A[i][j]%3==0)S=S+A[i][j];cout<<"\nThe Sum of all the values which are divisible by 2 or 3 in the array = "<<S;}

Q19. Write a function in C++ to perform a PUSH operation in a dynamically allocated stack considering the following:

struct node { intx,y;

node *Link; };

Ans : struct node { intx,y;

node *Link; }*top, *temp;void PUSH(node *np) {

if(top = = NULL) top = np;

else{

temp = top; top = np; // New node becomes to the first node npLink = temp;

}}

Q20. Write a function in C++ to perform Insert operation in a dynamically allocated Queue containing names of students.struct stud{

char Name[20];stud *Link;

};Ans :struct stud

{char Name[20];stud *Link;

} *front, *rear;void Insert(stud *np){

if (front = = NULL)front = rear = np;

else{

rearLink = np;rear = np;

}

Page 17: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

}Q21. Write a function in C++ to perform Push operation on a dynamically allocated Stack containing real

numbers. struct NODE{

float Data; NODE *Link;};

Ans: class STACK{

NODE *Top;public:

STACK();void Push();void Pop();

};void STACK::Push(){

NODE *Temp;Temp=new NODE;cin>>TempData;TempLink=Top;Top=Temp;

}

Q22. Evaluate the following postfix notation of expression:15 3 2 + / 7 + 2 *

Ans: Step 1: Push

15Step 2: Push Step 3: Push

315

Step 4: + PushPop PopOp2=2 Op1=3

3 Op2=2 515 15

Step 5: / PushPop PopOp2=5 Op1=15

Op2=515 3

Step 6: Push

2

3

Page 18: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

73

Step 7: + PushPop PopOp2=7 Op1=3

7 Op2=73 3 10

Step 8: Push

210

Step 7: * PushPop PopOp2=2 Op1=2

Op2=1010 20

Step 8: Pop

Result20

Q23. Evaluate the following postfix notation of expression:True, False, AND, True, True, NOT, OR, AND

Ans :Step 1: Push

TrueStep 2: Push

FalseTrue

Step 3: AND PushPop PopOp2=True Op1=False

Op2=TrueTrue False

Step 4: Push

TrueFalse

Step 5: Push

TrueTrueFalse

Page 19: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Step 6: NOT PushPopOp2=True False

True TrueFalse False

Step 7: OR PushPop PopOp2=False Op1=True

True Op2=False TrueFalse False False

Step 8: AND PushPop PopOp2=True Op1=False

Op2=TrueFalse False

Step 9: Pop

ResultFalse

Q24. Evaluate the following postfix notation of expression:25 8 3 – / 6 * 10 +

Ans: Operator Scanned Stack Content25 258 25, 83 25, 8, 3- 25, 5/ 56 5, 6* 3010 30, 10+ 40

So, the answer is 40.(Infix to Postfix)

Q25. Convert A + ( B * C – ( D / E )) * F into postfix form showing stack status after every step.Ans :

Step No. Symbol Scanned Stack Expression1 A ( A2 + ( + A3 ( ( + ( A4 B ( + ( A B5 * ( + ( * A B6 C ( + ( * A B C7 – ( + ( - A B C *8 ( ( + ( - ( A B C *9 D ( + ( - ( A B C * D10 / ( + ( - ( / A B C * D

Page 20: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

11 E ( + ( - ( A B C * D E12 ) ( + ( A B C * D E / – 13 ) ( A B C * D E / – +14 * ( * A B C * D E / – +15 F ( * A B C * D E / – + F16 ) A B C * D E / – + F *

So, the postfix form is: A B C * D E / – + F *

Page 21: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Topic: DATA FILE HANDLING

Q. 1: Discuss the two methods of opening a file within a C++ program. When is one method preferred over the other?Ans.: A file can be opened in two ways:-

a) Using the constructor of the stream class — this method is useful when only one file is used in the stream. Constructors of the stream classes ifstream, ofstream and fstream are used to initialize the file stream object with the file name.

For example, ifstream readfile(”Names.dat”,ios::binary);b) Using the function open () - This method is useful when we want to use different files in the stream. If

two or more files are to be processed simultaneously, separate streams must be declared for each. For example

ifstream ifi; I/input stream ifl created ifLopen(”Names.Dat”), i/file Names.Dat linked with iflSecond method is preferred over first method when there is a situation to open more than one file.Q. 2: What role is played by file modes ¡n file operations? Describe the various file mode constants and their meanings.Ans. : A file mode describes how a file is to be used: read it, write to it, append it, and so on. Different file modes constants and their meanings are as following:ConstantMeaningios::in -> Opens file for reading.ios::out -> Opens file for writing.ios::ate -> This seeks to end-of-file upon opening of the file.ios::app -> This causes all output to that file to be appended to the end.ios::trunc -> The contents of a pre-existing file by the same name to be destroyed

and truncates the file to zero length.ios::nocreate -> Causes open() function to fail if the file does not already exist.ios::noreplace -> Causes open() function to fail if the file already exist.ios::binary -> Causes a file to be opened in binary mode.Q. 3 : Write a code snippet that will create an object called filout for writing, associate it with the filename STRS. The code should keep on writing strings to it as long as the user wants.Ans.: void main{ char c,fname[10]; ofstream filout; filout.open(”STRS”); cout«”Enter contents to store in file (Enter * to stop) :\n”; while((c=getcharO) !=‘*‘) filout«c;}Q. 4: Write a code snippet that will create an object called filout for writing, associate it with the filename STRS. The code should keep on writing strings to it as long as the user wants.Ans.: void main{ char c,fname[10]; ofstream filout; filout.open(”STRS”); cout«”Enter contents to store in file (Enter * to stop) :\n”; while((c=getcharO) !=‘*‘) filout«c; filout.closeO;}

Page 22: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Q. 5 : Write a program that counts the number of characters up to the first $ in input and that leaves the $ in the input stream.Ans. : void main{ char s[80],ch; mt count=0; ifstreani file (“abc.txt”); while ( !file.eof) ( file.getline (s, 90); for(int i=0;i<80;i++) ( if(s[i]==’$’) break; count++; cout«count; fi1e.c1ose(); }

Q. 6: Write a program that reads a text file and creates another file that is identical expect that every sequence of consecutive blank space is replaced by a single space.Ans.: void main()

{ char ch; int count=O; ifstream instream; ofstream outstream; instream.open(”A.txt”); outstream.open(”B.txt”); while(!instream.eof()) ch = (char)instream.get( ); if (isspace (ch)) count++; if (count >= 2) ch=’ ‘; Count = O; else outstream«ch;}

Q. 7: Suggest the situation where write() and read() are preferred over get() and put() for file I/O operations. Support your answer with examples.Ans. : The get() and put() functions perform I/O byte by byte. On the other hand, read() and write() functions let you read and write structures and objects in one go without creating need for I/O for individual constituent fields. Example:file .get (ch);file.put (ch);file.read((char *)&obj, sizeof(obj));file.write((char *)&obj sizeof(obj));

Page 23: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Q. 8 : Observe the program segment given below carefully, and answer the question that follows:class Book( int Book_no;char Bookname[20];public://function to nte Book detailsvoid enterdetails ();//function to display Book detailsvoid showdetails();//function to return Book_noint Rbookno() { return book_no; }void Modify(Book NEW)( fstream File;File.open(”BOOK.DAT”,ios: :binary|ios::in|ios::out);Book OB;int Recordsread=0 ,Found=0;while(!Found&&File.read((char*)&OB, sizeof(OB)))( Recordsread++;if (NEW.RBook_no()=OB.RBook_no())( _______________ I/Missing StatementFile. write ( (char*) &NEW, sizeof (NEW));Found=1;)elseFile.write ( (char*) &OB, sizeof (OB));)if ( !Found)cout«”Record for modification does not exist”;File.close();}If the function Modify() is supposed to modify a record in file BOOK. DAT with the values of Book NEW passed to its argument, write the appropriate statement for Missing Statement using seekp() or seekg, whichever needed, in the above code that would write the modified record at its proper place.Ans. : File.seekg (-1*sizeof (NEW) ,ios: :cur);

Q. 9 : void main () ( char ch=’A’; fstream fileout(”data.dat”,ios: :out); fileout«ch; int p=fileour.tellg(); cout«p; }

What is the output if the file content before the execution of the program is the string “ABC”?(Note that” “are not part of the file).

Ans.: 1

Q. 10 : Given a binary file SPORTS.DAT, containing records of the following structure type:struct Sports( char Event[20];

Page 24: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

char Participant[10] [30];}Write a function in C++ that would read contents from the file SPORTS.DAT and creates a file named ATHLETIC.DAT copying only those records from SPORTS.DAT where the event name is “Athletics”.Ans. : void copyfileO{ ifstream fin; ofstream fout; fin.open(”SPORTS.DAT”,ios::inhios::binary); fout. open (“ATHELETIC. DAT”, ios:: out I ios:: binary); Sports si; whiie(!fin.eof O) fin.read((char*)&sl,sizeof(sl)); if (strcnip (si. Event, “Athletics”) ==O) fout.write ( (char*) &si, sizeof (si)); fin.close() ; fout.close();

} 

Page 25: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

HOTS ON POINTERS

Q 1 WHAT WIIL BE OUTPUT OF FOLLOWING PROGRAM? 1#include<iostream.h># include <conio.h>void main(){clrscr();int sum(int(*)(int),int);int square(int);int cube(int);cout<<sum(square,4)<<endl;cout<<sum(cube,4)<<endl;getch();}int sum(int(*ptr)(int k),int n){int s=0;for(int i=1;i<=n;i++)

{s+=(*ptr)(i);}return s;

}int square(int k){ int sq;sq=k*k;return k*k;}int cube(int k){return k*k*k;}

ANS 1> OUTPUT WILL BE 30

100

Q.2 Find the output of the following program?#include<iostream.h>#include<conio.h>#include<string.h>class state{ char *statename; int size; public: state(){size=0;statename=new char[size+1];} state (char *s) { size=strlen(s);statename=new char[size+1]; strcpy(statename,s); }

Page 26: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

void display() { cout<<statename<<endl;} void replace(state&a, state &b) {size=a.size+b.size; delete statename; statename=new char[size+1]; strcpy(statename, a.statename); strcat(statename,b.statename); }};void main(){ clrscr(); char *temp="Delhi"; state state1(temp), state2("Mumbai"), state3("Nagpur"), s1,s2; s1.replace(state1,state2); s2.replace(s1,state3); s1.display(); s2.display(); getch();}

Ans.: DelhiMumbaiDelhiMumbaiNagpur

Question 3 - Give the output of the following program:void main(){char *p = “Difficult”;char c;c = ++ *p ++;printf (“%c”,c);}

Question 4 - Give the output of the following program:void main(){int x [] = { 10, 20, 30, 40, 50}:int *p, **q, *t;p = x;t = x + 1;q = &t;cout << *p << “,” << **q << “,” << *t++;}

Question 5 - void main( ){char * x = “teAmIndia”;char c;c = ++ *x ++;cout<<c;}

Page 27: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Question 6 - void main( ){char *x = “teAmIndia”;char c;c = ( *(x+1) ) ++ ;cout<<c;}

Question 7 - void main(){char * x = “teAmIndia”;char c;c = ++( *(x+1) );cout<<c;}

Question 8 - What will be the output of the program( Assume all necessary header files are included) :#include<iostream.h>void print (char * p ){p = "pass";cout<<"value is "<<p<<endl;}void main( ){char * x = "Best of luck";print(x);cout<<"new value is "<<x<<endl;}

Page 28: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

HOTS IN C++

CONCEPTS OF OOP’SQ1. Explain Operators?Ans: 1. Arithmetic operators :-Those operators are operates only on numeric data types operands are known as arithmetic operators.

2. Unary - Result is the negation of operand’s value (Reverse the sign of operand’s value) If a=5 then – a means -5. If a = - 4 then – a means 4.

3. Unary + The result is the value of its operand If a=5 then +a means 5. If a = - 4 then +a means -4.

4. + (Addition Operator) : Addition ( it adds two numbers) 4+20 results is 24. If a = 5 then a + 5 results 10.

5. - ( Subtraction Operator) :Subtraction ( Subtract the second operand from first) 14 – 3 evaluates to 12. If a = 2 , b = 3 then b – a evaluates 1.

6.*(Multiplication Operator) :Multiplies the values of its operands 3*4 evaluates to 12. If a=2, b=3 then a*b evaluates to 6.

7. / (Division Operator) :Divides its first operand by the second 100/5 evaluates 20. If a =10 , b = 5 then a/b evaluates 2

8. % (Modulus Operator) :It produce the remainder of dividing the first operand by second 19%6 evaluates to 1.

If a = 14 , b = 3 then a%b evaluates to 2. Modulus operator requires that both operands be integer and second operand be non-zero.

9. Increment and Decrement Operators (++ , - -) : The increment operator (++) adds 1 to its operand and decrement operator (--) subtract one from its operand. In other word a = a + 1; is same as ++a; or a++; & a = a – 1 ; is same as --a; or a--; Both the increment & decrement operators comes in two version :

(i)Prefix increment/decrement :- When an increment or decrement operator precedes its operand, it is called prefix increment or decrement(or pre-increment / decrement). In prefix increment/decrement , C++ perform the increment or decrement operation before using the value of the operand. e.g.,

If sum = 10 and count =10 then Sum = sum +(++count); First count incremented and then evaluate sum = 21.

(ii)Postfix increment/decrement :- When an increment or decrement operator follows its operand, it is called postfix increment or decrement (or post-increment / decrement).

Page 29: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

In postfix increment/decrement , C++ first uses the value of the operand in evaluating the expression before incrementing or decrementing the operand’s value. e.g., If sum = 10 and count =10 then Sum = sum +(count++); First evaluate sum = 20 , and then increment count to 11.

Q2. Explain Relational Operator?Ans: These operators are used to compare two values. If comparison is true, the relational expression results into the value 1 and if the comparison is false its result will be 0. The six relational operators are:

(a) Operator Meaning (b) = = Equal to

(c ) != Not equal to (d) < Less than (e) <= Less than or equal to (f) > Greater than (g) >= Greater than or equal to

Q3. Explain Logical Operators : In addition to the relational operator, C++ contains three logical operators. Relational operators often are used with logical operators to construct more complex decision making expressions.

Q4. Explain Assignment Operator: Ans: C++ offers an assignment operator (=) to assign a value to an identifier. The assignment statement that make use of this operator are written in the form : var = expression ; where var generally represents a variable and expression may be a constant or a variable or an expression.

Q5. Explain Shorthand operators.Ans: C++ offers special shorthand operators that simplify the coding of a certain type of assignment statement . e.g., a = a + 10 ; can be written as a+=10 ; This shorthand works for all binary arithmetic operators. The general form of this shorthand is Var = var operator expression ; is same as var operator = expression ;

Following are some examples of C++ shorthands: x -=10 ; equivalent to x = x -10 ; x*=3 ; equivalent to x = x * 3 ; x/=2 ; equivalent to x = x/2 ; x%=z equivalent to x = x % z ;

Q6. Explain Conditional operator ( ? : )

Ans: The conditional operator (? :) is a ternary operator i.e., it require three operands. The general form of conditional operator is:

expression1? expression2: expression3 ;

Page 30: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Where expression1 is a logical expression , which is either true or false. If expression1 evaluates to true i.e., 1, then the value of whole expression is the value of expression2, otherwise, the value of the whole expression is the value of expression3.

For example 14 min = a<b? a : b ;

Here if expression (a<b ) is true then the value of a will be assigned to min otherwise value of b will be assigned to min.

Q7. Explain Comma operator ( , ) Ans: The comma operator (,) is used to separate two or more expressions that are included where only one expression is expected. When the set of express ions has to be evaluated for a value, only the rightmost expression is considered.

For example, the following code:

a = (b =3 , b +2 ); Would first assign the value 3 to b, and then assign b+2 to variable a. So, at the end, variable a would contain the value 5 while variable b would contain value 3.

Q8. Explain sizeof() operator?Ans: This operator returns the size of its operand in bytes. The operand may be an expression or identifier or it may be a data type. a= sizeof (char);

This will assign the value 1 to a because char is a one-byte long type.

Q9. Explain Expressions?

Ans: An expression in C++ is any valid combination of operators, constants, and variables.Pure Expressions:-

If an expression have all operand of same data types then it is called a pure expression.

Mixed Expressions :-If an expression have operands of two or more different data types then it is called a mixed expression.

Arithmetic Expressions:-Arithmetic expression can either be integer expressions or real expressions. Sometimes a mixed expression can also be formed which is a mixture of real and integer expressions.

Integer Expressions:- Integer expressions are formed by connecting all integer operands using integer arithmetic operators.

Real Expressions:-Real expressions are formed by connecting real operands by using real arithmetic operators.

Logical Expressions:-

Page 31: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

The expressions which results evaluates either 0 (false) or 1 (true) are called logical expressions. The logical expressions use relational or Logical operators.

Q10. Explain Type Conversion:-Ans: The process of converting one predefined data type into another is called type conversion. C++ facilitates the type conversion in two forms: (i)Implicit type conversion:- An implicit type conversion is a conversion performed by the compiler without programmer’s intervention. An implicit conversion is applied generally whenever different data types are intermixed in an expression. The C++ compiler converts all operands upto the data type of the largest data type’s operand, which is called type promotion.

(ii)Explicit type conversion:- An explicit type conversion is user-defined that forces an expression to be of specific data type.

Q11. Explain Type Casting?Ans: The explicit conversion of an operand to a specific type is called type casting.

Type Casting Operator - (type) :-Type casting operators allow you to convert a data item of a given type to another data type. To do so , the expression or identifier must be preceded by the name of the desired data type , enclosed in parentheses . i. e., (data type) expression Where data type is a valid C++ data type to which the conversion is to be done.

For example , to make sure that the expression (x+y/2) evaluates to type float , write it as:

(float) (x+y/2)

Q12. Explain Precedence of OperatorsAns:- Operator precedence determines which operator will be performed first in a group of operators with different precedence. For instance 5 + 3 * 2 is calculated as 5 + (3 * 2), giving 11

Q13. Explain Statements?Ans: Statements are the instructions given to the Computer to perform any kind of action.

Q14. Explain Null Statement? Ans: A null statement is useful in those case where syntax of the language requires the presence of a statement but logic of program does not give permission to do anything then we can use null statement. A null statement is nothing only a ;. A null (or empty statement have the following form:

; // only a semicolon (;) Q15. Explain Compound Statement ? Ans: A compound statement is a group of statements enclosed in

Q16. Explain Objects?Ans: Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class.

Page 32: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

An Object is a collection of data members and associated member functions also known as methods.

Q17. Explain Classes?Ans: Classes are data types based on which objects are created.

Thus a Class represents a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects become functions of the class and are referred to as Methods.

Classes are the blueprints upon which objects are created. E.g when we design a map of the house, the architect first designs it. Once it is designed, the raw material is used to build the house. In this example, Design of the house is CLASS (blueprint) and the house built on the basis of design is an object.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.

Q18. Explain Inheritance?

Ans: Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class. The new class that is formed is called derived class.

Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming. It is the process by which one class inherits the properties of another Class.

Q19. Explain Data Abstraction?Ans:

Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.

The concept of abstraction relates to the idea of hiding data that are not needed for presentation. The main idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details.

An Abstract Data Type is defined as a data type that is defined in terms of the operations that it supports and not in terms of its structure or implementation.

Q20. Explain the features of Object oriented Programming?

Ans: FEATURES OF OBJECT ORIENTED PROGRAMMING:

Inheritance:Inheritance is the process of forming a new class from an existing class or base class. Thebase class is also known as parent class or super class.

Derived class is also known as a child class or sub class. Inheritance helps inreusability of code , thus reducing the overall size of the program

Data AbstractionIt refers to the act of representing essential features without including the backgrounddetails .Example : For driving , only accelerator, clutch and brake controls need to be

Page 33: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

learnt rather than working of engine and other details.Data Encapsulation:It means wrapping up data and associated functions into one single unit called class..A class groups its members into three sections :public, private and protected, whereprivate and protected members remain hidden from outside world and thereby helps inimplementing data hiding.

Modularity :The act of partitioning a complex program into simpler fragments called modules iscalled as modularity.It reduces the complexity to some degree and It creates a number of well defined boundaries within the program .Polymorphismmeans many and morphs mean form, so polymorphism means one name multipleforms.It is the ability for a message or data to be processed in more than one form.C++ implements Polymorhism through Function Overloading .

Q21. Explain Access Specifiees in Class.

Ans: Access specifiers in Classes:

Access specifiers are used to identify access rights for the data and member functions of the class.There are three main types of access specifiers in C++ programming language:privatepublicprotectedMember-Access ControlType of AccessMeaning

PrivateClass members declared as privatecan be used only by memberfunctions and friends (classes or functions) of the class.

ProtectedClass members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class.PublicClass members declared as public can be used by any function

Importance of Access Specifiers :Access control helps prevent you from using objects in ways they were not intended to beused. Thus it helps in implementing data hiding and data abstraction.

Page 34: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

CONSTRUCTOR & DESTRUCTOR

Q1. What is constructor?

Ans. A member function with the same name as its class is called constructor and it is used to initialize the objects of that class type with a legal initial value.

Q2. What is destructor?

Ans. A destructor is a member function having same name as its class but preceded by ~ sign and it de-initializes an object before it goes out of scope.

Q3. What are different types of constructors?

Ans. The different types of constructors are Default constructor, Parameterized constructor and Copy constructor.

Q4. What is default constructor?

Ans. A constructor that accepts no parameter is called the default constructor.

Q5. What is parameterized constructor?

Ans. A constructor that accepts parameters for its invocation is known as parameterized

Constructor.

Q6. Can constructor or destructor have return type?

Ans. constructor or destructors have no return type not even void.

Q7:- How many types of method to call constructors in OOP?

Ans:- There are two types of methods to call constructor-

(i) By calling constructor Implicitly (ii) By calling constructor Explicitly

Q8:- What do you understand by Default constructor? What is its role?

Ans:- A default constructor one that takes no arguments. It is automatically invoked when an object is created without providing any initial values.Q9:- Is the default constructor for class Test always Test::Test () ?Ans:- No, A “default constructor” is a constructor that can be called with no arguments. Example- class Test { int a,b; public: Test();

----- };

Q10:- What do you mean by a temporary instance of a class?Ans:- A temporary instance of a class means an anonymous object (no name ) of the same class and which is shortlived.Its benefit is when an object is required only for very short time ( an expression or a statement ) .We need not reserved memory for it for long. A temporary object for the same purpose can be created which remains in the memory as long as the statement defining it is getting executed after the statement this object is automatically destroyed and memory is released. Therefore memory remains occupied only for the time when it is needed.

Page 35: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Q11:-What is significance of constructors in OOP?

Ans:- One major characteristic of OOP is its close correspondence with the real world entities.OOP objects also are created and scrapped. When an object is created, it must be constructed with some legal initial value automatically without being specified by programmer. Therefore, the constructor takes over this very important duty to initialization of an object being created and relieves us from this task.

Q12:- What do you understand by Default constructor? What is its role?

Ans:- A default constructor one that takes no arguments. It is automatically invoked when an object is created without providing any initial values.

Q13:- Write the special three characteristics of constructer?

Ans: - 1.Constructor functions are invoked automatically when the object are created.

2. No return type (not even Void) can be specified for a constructor.

3. A constructor may not be static.

Q14:-write a short note on the significant of the destructor? Ans- OOP object are also created and scrapped off. An object that is existing must be scrapped off when it is no more needed. The task of scrapping off an object is carried out by a destructor’s destructor de -initializes an object and de allocated all allocated resources.Q15:- What do you understand by Destructor? What is its role?Ans:-Destructor is also a member function of a class which name is same as class name followed by ~(tild) symbol. Its role to deallocate the memory used by the object after destroys the scope of object.Q16:- What is parameterized constructor? Explain with example?Ans:- A constructor that accepts parameters for its invocation is known as parameterized constructor. Example- class Test { int a,b; public: Test( int i,int j) { a=i; b=j; } };

Q17:-Answer the questions (i) and (ii) after going through the following class- Class Race { int CarNo,Track; Public: Race(); //function 1 Race(int CN); //function 2

Race(Race &R) //function 3 Void Register(); //function 4

void Drive(); //function 5 }; void main() { Race R; }

(i) Out of the following,which of the options is correct for calling function 2?Option 1-Race T(30); option 2-Race U(R);,

(ii) Name the feature of object oriented programming,which is illustrated by function1, function2 and function 3 combined together.

Ans:- (i) option 1 is correct (ii) Constructor Overloading.Q 18:- Rewrite the following program after removing the synthetical errors

(if any). Underline each correction. #include<iostream.h>#include<stdio.h>Class Mystudent

Page 36: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

{ int StudentId=1001; Char Name[20]; Public MyStudent() { } void Register() { cin>>StudentId; gets(Name); } void Display() { cout<<StudentId<<”;”<<Name<<endl; } }; void Main() { Mystudent MS; Register.MS(); MS.Display(); }

Ans:- #include<iostream.h>#include<stdio.h>Class Mystudent { int StudentId; Char Name[20]; public: MyStudent() { StudentId=1001; } void Register() { cin>>StudentId; gets(Name); } void Display() { cout<<StudentId<<”;”<<Name<<endl; } }; void main() { MyStudent MS; MS.Register(); MS.Display(); }

Q.19Answer the questions (i) and (ii) after going through the following class:

class Patient{char Disease[20]; int Age; public: Patient() //Constructor 1 {strcpy(Disease, “Swine Flu”); Age = 20; }Patient(char *d, int a) //Constructor 2 { strcpy(Disease, d); Age = a; } Patient(Patient & P); // Constructor 3 ~Patient() //Destructor { cout<<” Patient Cured” ; }};void main(){ Patient P1(“Cold”,25); //Statement 1 Patient P2 = P1; //Statement 2

Page 37: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

}

(i) When object P2 is created, which constructor will be called and why?(ii) Write complete definition for Constructor 3.

Ans -(i) Constructor 3 which is a copy constructor will be called to initialize object P2 with object P1. (ii) Patient(Patient & P) { Disease=P.Disease; Age = P.Age; } Q20 :-Discuss the various situations when a copy constructor is automatically invoked.Ans:- 1. When an object is defined and initialized with another object of the same class type,then the copy constructor is invoked to copy the data values of one object to the other. 2. When an object is passed by the value to a function,then the copy of the passed object is created for the function by invoking the copy constructor. 3. When a function returns an object,the copy constructor creates a temporary object to hold the return values of the function returning an object.

Concept of Inheritance (Extending Class) in C++

1. What is difference between protected access specifier and private access specifier?2. What is difference between Public Viability mode and Private Visibility mode?3. What is Hybrid Inheritance?4. What is Containership?5. Consider the following code and answer the questions below:

class Book {

char title[20];char author[20];int no_of_pages;public:

void read( );void show( );

};class TextBook : private Book{

int no_of_chapters, no_of_assignments;protected:

int standard;public:

void readtextbook( );void showtextbook( );

};class PhysicsBook : public TextBook{

char topic[20];public:

void readphysicsbook( );void showphysicsbook( );

Page 38: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

};i. Name the members, which can be accessed from the member functions of class PhysicsBook.ii. Name the members, which can be accessed by an object of class TextBook.

iii. Name the members which can be accessed by an object of class Physicsbook.iv. What will be the size of an object (in bytes) of class Physicsbook?

Answer: (i) no_of_chapters, no_of_assignments, standard, topic, readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook()(ii) read(), show(), readtextbook(), showtextbook()(iii) readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook()(iv)20 + 20 + 2 + 2 + 2 + 2 + 20 = 68 bytes.

6. Consider the following code and answer the questions below:class Peronal {

int class, rno;char section;protected:

char name[20];public:

Personal();void pEntry();void pDisplay();

};class Marks : private Personal{

float m[5]; protected:

char grade[5]; public:

Marks(); void mEntry();

void mDisplay();};class Result : public Marks{

float total, agg;public:

char finalGrade, comments[20];Result();void rCalculate();void rDisplay();

};i. Which type of inheritance is shown in the above code?ii. Write the name of those data members which can be directly accessed from the objects of class

Result.iii. Write the names of those member functions, which can be directly accessed from the objects of

class Result.iv. Write the names of those data members, which can be directly accessed from mEntry( ) function

of class Marks.

Page 39: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Answer: (i) Multilevel Inheritance(ii) finalGrade, comments(iii) rCalculate(), rDisplay(), mentry(), mDisplay()(iv) m, grade, name

7. Consider the following code and answer the questions below:class Magazine{

char MCode[10];protected:

char MName[20];public:

Book();void MEnter();void MDisplay();

};class Member{

char MCode[10];protected:

char MName[25];public:

Member();void MEnter();void MDisplay();

};class Library : private Magazine, public Member{

char LName[15];float Charge;public:

Library();void LEnter();void LDisplay();

};i. Which type of inheritance is shown in the above code?ii. Write the names of all the members, which are accessible from LEnter( ) functions of class

Library?iii. Write name of all the members accessible through an object of class Libraryiv. What shall be the order of execution for the constructors Magazine(), Members() and Library(),

when object of class Library is declared?Answer:(i) Multiple Inheritance(ii) LDisplay(), Member::MEnter(), Member::MDisplay(), Magazine::MEnter(), Magazine::MDisplay(), LName, Charge, Member::MName, Magazine::MName(iii)No Data member, Functions: LEnter(), LDisplay, Member::MEnter() and Member::MDisplay()(iv) Order of constructors execution is: Magazine(), Mameber(), Library()

Page 40: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

8. Consider the following code and answer the questions below:class Drug{

char category[10];char date_of_manufacture[10];char company[20];public:

Drug();void enterdrugdetails();void showdrugdetails();

};class Tablet : public Drug{

protected:char tablet_name[30];char volume_label[20];

public:float price;Tablet();void entertabletdetails();void showtabletdetails ();

};class PainReliever : public Tablet{

int dosage_units;char side_effects[20];int use_within_days;public:

PainReliever();void enterdetails();void showdetails();

};i. How many bytes will be required by an object of class Drug and an object of class PainReliever

respectively ?ii. Write names of all the data members which are accessible from the object of class PainReliever.

iii. Write names of all the members accessible from member functions of class Tablet.iv. Write names of all the member functions which are accessible from objects of class

PainReliever.

Answers:i.Size of Drug's object - 40 bytesSize of PainReliever's object - 118

Page 41: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

ii. price

iii.Data Members :tablet_name, volume_label, priceMember Functions :enterdrugdetails(), showdrugdetails(), entertabletdetails(), showtabletdetails()

iv.enterdrugdetails(),showdrugdetails(), entertabletdetails(),showtabletdetails (), enterdetails(), showdetails()

9. Consider the following code and answer the questions below:class Publisher{

char pub[12];double turnover;protected:

void register();public:

Publisher();void enter();void display();

};

class Branch{

char city[20];protected:float employees;public:

Branch();void haveit();void giveit();

};class Author : private Branch, public Publisher{

int acode;char aname[20];float amount;public:

Author();void start();void show();

};i. Write the names of data members, which are accessible from objects belonging to class Author.ii. Write the names of all the member functions which are accessible from objects belonging to

class Branch.iii. Write the names of all the members which are accessible from member functions of class

Author.

Page 42: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

iv. How many bytes will be required by an object belonging to class Author?Answers:i. None

ii. haveit() giveit()

iii.member functions :register(), enter(), display(), haveit(), giveit(), start(), show()data members : employees, acode, aname, amountiv. 70

10. Consider the following code and answer the questions below:class Vehicle{

private:int wheels;

protected :int passenger:

public :void inputdata(int, int);void outputdata();

};class Heavyvehicle : protected Vehicle{

int diesel_petrol;protected :

int load;public:

void readdata(int, int);void writedata();

};

class Bus : private Heavyvehicle{

char make[20];public :

void fetchdata(char);void displaydata();

};(i) Name the base class and derived class of the class Heavyvehicle.(ii) Name the data member(s) that can be accessed from function displaydata().(iii) Name the data member's that can be accessed by an object of Bus class.(iv) Is the member function outputdata() accessible to the objects of Heavyvehicle class.Answers:i. base class – Vehicle

derived class - Bus

ii. passenger, load, make

Page 43: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

iii. None

iv. No

Page 44: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

HOTS C++ REVISION CLASS XI

1. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.# include <iostream.h>

void main()

{

struct STUDENT

{

char stu_name [20];

char stu_sex;

int stu_age=17;

} student;

gets(stu_name);

gets(stu_sex);

}

Ans : # include <iostream.h>

#include <stdio.h> // header file missing

void main()

{

struct STUDENT

{

char stu_name [20];

char stu_sex;

int stu_age; //Can not be initialized here

} student;

gets(student.stu_name); //Can not be directly accessible, so accessing through object

gets(student.stu_sex); //Can not be directly accessible, so accessing through object

}

2. Find the output of the following program:

# include<iostream.h>

#include<string.h>

class state

Page 45: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

{

char * state_name;

int size;

public;

state( )

{

size = 0;

state_name = new char[size+1];

}

state(char *s)

{

size = strlen(s) ;

state_name = new char[size+1];

strcpy(state_name,s);

}

void display()

{

cout<<state_name<<endl;

}

void Replace (state &a, state &b)

{

size = a.size + b.size;

delete state_name;

state_name = new char[size+1] ;

strcpy(state_name, a.state_name);

strcat(state_name, b.state_name);

}

};

void main( )

{

char *temp = “Delhi”;

Page 46: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

state state1(temp), state2(”Mumbai”), state3(”Nagpur”), S1, S2;

S1 .Replace(state1, state2);

S2.Replace(S1, state3);

S1.display( );

S2.display( );

}

State 1

Delhi

State 2

Mumbai

State 3

Nagpur

S1 - strcat(state1, state 2)

DelhiMumbai

11

S2 - strcat(S1, state3)

DelhiMumbaiNagpur

17

Output : DelhiMumbai

DelhiMumbaiNagpur

3. Find the output of the following program :

#inc1ude <iostream.h>

struct POINT

{

int X, Y, Z;

};

void StepIn (POINT &P, int Step=1)

{

Page 47: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

P.X+=Step;

P.Y -=Step;

P.Z+=Step;

}

void StepOut (POINT &P, int Step=1)

{

P.X-=Step;

P.Y+=Step;

P.Z–=Step;

}

void main ( )

{

POINT P1={15, 25, 5}, P2={10, 30, 20};

StepIn(P1);

StepOut(P2,4);

cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl;

cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;

StepIn(P2,12);

cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;

}

Output is :

16, 24, 6

6, 34, 16

18, 22, 28

4. Go through the C++ code shown below, and find out the possible output or outputs from the suggested output Options (i) to (iv). Also, write the least value and highest value, which can be assigned to the variable Guess.

#include <iostream.h>

#include <stdlib.h>

void main ( )

Page 48: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

{

randomize ( ) ;

int Guess, High=4;

Guess=random{High)+ 50 ;

for{int C=Guess ; C<=55 ; C++)

cout<<C<<"#" ;

}

(i) 50 # 51 # 52 # 53 # 54 # 55 #

(ii) 52 # 53 # 54 # 55

(iii) 53 # 54 #

(iv) 51 # 52 # 53 # 54 # 55

Ans : (i) 50 # 51 # 52 # 53 # 54 # 55 #

Least value 50

Highest value 53

5. Find the output of the following program:

#include<iostream.h>

void main ( )

{

int Track [ ] = {10, 20, 30, 40}, *Striker ;

Stxiker=Track :

Track [1] += 30 ;

cout<<"Striker>"<<*Striker<<end1 ;

Striker – =10 ;

Striker++ ;

cout<<"Next@"<<*Striker<<end1 ;

Striker+=2 ;

cout<<"Last@"<<*Striker<<end1 ;

cout<< "Reset To" <<Track[0] <<end1 ;

}

Ans: Striker>10

Next@50

Page 49: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Last@40

Reset to 0

6. Find the output of the following program:

#inc1ude<iostream.h>

void ChangeArray(int Number, int ARR[ ], int Size)

{

for (int L =0; L<Size; L++)

if (L<Number)

ARR [L] +=L;

e1se

ARR [L] *=L;

}

void Show (int ARR [ ], int Size)

{

for (int L=0; L<Size; L++)

(L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ;

}

void main ( )

{

int Array [ ] = {30, 20, 40, 10, 60, 50};

ChangeArray (3, Array, 6) ;

Show (Array, 6) ;

}

Ans: 30

21#42

30#240

250#

7. What is the difference between Type Casting and Automatic Type conversion? Also, give a suitable C++ code to illustrate both.

Automatic Type Conversion: It is an implicit process of conversion of a data from one type to another.

Page 50: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

For example :

1int N = 65;

char C = N; // Automatic type conversion ; conversion

cout<<C;

Type Casting: It is an explicit process of conversion of a data from one type to another. For example

int A=1, B=2;

float C = (float) A/B; //Type Casting

cout<<C;

8.Find the output of the following program:

#include<iostream.h>

void main ( )

{

int *Queen, Moves [ ] = {11, 22, 33, 44};

Queen = Moves;

Moves [2] + = 22;

Cout<< "Queen @"<<*Queen<<end1;

*Queen - = 11;

Queen + = 2;

cout<< "Now @"<<*Queen<<end1;

Queen++;

cout<< "Finally@"<<*Queen«end1;

cout<< "New Origin @"<<Moves[0]<<end1;

}

Ans: Queen @11

Now @55

Finally @44

New origin @0

9. Find the output of the following program :

#include <iostream.h>

Page 51: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

#include <ctype.h>

void ChangeIt(char Text[ ], char C)

{

for (int K=0;Text[K]!='\0';K++)

{

if (Text[K]>=’F’ && Text[K]<=’L’)

Text[K]=tolower (Text[K]);

else

if (Text[K]=’E’ || Text[K]==’e’)

Text[K]==C;

else

if (K%2==O)

Text[K]=toupper(Text[K]);

else

Text[K]=Text[K-l];

}}

void main ( )

{

char OldText[ ]=”pOwERALone”;

ChangeIt(OldText,’%’);

cout<<“New TEXT:”<<OldText<<endl;

}

Ans. New TEXT : PPW % RRllN%

10. Find the output of the following program:

#include <iostream.h>

struct THREE_D

{int X,Y,Z;};

void MoveIn(THREE_D &T, int Step=l)

}

T.X+=Step;

Page 52: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

T.Y-=Step;

3T.Z+=Step;

}

void MoveOut(THREE_D &T, int Step=l)

{

T.X-=Step;

T.Y+=Step;

T.Z-=Step;

}

void main ()

{

THREE_D Tl={lO,20,5},T2={30,lO,40};

MoveIn(T1);

MoveOut(T2,5) ;

cout<<Tl.X<<“,”<<Tl.Y<<“,”<<T1.Z<<endl;

cout<<T2.X<<“,”<<T2.Y<<“,”<<T2.Z<<endl;

MoveIn(T2,l0);

cout<<T2.X<<“,”<<T2.y<<“,”<<T2.Z<<endl;

}

Ans. 11, 19, 6

25, 15, 35

35, 5, 45

11. Find. the output of the following program:

#include <iostream.h>

#include <ctype.h>

void MyCode (char Msg [], char CH)

{

for (int (Cnt=O;Msg[Cnt]!=’\0';Cnt++)

{

if (Msg[Cnt]>=’B’ && Msg[Cnt]<=’G’)

Page 53: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Msg[Cnt]=tolower(Msg[Cnt]);

else

if (Msg[Cnt]==’A’|| Msg[Cnt]==’a’)

Msg[Cnt]=CH;

else

if (Cnt%2==0)

Msg[Cnt]=toupper(Msg[Cnt]);

else

Msg[Cnt]=Msg[Cnt-l];

}

}

void main ()

{

char MyText [] =” ApEACeDriVE”;

MyCode(MyText,’@’);

cout<<“NEW TEXT:”<<MyText<<endl;

}

Ans. NEW TEXT :@@e@ccddIIe

12. Find the output of the following program:

#include <iostream.h>

void Changethecontent(int Arr[ ], int Count)

{

for (int C=1;C<Count;C++)

{

Arr[C-1]+=Arr[C];

}

void main()

{

int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};

Changethecontent(A,3);

Page 54: Web viewWrite the equivalent Boolean Expression for the following Logic Circuit

Changethecontent(B,4);

Changethecontent(C,2);

for (int L=0;L<3;L++) cout<<A[L]<<'#';

cout<<endl;

for (L=0;L<4;L++) cout<<B[L] <<'#';

cout<<endl;

for (L=0;L<2;L++) cout<<C[L] <<'#';

}

7#9#5#

30#50#70#40#

2100#1200#