Вы находитесь на странице: 1из 58

2015 QUESTION PAPER

(a) Write the definition of a function Change(int P[], int N) in C++, which should
change all the multiples of 10 in the array to 10 and rest of the elements as 1. For
example, if an array of 10 integers is as follows:

After executing the function, the array content should be changed as follows:

(b) A two dimensional array ARR[50][20] is stored inthe memory along the two
with each of its elements occupying 4 bytes. Find the address of the element
ARR[30][10], if the element ARR[10][5] is stored at the memory location 15000.
(c) Write the definition of a member function Push() in C++, to add a new book in
a dynamic stack of BOOKS considering the following code is already included
in the program:
struct BOOKS
{
char ISBN[20], TITLE[80];
BOOKS*Link;
};
class STACK
{
BOOKS *Top;
public:
STACK() { Top=NULL; }
void PUSH();
void POP();
~STACK();
};
(d) Write a function REVROW(int P[][5], int N, int M) in C++ to display the content
of a two dimensional array, with each row content in reverse order.
For example, if the content of array is as follow:
The function should display output as:
(e) Convert the following Infix expression to its equivalent Postfix expression,
showing the stack content for each step of conversion:
U+V+R/(S–T)
[2+3+4+3+2=14]
AnswerS
(a)

Output-
(b)
Element size =4 bytes
Lr=Lc=0;
B=?
ARR[10][5]=15000
ARR[30][10]=?
ARR[I][J]= B + W[n(I-Lr) + (J-Lc)]
15000 = B + 4[20(10-0)+(5-0)]
15000 = B + 4[ 200+5]
15000 = B + 4[205]
B = 15000 – 820
B= 14180
Now, put the value of base address to evaluate the address of cell ARR[30][10]
ARR[30][10]= 14180 + 4[20(30-0) + (10-0)]
= 14180 + 4[600+10]
= 14180 + 2440
ARR[30][10]= 16620 Ans.
(c)
void STACK::PUSH()
{
BOOKS *temp;
temp=new BOOKS;
if(temp==NULL)
cout<<"Stack is Full";
else
{
cout<<"Enter ISBN:";
cin>>temp->ISBN;
cout<<”Enter TITLE: ”:
cin>>temp->TITLE;
temp->Link=top;
top=temp;
}
}
(d)

(e)
U * V + R / (S – T)
Stack status for infix to postfix conversion is shown below-
(U * V) + (R / (S – T))
2014
(a) Write code for a function offEven(int s[], int N) in C++, to add 5 in all the odd values
and 10 in all the even values of the array S.

Example: If the original content of the array S is

The modified content will be:

(b) An array T[25][20] is stored along the row in the memory with each element requiring
2 bytes of storage. If the base address of array T is 42000, find out the location of
T[10][15]. Also, find the total number of elements present in this array.
(c) Write a user-defined function SumLast3(int A[][4], int N, int M) in C++ to find and
display the sum of all the values, which are ending with 3 (i.e., units place is 3). For
example if the content of array is:

33 13 92

99 3 12

The output should be 49.


(d) Evaluate the following postfix expression. Show the status of stack after execution of
each operation separately:
F, T, NOT, AND, F, OR, T, AND

(e) Write a function POPBOOK() in C++ to perform delete operation from a Dynamic
Stack, which contains Bno and Title. Consider the following definition of NODE, while
writing your C++ code.
struct NODE
{
int Bno;
char Title[20];
NODE *Link;
};
[3+3+2+2+4=14]

ANSWERS
#include< iostream.h>
#include< conio.h>
void oddEven(int s[], int N)
{
for(int i=0;i
{
if(s[i]%2==0)
s[i]=s[i]+10;
else
s[i]=s[i]+5;
}
}

void main()
{
clrscr();
int i, arr[5];
cout<< "Enter five elements in the array";
for(i=0;i<5;i++)
cin >> arr[i];

cout << "The array is: ";


for(i=0;i<5;i++)
cout << arr[i]<< " , ";

// calling function for adding values


oddEven(arr,5);

cout<< "The updated array is: ";


for(i=0;i<5;i++)
cout<< arr[i]<< " , ";

getch();
}

(b)
Base Address = 42000
Element size W = 2 bytes

Rows in Array = 25

Columns in Array = 20

Lr, Lc=0,0

Location of array I, J = 10, 15

Row Major:
T[I][J]=B+W[C(I-Lr)+ (J-Lc)]

T[10][15 ] = 42000 + 2 * [(20(10-0 ) + (15-0))]


=42000+ 2*(200+15)
=42000+430
=42430

Total Number of elements present in array T is R * C i.e., 25 * 20 = 500

(c)
#include < conio.h>
#include < iostream.h>
void SumLast3(int A[][3], int N, int M)
{ int num,last,sum=0;
for(int i=0; i
{
for(int j=0; j
{
num=A[i][j];
last=num%10;
if(last==3)
sum=sum+num;
}
}
cout<< "Sum of the digits ending with 3 is: "<< sum;
}
void main()
{
clrscr();
int arr[2][3] ={{33, 13, 92}, {99, 3, 12}};

SumLast3(arr,2,3);
getch();
}

(d)
The Given postfix notation:
F, T, NOT, AND, F, OR, T, AND
Push each element in the stack bucket one by one.

(e)
struct NODE
{
int BNo;
char Title[20];
NODE *link;
};

void STACK::POPBOOK()
{
NODE *temp;
//structure pointer top is holding the address of the top node
if(top==NULL) // Value NULL is initially assigned to top
cout<< "Stack is Empty";
else
{
temp=top;
temp=temp->link;
top=temp;
cout<< "The element is popped out.";
}
}

2013
(a) Write a code for a function void ChangeOver(int P[ ], int N) in C++, which re-
positions all the elements of the array by shifting each of them to the next
position and by shifting the last element to the first position.
For example: If the content of the array is:

0 1 2 3 4
12 15 17 13 21
The changed content will be:

0 1 2 3 4
21 12 15 17 13
(b) An array T[15][10] is stored along with the row in the memory with each
element requiring 8 bytes of storage. If the base address of the array T is 14,000,
then find out the location of T[10][7].

(c) Write a user-defined function

DispTen(int A[ ][4], int N, int M)


in C++ to find and display all the numbers, which are divisible by 10. For example,
if the content of the array is:

12 20 13

2 10 30

The output should be:

20 10 30

(d) Evaluate the following postfix expression. Show the


status of the stack after the execution of each operation:
5, 2, *, 50, 5, /, 5, -, +

(e) Write a function QDELETE() in C++ to perform the delete operation on a Linked
Queue, which contains the Passenger no. and Passenger name. Consider the
following definition of node in the code:

struct node
{

long int Pno;

char Pname[20];

node *Link;

};
[3+3+2+2+4 = 14]
ANSWERS
Answer:

(a).
#include< iostream.h >
#include< conio.h >
void ChangeOver(int P[], int N)
{
int temp;

temp=P[N-1];

for(int i=N-1;i>0;i--)
{
P[i]=P[i-1];

}
P[0]=temp;
}

void main()
{
clrscr();
int arr[20],range,i;

cout << "nEnter Range: ";


cin >> range;

cout << "nEnter "<< range<< " elements:";


for(i=0;i
cin >> arr[i];

cout << "nThe array before conversion is: ";


for(i=0;i
cout << arr[i]<< " ,t";

ChangeOver(arr,range);

cout << "nThe array before conversion is: ";


for(i=0;i
cout << arr[i]<<" ,t";

getch();
}

(b)

B= 14000
E= 8 Bytes
Lr=Lc=0
T[10][7]=?
Row Major:
P[10][7] =B+E[C(I-Lr)+(J-Lc)]
= 14000 + 8[10(10-0) + (7-0)]
= 14000 + 7(107)
= 14000 + 749
= 14749 Ans
(c) #include< iostream.h >
#include< conio.h >

void DispNTen(int L[][4], int R, int C)

cout << "nThe Divisible elements are: ";

for(int i=0; i < R ; i++)

for(int j = 0; j < C; j++)


{

if(L[i][j]%10==0)

cout << L[i][j]<< "t";

void main()

clrscr();

int M[4][4],r,c,i,j;

cout << "nEnter Rows: ";

cin >> r;

cout << "nEnter Cols: ";

cin >> c;

cout << "nEnter elements:";


for(i = 0 ; i < r ; i++)

for(j = 0 ; j < c ; j++)

cin >> M[i][j];

cout << "nThe Martrix is: ";

for(i = 0 ; i < r ; i++)

cout <<"nn";

for(j= 0 ; j < c ; j++ )

cout << M[i][j] << "t";

DispNTen(M,r,c);

getch();

(d) 5, 2, *, 50, 5, /, 5, -, +
(e)

void Queue::QDELETE()
{
node *temp;

if(startPtr==NULL)
cout<<”Queue is Empty (underflow…)”;

else
{
temp= startPtr;
startPtr=startPtr->link;
cout << ”nThe record deleted is: ”;
cout << ”n PNo: ”<< temp->Pno;
cout << ”n Name : ”<< temp->Pname;

delete temp;

}
______________________________________________________________________
__________2012
a) Write a function SWAP2BEST (int ARR[ ],int Size) in C++ to modify the content
of the array in such a way that the elements, which are multiples of 10 swap with
the values present in the very next position in the array.

For example:
If the content of Array ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54

b) An array T[20][10] is stored in the memory along the


column with each of the elements occupying 2 bytes. Find
out the memory location of T[10][5], if the element[2][9] is
stored at the location 7600.
c) Write a function in C++ to perform Insert operation in a static circular Queue
containing Book’s information (represented with the help of an array of structure
BOOK).
struct BOOK
{
long Accno; //Book Accession Number
char Title[20]; //Book Title
};
d) Write a function ALTERNATE (int A[ ][3], int N, int M) in C++ to display all
alternate elements from two-dimensional array A (starting from A[0][0]).
For example:
If the array is containing:
23 54 76
37 19 28
62 13 19
The output will be:
23 76 19 62 19
e) Evaluate the following POSTFIX notation. Show the status of stack after every
step of evaluation (i.e. after each operator):True, False, NOT, AND, False, True,
OR, AND
[3+3+4+2+2 = 14]
ANSWERS
(a). A C++ function SWAP2BEST(int ARR[], int Size) that
swaps the elements which are multiple of 10, with their very
next positioned element.
void SWAP2BEST (int ARR[], int Size)
{
int temp;
for(int i = 0; i < SIZE; i++)
{
if(ARR[i]%10 == 0)
{ //swap with the next element
temp = ARR[i];
ARR[i] = ARR[i+1];
ARR[i+1] = temp;
i++; //reach next to the number that has been
swapped
}
}
}

(b). B= ?
E=2 Bytes
Lr=Lc=0
S[2][9]=7600
Column Major:
S[I][J]=B+E[(I-Lr)+R(J-Lc)]
S[2][9] = B + 2[(2-0)+20(9-0)]
7600 = B + 2(182)
B = 7600-364
B = 7236
Now Address of S[5][10] is:
S[10][5] = B+ E[(I-Lr)+R(J-Lc)]
= 7236 + 2[(10-0] + 20(5-0)]
= 7236 + 2(110)
= 7236 + 220
= 7456 Ans
(c). // declare a global variables

Const int size=10;


int front,rear;
front=rear=-1;
Book B[size];

void insert_in_CQ( )
{
if(front==0 && rear==size-1)||(front==rear+1))
cout<< ”Underflow”;
else if(rear==-1)
front=rear=0;
else
{
rear++;
cout<< ”Enter Accession No:”;
cin>>B[rear].acc;
cout<< ”Enter Title: ”;
cin>>B[rear].Title;
}
}

(d). Function ALTERNATE(int A[][3], int N, int M) that displays all


alternate elements from 2Dimensional array A.

void ALTERNATE(int A[ ][3 ], int N, int M)


{

for(int i = 0; i < N*M; i = i+2)


{
cout<< A[i/M][i%M]<< "n";
}

(e). The Given postfix notation:


True, False, NOT, AND, False, True, OR, AND

Push each element in the stack bucket one by one.

Therefore the Answer is True.

2011
a)Write a Get2From1() function in C++ to transfer the content from one array ALL[
] to two different arrays Odd[ ] and Even[ ]. The Odd[ ] array should contain the
values from odd positions(1,3,5…) of ALL[ ] and Even[ ] array should contain the
values from even positions (0,2,4,…) of ALL[].
Example :
If the ALL[ ] array contains
12,34,56,67,89,90
The Odd[ ] array should contain
34,67,90
And the Even[ ] array should contain
12,56,89
b) An array G[50][20] is stored in the memory along the row with each of its
elements occupying 8 bytes. Find out the location of G[10][15], if G[0][0] is stored
at 4200.
c) Write a function in C++ to perform Delete operation on a dynamically allocated
Queue containing Members details as given in the following definition of
NODE:
struct NODE
{
long Mno; //Member Number
char Mname[20]; //Member Name
NODE *Link;
};
d)Write a DSUM() function in C++ to find sum of Diagonal Elements from a NxN
Matrix.
(Assuming that the N is a odd number)
e)Evaluate the following postfix notation of expression: True
,False,NOT,AND,True,True,AND,OR

[ 3+3+4+2+2 =14 ]
ANSWERS
Answer:

(a)

void Get2From1()
{
int All[]={12,34,56,67,89,90};
int Odd[3];
int Even[3];
int i,j,k;
j=k=0;
for(i=0;i<6;i++)
{
if(i%2==0)
{
Even[j++]=All[i];
}
else
Odd[k++]=All[i];
}
cout << "All Array :n";
for(j=0;j<6;j++)
cout<
cout << "Even Index Array :n";
for(j=0;j<3;j++)
cout<
cout << "Odd Index Array :n";
for(j=0;j<3;j++)
cout<
}

(b) Given:
W=8,N=20,B=4200
G[10][15]=4200+8(20(10-0)+(15-0))
=4200+8(200 + 15)
=4200+8(215)
=4200+1720
=5920

(c) void queue :: quedel()


{
node *temp;
int val;
if(front ==NULL)
{
cout << "Queue Empty";
}
else
{
temp = front;
front = front -> Link
val = temp -> Mno;
cout << "Deleted value is" << val;
Delete temp;
}
if(front == NULL)
Rear=front;
}

(d)

void DSUM()
{
int a[n][n], sum=0;
for ( int i = 0 ; i < n ; i ++)
{
for( int j = 0 ; j < n ; j ++)
{
cin >> a[i][j];
}
}
for ( int i = 0 ; i < n ; i + +)
{
for( int j = 0 ; j < n; j + +)
{
if( i==j )
{
sum = sum +a[i][j];
}
}
}
cout << " Sum of dialgonal elements is: " << sum;
}
(e)

Scanned Elements Operation Stack


True PUSH True True
False PUSH False True, False
NOT NOT(False) True, True
AND AND(True, True) True
True PUSH True True, True
True PUSH True True, True, True
AND AND(True, True) True, True
OR OR(True, True) True

______________________________________________________________________
_________
2010
a) Write a function REASSING() in C++ which accepts an array of integers and its
size as parameters and divide all those array elements by 5 which are divisible by
5 and multiply other array elements by 2. (3)
Sample Input Data of the array

A[0] A[1] A[2] A[3] A[4]

20 12 15 60 32
Content of the array after calling REASSIGN() function

A[0] A[1] A[2] A[3] A[4]

4 24 3 12 64
b) An array T [ 90 ] [ 100 ] is stored in the memory along the column with each of
the elements occupying 4 bytes. Find out the memory location for the element T [
10 ] [40 ] , if the Base Address of the array is 7200. (3)
c) Write a complete program in C++ to implement dynamically allocated Queue
containing names of cities. (4)
d) Write a function int ALTERSUM (int B [ ] [ 5 ] ,int N, int M) in C++ to find and
return the sum of elements from all alternate elements of a two- dimensional
array starting from B [ 0 ] [ 0 ] . (2)
Hint:
If the following is the content of the array.

B[0][0] B[0][1] B[0][2]


4 5 1
B[1][0] B[1][1] B[1] [2]
2 8 7
B[2][0] B[2][1] B[2][2]
9 6 3
The function should add elements B [ 0] [0 ] ,B [ 0 ] [ 2 ] ,B [ 1 ] [ 1 ],B [ 2 ] [ 0 ]
and B [ 2 ] [ 2 ].
e) Evaluate the following postfix notation of expression: (2)
(Show status of Stack after each operation)
True, False, NOT, OR, False, True, OR, AND
ANSWERS
Answer:

a) The function is as follows :


void REASSIGN (int A [ ], intN)
{
for (int i=0;i< n;i++)
{
if(A [ i ] %5 == 0)
A [ i ] =A [ i ] /5;
else
A [ i ] =A [ i ] *2;
}
}
b) Loc(P [ i ] [ j ] ) =Base(P) + W(i+j*m)
Loc(P [ i ] [ j ] ) =Base(P) +4(10+40*90)
Loc(P [ 10 ] [ 20 ] ) =7200+4(10+40*90)
=7200+4(10+3600)
=7200+4(3610)
=7200+14440
=21640

c) Program:
# include < iostream.h >
# include < stdio.h >
# include < conio.h >
# include < stdlib.h >
# include < ctype.h >
# include < string.h >
Struct node
{
char City [ 20 ] ;
node * link;
};
class queue
{
node * front, *rear;
public:
queue () { front = rear = NULL; }
void add_Q; //Add queue
void del_Q; //Delete queue
void show_Q; //Show queue
};
void queue::add_Q()
{
node*temp;
char ct [ 20 ] ;
temp = new node;
cout << “Enter City”;
gets(ct);
strcpy(temp -> City, ct);
temp -> link=NULL;
rear-> link=temp;
rear=temp;
if(front == NULL)
front = rear;
}
// Function for deletion
void queue::del_Q()
{
node *temp;
char ct [ 20 ];
if (front == NULL)
{
cout << ”Queue Empty”;
}
else
{
temp = front;
front = front -> link;
strcpy(ct,temp -> City);
temp -> link=NULL;
cout << ”Delete value is ” << ct;
delete temp;
}
if (front == NULL)
rear = front;
}
//Function for show elements
void queue :: show_Q()
{
Node * temp;
temp = front;
clrscr();
cout << ”The Queue value are”;
while (temp! = NULL)
{
cout << ”n” << temp -> city;
temp= temp -> link;
}
}
void main()
{
node *front,*rear;
int choice;
queue QUEUE;
char opt = ‘Y’;
front = rear = NULL;
clrsrc();
do
{
cout << ”ntt Main Menu”;
cout << ”nt1. Addition of Queue”;
cout << ”nt2. Deletion from Queue”;
cout << ”nt3. Traverse of Queue”;
cout << ”nt4. Exit from Menu”;
cout << ”nn Enter your choice from above”;
cin >> choice;
switch (choice)
{
case 1:
do
{
QUEUE.add_Q();
cout << ”nDo you want to add more element < Y/N > ?”;
cin >> opt;
}
while(toupper(opt)==’Y’);
break;
case2:
opt =’Y’;
do
{
QUEUE.del_Q();
cout << ”/n Do you want to add more elements < Y/N > ?” ;
cin >> opt;
}
while(toupper(opt)==’Y’);
break;
case3:
QUEUE.show_Q();
break;
case 4:
exit(0);
}
}
while (choice ! =4);
}

d)The function is as follows :


int ALTERSUM(int B [ ] [ 5 ] ,int n, int m)
{
int sum=0,q=1;
for(int i=0,i < n; i++)
for(int j=0;j < m; j++)
{
if(q % 2 != 0)
sum = sum+ B [ i ] [ j ] ;
q++;
}
return sum;
}
e)

Element Scanned Stack


True True
False True, False
NOT True, True
OR True
False True ,False
True True, False,
True
OR True, True
AND True
So the result is true.
2009
a) Write a function SORTSCORE() in C++ to sort an array of structure Examinee in
descending order of Score using Bubble Sort. [3]
Note: Assume the following definition of structure Examinee
struct Examinee
{
long RollNo;
char Name[20];
float Score;
};
Sample Content of the array (before sorting)
Roll No Name Score

1001 300
Ravyank Kapur
1005 Farida Khan 289

1002 Anika Jain 345

1003 George Peter 297

Sample Content of the array (after sorting)


Roll No Name Score

1002 Anika Jain 345

1001 Ravyank Kapur 300

1003 George Peter 297

1005 Farida Khan 289

(b) An array T [50][20] is stored in the memory along the column with each of the
elements occupying 4 bytes. Find out the base address and address of element T
[30][15], if an element T[25][10] is stored at the memory location
9800. [4]

(c) Write a function QUEDEL() in C++ to display and delete element from a
dynamically allocated Queue containing nodes the following given structure:
[4 ]
struct NODE
{
int Itemno;
char Itemname[20];
NODE *Link;
};
d) Define a function SWAPARR() in C++ to swap (interchange) the first row
elements with the last row elements, for a dimensional integer array passed as
the argument of function. [3]
Example: If the two dimensional array contains
5 6 3 2

1 2 4 9

2 5 8 1

9 7 5 8

After swapping of the content of first row and last row, it should be as follows:
9 7 5 8

1 2 4 9

2 5 8 1

5 6 3 2

e) Convert the following infix expression to its equivalent postfix expression


showing stack contents for the conversion:
[2]
A + B * (C – D) / E

ANSWERS
(a) void SORTSCORE (Examinee E[], int N)
{
Examinee temp;
for ( int i=0; i < N; i++)
for (j=0; j < N-i-1; j++)
if ( E[j]. Score < E[j+1]. Score)
{
temp= E[j];
E[j] = E[j+1];
E[j+1] = temp;
}
}
(b ) Given,
W=4
N=50
M=20
Loc(T [25][10])=9800
Column Major Formula:
Loc(T [I][J]) =Base(T)+W*(N*J+I)
Loc(T[25][10]) =Base(T)+4*(50*10+25)
9800 =Base(T)+4*(500+25)
Base(T) =9800- 2100
Base(T) = 7700
Loc(T[30][15]) =7700 +4*(50*15 + 30)
=7700 +4*(750 +30)
=7700 +3120
=10820
(c) #include < iostream.h >
class linkedQueue
{
private :
struct NODE
{
int Itemno;
char Itemname [20];
NODE *Link;
};
NODE *front, *rear;
public :
int remove (void);
}
int linkedQueue:: remove (void)
{
int num;
NODE * temp;
if (front==NULL)
{
cout<<” QUEUE EMPTY!! “ ;
return (-1);
}
else
{
temp= front;
front= front ->Link;
num=temp -> Itemno;
delete temp;
if (front==NULL) && (rear=NULL))
return num;
}
}
(d) void SWAPARR ( int X[100] [ ],int M, int N )
{
int temp, i;
for (i=0;i
temp= X [0][i];
X[0][i] = X[N-1][i];
X[N-1][i]= temp;
}
}
(e) A + B * (C – D) / E
symbol scanned stack expressiony
A ( A
+ (+ A
B (+ AB
* (+ * AB
( (+ * ( AB
C (+*( ABC
- (+*( - ABC
D +*( - ABCD
) (+* ABCD–
/ (+/ ABCD-*
E (+/ ABCD-*E
) A B C D-* E / +
The equivalent postfix expression is
ABCD-*E/+

2008
a) Write a function in C++, which accepts an integer array and its size as
parameters and rearranges the array in reverse. Example: if an array of nine
elements initially contains the elements as

4,2,5,6,7,8,12,10
then the function should rearrange the array as
10,12,8,7,6,5,2, [4]

(b) An array Arr[40][10] is stored in the memory along the column with each element
occupying 4 bytes. Find the address of the location Arr[3][6], if the location Arr[30][10] is
stored at the address 9000. [4]

(c) Write a function in C++ to insert an element into a dynamically allocated Queue where
each node contains a name (of type string) as data. [4]

Assume the following definition of THENODE for the same.


struct THENODE
{
char Name[20];
THENODE *LINK;
};
(d) Write a function in C++ to print the product of each column of a two dimensional
integer array passed as an argument of the function.
Explain: If the two dimensional array contains. [2]
1 2 4
3 5 6
4 3 2
2 1 5

then, the output should appear as:


Product of column 1 = 24
Product of column 2 = 30
Product of column 3 = 240

(e) Evaluate the following postfix notation of expression (Show status of Stack after
execution of each operation): [2]
4,10,5,+,*,15,3,/,-
ANSWERS
(a)
# include < iostream.h >
# include < conio.h >
# define n 9
void Reverse(int[], int);
void main()
{
int num[n], i;
cout << "Enter nine elements" << endl;
for ( i=0; i < n;i++)
{
cin >> num[i];
}
cout << "Initially the array is:" << endl;
for(i=0; i < n; i++)
{
cout << num[i] << endl;
}
Reverse(num, i-1);
getch();
}
void Reverse(int num[], int i)
{
int index, a, j, temp, k;
index=i;
a=i/2;
if(i%2==1)
a=a+1;
for(k=0;k < a;k++,i--)
{
temp=*(&num[i]);
num[i]=num[k];
*(&num[k])=temp;
}
cout << "After reversing" << endl;
for(j=0; j < = c; j++)
{
cout << num[j] << endl;
}
}

(b) The address of an element a[i][j] is given as:


Address of a[i][j]= Base address + w[n(j-0) + (i-o)]
Here,
Base address is the address of the first element of the array,
w is the element size,
n is the number of rows.

In the given example:


Arr[40][10] is given:
Arr[30][10]=9000
Let base address be a[0][0],
w or element size = 2
n or number of rows = 40

Therefore,
Arr[30][10]= Arr[0][0] + 2[40(10-0)+(30-0)]
9000= Arr[0][0] + 2[40 x 10 + 30]
9000=Arr[0][0] + 2(400 +30)
9000=Arr[0][0] + 2 x 430
9000= Arr[0][0] + 960
Arr[0][0] = 9000 – 960
Arr[0][0] = 8040

Now, to find
Arr[3][6] = 8040 + 2[40(6-0) + (3-0)]
= 8040 + 2[40 x 6 + 3]
= 8040 + 2[240 + 3]
= 8040 + (2 x 243)
= 8040 + 486
= 8526

(c)
# include < iostream.h >
# include < conio.h >
# include < stdlib.h >
struct THENODE
{
char Name[20];
THENODE *LINK;
};
class MyQueue
{
THENODE * Rear, * Front;
public:
MyQueue()
{
Rear=NULL;
Front=NULL;
}
void Insert();
};
void MyQueue:: Insert(void)
{
Rear= new NODE;
cout << "Insert name" << endl;
cin >> Rear-> Name;
if ( Front == NULL)
{
Front = Rear;
Front->Next=NULL;
}
else
{
Rear-> Next=Front;
Front=Rear;
}
}

(d)
void Arrayproduct(int a[][], int n_row, int n_col)
{
int product=1, x,y;
for(int x=0; x < c; x++)
{
for(product=1, y=0; y < r, y++)
{
product = product * a[y][x];
}
cout << "n Product of column: " << x << "=" << product;
}
}
(e)

S.No. Element Scanned Operation Infix Expression


1 4 Push 4 4
2 10 Push 10 4,10
3 5 Push 5 4,10,5
4 + Pop 5,pop 10 4,15
(10+5)
5 * Pop 15,pop 4 60
(4*15)
6 15 Push 15 60,15
7 3 Push 3 60,15,3
8 / Pop 3,pop 15 60,5
(15/3)
9 - Pop 5, pop 60 55
(60-5)

The given expression evaluates to 55.


2007
(a) Write a function in C++ which accepts an integer array and its size as
arguments and replaces elements having odd values with thrice its value and
elements having even values with twice its
value. [4]
Example: If an array of five elements initially contains the elements as
3, 4, 5, 16, 9 then, the function should rearrange the content of the array as 9, 8, 15, 32, 27 4

(b) An array Array [20][15] is stored in the memory along the column with each element occupying
8 bytes. Find out the Base Address and address of the element Array[2][3] if the element Array [4]
[5] is stored at the address 1000. [4]

(c) Write a function in C++ to delete a node containing Book’s information, from a dynamically
allocated Stack of Books implemented with the help of the following structure.
[4]
struct Book
}
int BNo;
char BName[20];
Book *Next;
};

(d) Write a function in C++ which accepts a 2D array of integers and its size as arguments and
displays the elements which lie on diagonals. [2]
[Assuming the 2D Array to be a square matrix with odd dimension
i.e. 3×3, 5×5, 7×7, etc.]
Example, if the array content is
543
678
129
Output through the function should be :
Diagonal One : 5 7 9
Diagonal Two : 3 7 1

(e) Evaluate the following postfix notation of expression : [2]


25 8 3 - / 6 * 10 +
ANSWERS
(a) void func ( int *arr[ ], int size )
{
int i;
for ( i=0; i < size; i++ )
if (arr[i] % 2==0)
arr[i] = arr[i] * 2;
else
arr[i]= arr[i] *3;
for ( i=0; i < size; i++ )
cout << arr [i] << “, “;

(b) In column major arrangement in C++, address of a particular location (I, J) is


calculated as:
Address [I] [J] = B+ W [ n (J-0) + (I-0 )]
Where,
B- Base address
W- Element size
n- no. of rows

Given is:
A[4] [5] = B + W [20 [5-0] + [4-0] ]
1000 = B + 8 [20 * 5 + 4]
1000= B+ 8 (100 + 4 )
1000= B + 832
1000-832 = B
B= 168

Base address = 168


Now, A[2][3]= 168 + 8 [20(3) +2]
A[2][3] = 168 + 496
A[2] [3] = 664

(c) struct *top;


void del()
{
Book * ptr;
if ( ! top)
{
cout << “Ünderflown” ;
exit(1);
}
else
{
ptr=top;
top= top -> Next;
delete ptr;
}
}

(d) void Diag (int *arr[ ] [ ], int R, int C)


{
int i;
if (R! = C|| ( R%2 =0 && C%2=0)
{ cout << “ Array is not square matrix with odd dimension: “;
exit (0);
}
cout<< “Diagonal One: “ ;
for (i=0; i
cout << arr [i] [i];
cout << endl << “Diagonal Two: ” ;
for ( i= R-1; i>=0; i--)
cout << arr[i] [i];
}

(e) Evaluation of Postfix Notation:


25 8 3 - 6 * 10 +
= 25 / (8-3) * 6 +10
= 25/5 * 6 +10
= 5 * 6 + 10
= 30 + 10
= 40
2006
(a) Write a function in C++ which accepts array and its size as
arguments/parameters and assign the elements into a two dimensional array of
integer in the following format [3]

If the array is 1,2,3,4,5,6


The resultant 2D array is given below
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

If the array is 1,2,3


The resultant 2D array is given below
1 2 3
1 2 0
1 0 0

(b) An array MAT[30[10] is stored in the memory column wise with each element occupying 8
bytes of memory. Find out the base address and the address of element MAT[20][5], if the location
of MAT[5][7] is stored at the address 1000. [4]

(c) class queue


int data[10];
int front, rear;
public:
queue() (front = -1; rear = -1;)
void add(); // to add an element into the queue
void remove(); // to remove an element from the queue
void Delete(int ITEM); //to delete all elements which are
equal to ITEM
};
Complete the class with function definitions for a circular array queue. Use another queue to
transfer data temporarily. [4]

(d) Write a function in C++ to perform push operation on a dynamically allocated stack containing
real number. [3]

(e) Write the equivalent infix expression for


a, b, AND, a, c, AND, OR [2]
ANSWERS
(a) #include < iostream.h >
void r2D(int arr[], int size)
{ int arr1 [15] [15], I, j;
for( I =0; I < size; I++)
for( j =0; j < size; I++)
arr1 [I] [j] = 0;
for( I =0; I < size; I++)
for( j =0; j < size – I; j++)
arr1[I] [j] = arr[j];
cout << “The resultant 2D array is:”;
for( I =0; I < size; I++)
{ for(j = 0; j < size; j++)
cout << arr1[I] [j] << ”t”;
cout << endl;
}
}
void main()
{
int arr[15], I, size;
cout << ”n Enter the size of the array:”;
cin >> size;
cout << Ënter the elements of the array:”;
for (I = 0; I < size; I++)
cin >> arr[I];
r2D(arr, size);
}

(b) In column major arrangement in C++, address of a particular location (I,J) is


calculated as:
Address[I][J] = B + W[n(J-0) + (I – 0)]
Where B is the base address, W is the element size and n is the number of
rows.
Given is:
MAT[5] [7] = B + W[30(7-0)+(5-0)]
1000 = B + 8[210 + 5]
B = -720
Base Address B = -720
Now,
MAT[20][5] = -720 + 8[30(5) +20)]
= -720 + 8[150 + 20]
= -720 + 1360
= 640

(c) class queue


{ int data[10];
int front, rear;
public:
queue() {front = -1; rear = -1;}
void add()
{ cout << Enter the value to add in the queue:”;
cin >> data[rear +1];
if( front == -1)
{
front = 1;
rear = 1;
}
else
rear = rear +1;
}
void remove()
{
if(front == -1)
{
cout << ”n The value which is to be removed from
the queue is:” << data[front];
data[front] = -1;
front = front – 1;
}
}
void Delete(int ITEM){
int temp[10], I, j, counter = 0;
j = front;
for( I = 0; I < 10 && j >=0; I++, j--)
{ if(data[i]! = ITEM)
{
temp[I] = data[I];
counter+= 1;
}
}
for( I =0; I < 10; I++)
data[I] = -1;
for( I =0; I < front_counter; I++){
data[I] = temp[I];
front = I-1;}
}

(d) #include < iostream.h >


#include< conio.h >
struct node
{
float data;
node *link;
};
node *push(node *top, float val)
{ node *temp;
temp = new node;
temp -> data = val
temp -> link = NULL;
if(top == NULL)
top = temp;
else
{
temp -> link = top;
top = temp;
}
return(top); }

(e) Infix notation:


a AND b OR a AND c
2005
(a) Write a function in C++ which accepts an integer array and its size as
arguments/parameters and exchanges the values of the first half side
elements
with the second half side elements of the array. [3]
Example:
If an array of eight elements has initial content as:
2,4,1,6,7,9,23,10
The function should rearrange the values as:
7,9,23,10,2,4,1,6

(b) An array Arr[15][35] is stored in the memory along the column with each of its
elements occupying 8 bytes. Find out the base address and the address of an element
Arr[2][5], if the location Arr[5][10] is stored at the address 4000. [4]

(c) Write a function in C++ to perform a PUSH operation in a dynamically allocated


stack considering the following: [4]
struct Node
{
int X, Y;
Node *Link;
};
class STACK
{
Node *Top;
public:
STACK () { Top=NULL;}
void PUSH();
void POP();
~STACK();
};

(d) Write a function in C++ to print the sum of all the values which are either divisible
by 2 or are divisible by 3 present in a two dimensional array passed as the argument to
the function. [3]

(e) Evaluate the following postfix notation of expression: [2]


10 20 + 25 15 - * 30 /
ANSWERS
(a)
void swap( int a[], int size)
{
int middle, oddvalue, midvalue, temp;
middle=size/2;
if(size%2==0)
oddvalue=0;
else
{
oddvalue=1;
midvalue=a[middle];
}
for(int I=0; I< middle; I++)
{
temp=a[I];
a[I]=a[middle +I + oddvalue];
a[middle + I]=temp;
}
if(oddvalue==1)
a[size-1]=midvalue;
}

(b) The formula to find the address of an array element in column major form is:
A[I][J]= B + W[N(J-0) + (I-0)]
Where,
B is the base address,
W is the element size,
N is the number of rows.

Given:
An array Arr[15][35] with W=8,
Address of Arr[5][10]=4000

Now,
Arr[5][10]=4000
B + W [N (J-0) + (I-0)] =4000
B + 8 [15 (10-0) + (5-0)]= 4000
B+ 8[15 X 10 +5] =4000
B + 8(150+5)=4000
B+ 8 X 155=4000
B + 1240=4000
B=4000-1240
B=2760
Address of Arr[2][5]= B + W[N(J-0) +(I-0)] Arr[2][5]= 2760 + 8[15(5-0) +
(2-0)]
Arr[2][5]=2760+ 8[15 x 5 + 2]
Arr[2][5] = 2760 + 8[75+2]
Arr[2][5]=2760 + (8 x 77)
Arr[2][5]=2760+ 616
Arr[2][5]=3376

(c)
STACK :: PUSH()
{
Node *Temp;
Temp=new Temp;
if(Temp)
{
cout << “n Enter the value of X:”;
cin >> TempX;
cout << “n Enter the value of Y:”;
cin >> TempY;
Temp Link=Top;
Top=Temp;
}
else
cout << “n Error in memory allocation”;
}

(d)
void Sum_of_numbers(int arr[][], int row, int column)
{
int I=0, J=0, Sum=0;
for(I=0;I
{
for(J=0;J
{
if((arr[I][J]%2==0) || (arr[I][J]%3==0))
sum=sum+arr[I][J];
cout << “Sum_of_numbers = “ << sum;
}
}
}

(e)

S.No. Element Scanned Operation Infix Expression


1 10 Push 10 10
2 20 Push 20 10,20
3 + Pop 20, Pop 10, 30
Push(20+10)
4 25 Push 25 30,25
5 15 Push 15 30,25,15
6 - Pop 15, Pop 25, 30, -10
Push (15-25)
7 * Pop -10, Pop 30, -300
Push (-10*30)
8 30 Push 30 -300, 30
9 / Pop 30, Pop -300,
Push(30/-300)

MODEL PAPER 1
a) Write a function in C++, which accepts an integer array and its size as
arguments/parameters and exchanges the values of first half side elements with
the second half side elements of the array.

If an array of eight elements has initial content as


2,4,1,6,7,9,23,10
The function should rearrange the array as
7,9,23,10,2,4,1,6

b) An array Arr[15][25] is stored in the memory along the column with each of its
elements occupying 4 bytes. Find the base address and the address of Arr[4][5].
If Arr[5][10] is located at 2600.

c) Write a function in C++ to perform a PUSH operations on a dynamically


allocated stack containing real number?

d) Write a function in C++ to find the sum of rows elements of a 2D array A[8][8]
containing integers
e) Evaluate the following postfix notation of expression:
10 20 + 25 15 - * 30 / [4+4+2+2+2=14]
ANSWERS
nswer:

a)
void Exchange (int A [ ], int N)
{
for (int I=0;I< N/2;I++)
{
int Temp=A[I];
A[I]=A[N/2+I];
A[N/2+I]=Temp;
}
}

b)
LOC(Arr[5][10])=Base(Arr)+W*(i+No. of Rows*j)
LOC(Arr[3][7])=Base(Arr)+4*(5+15*10)
2600=Base(Arr)+4*155
2600=Base(Arr)+620
Base(Arr)=2600-620
Base(Arr)=1980

Base Address=1980

LOC(Arr[4][5]) =Base(Arr)+W*(i+No. of Rows*j)


=1980+4*(4+15*5)
=1980+4*79
=1980+316
=2296

c)
struct Node
{
float data;
Node * next;
};
void push (Node *Top, float num)
{
Node*nptr = new Node;
nptr -> data = num;
nptr -> next = NULL;

if(Top == NULL)
Top = nptr;
else
{
nptr -> next = Top;
Top = nptr
}
}

d) The function is:

void Add(int A[8][8])


{
int sum, i,j;
for(i=0; i < 8;i++)
{
sum=0;
for(j=0; j < 8;j++)
sum=sum+A[i][j];
cout<< "The sum of the rows :"<< j+1<<" is "<< sum<< endl;
}
}

e)

Operand/Operator Stack Status


10 10
20 10,20
+ 30
25 30,25
15 30,25,15
- 30,10
* 300
30 300,30
/ 10

MODEL PAPER 2
a) Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the elements of the middle row and the elements of
middle column.
Example if the array content is
354
769
218

Output should be -
Middle row: 769 Middle column: 5 6 1

b) An array Arr[35][15] is stored in the memory along the row with each of its
elements occupying 4 bits. Find out the base address and the address of the
element Arr[20][5], if the location Arr[4][4] is stored at the address 2800.

c) Each node of a STACK containing the following information, in addition to


required pointer field -
Roll no. of the student.
Age of the student.

Give the structure of node for the linked stack in question.


TOP is a pointer to the topmost node of the STACK.

Write the following function -


PUSH() – TO push a node in to the stack which is allocated dynamically.
POP() – To remove a node from the stack and to release the memory.

d) Write a function in C++ to find the sum of columns elements of a 2D array


A[8][8] containing integers.

e)Evaluate the following postfix expression using a stack. Show the contents of
stack after execution of each operation:

20, 8, 4, /, 2, 3, +, *, -

[4+2+4+2+2=14]
ANSWERS
a)
#include < stdio.h>
#include < iostream.h>
#include < conio.h>
const M = 10;
const N = 10;
void display_RowCol(int Array[M][N], int r, int c)
{ int row = r / 2;
int col = c / 2;
// Finding the middle row
cout << "Middle Row : ";
for(int j=0; j< c; j++)
cout << Array[row][j] << " ";
cout << endl;
// Finding the middle column
cout << "Middle Column : ";
for(j=0; j< c; j++)
cout << Array[j][col] << " ";
getch();
}
void main()
{ int Array[M][N];
int i, j;
int r, c;
cout << "Enter total no. of rows: ";
cin >> r;
cout << "Enter total no. of columns: ";
cin >> c;
if ((r == c) && ((r%2==1) && (c%2==1)))
{ cout << "Input steps";
cout << "nEnter the element in the arrayn";
for(i=0; i< r; i++)
for(j=0; j< c; j++)
{ cin >> Array[i][j]; }
}
else
{ cout << "Input row and column not valid";
getch();
return;
}
display_RowCol(Array, r, c);
}

b) Base address is
LOC(Arr[i][j])=Base(Arr)+W*(i+No. of Rows*j)
LOC(Arr[4][4])=Base(Arr)+4*(4+35*4)
2800=Base(Arr)+4*144
2800=Base(Arr)+576
Base(Arr)=2800-576
Base(Arr)=2224
LOC(Arr[i][j])=Base(Arr)+W*(i+No. of Rows*j)
LOC(Arr[20][5])=2224+4*(20+35*5)
LOC(Arr[20][5])=2224+4*195
LOC(Arr[20][5])=2224+780
LOC(Arr[20][5])=3004

c)
struct STACK
{
int rollno, age;
STACK *next;
} *top, *nptr, *ptr;

void pop()
{
if (!pop) { cout << ”nUnderflow!!” ; exit(1); }
else
{ cout << ’n’ << top -> rollno << ’t’ << top -> age;
ptr = top;
top = top -> next;
delete ptr;
}
}
void push()
{
nptr = new stack; //allocate memory
cout << “n Enter roll number and age:“ ;
cin >> nptr-> rollno >> nptr->age ;
nptr -> next = NULL;
if (!top) top = nptr;
else
{
ptr -> next = top;
top = nptr
}
}

d) The function is:

void Add(int A[8][8])


{
int sum, i,j;
for(i=0;i< 8;i++)
{
sum=0;
for(j=0;j< 8;j++)
sum=sum+A[j][i];
cout<< ”The sum of the column :”<< i+1<< ” is “<< sum<< endl;
}
}

e)
Operand/Operator Stack Status
20 20
8 20,8
4 20,8,4
/ 20,2
2 20,2,2
3 20,2,2,3
+ 20,2,5
* 20,10
- 10
Answer is 10
MODEL PAPER 3
a) An array salary[50] contains the salary of 50 employees in a company. Write a
function in C++ to find the number of employees getting salary:
i) more than 10000 ii) less than 6000

b) An array Arr[15][25] is stored in the memory along the column with each of its
elements occupying 8 bytes. Find the base address and the address of Arr[2][5].
If Arr[5][10] is located at 3800.

c) Each node of a STACK containing the following information, in addition to


required pointer field:

Roll no. of the student


Age of the student.

Give the structure of node for the linked stack in question.

TOP is a pointer to the topmost node of the STACK. Write the following function:
PUSH() – TO push a node in to the stack which is allocated dynamically.
POP() – Te remove a node from the stack and to release the memory.

d) Write a function in C++ to display the elements of an array Arr[5][5]. Also


replace the elements which are even by 1 and print the matrix
again.

e) Evaluate the following postfix using a stack and show the content of the stack
after the execution of each
operation:
5,11,-,6,8,+12,*,/
[4+2+4+2+2=14]
Answer:

a)
The function is:

void sal()
{
int num1=0,num2=0;
for(i=0;i< 50;i++)
{
if(salary[i]>10000)
{
num1=num1+1;
}
if(salary[i]< 6000)
{
num2=num2+1;
}
}
cout<< ”Number of employees getting salary more than 10000=”<< num1<< endl;
cout<< ”Number of employees getting salary less than 6000=”<< num2;

}
b)
LOC(Arr[5][10])=Base(Arr)+W*(i+No. of Rows*j)
LOC(Arr[3][7])=Base(Arr)+8*(5+15*10)
3800=Base(Arr)+8*155
3800=Base(Arr)+1240
Base(Arr)=3800-1240
Base(Arr)=2560

Base Address=2560

LOC(Arr[2][5]) =Base(Arr)+W*(i+No. of Rows*j)


=1056+8*(2+15*5)
=2560+8*77
=2560+616
=3176

c)
struct STACK
{
int rollno, age;
STACK*next;
} *top, *nptr, *ptr;
void pop()
{
if (!pop)
{
cout << ”n Underflow!!” ;
exit(1);
}
else
{ cout << ’n’ << top -> rollno << ’t’ << top -> age;
ptr = top;
top = top -> next;
delete ptr;
}
}
void push()
{
nptr = new stack; //allocate memory
cout << “n Enter roll number and age to be inserted : “ ;
cin >> nptr-> rollno >> nptr->age ;
nptr -> next = NULL;
if (!top) top = nptr;
else
{
ptr -> next = top;
top = nptr
}
}
d)
void convert(int Arr[5][5])
{
int i,j;
cout<< ”The array is:-“<< endl;
for(i=0;i< 5;i++)
{
for(j=0;j< 5;j++)
{
cout<< Arr[i][j];
}
cout<< endl;
}
for(i=0;i< 5;i++)
{
for(j=0;j< 5;j++)
{
if(Arr[i][j]%2==0)
Arr[i][j]=1;
}
}
cout<< ”The array is after conversion:-“<< endl;
for(i=0;i< 5;i++)
{
for(j=0;j< 5;j++)
{
cout<< Arr[i][j];
}
cout<< endl;
}
}

e)

S.No. Element Scanned Operation Infix Expression


1 5 Push 5 5
2 11 Push 11 5,11
3 - Pop 11,pop 5 (5-11) -6
4 6 Push 6 -6,6
5 8 Push 8 -6,6,8
6 + Pop 8, pop 6 (6+8) -6,14
7 12 Push 12 -6,14,12
8 * Pop 12,pop 14 (14*12) -6,168
9 / Pop 168, pop -6 (-6/168) -1/28
Ans: -1/28
MODEL PAPER 4
a) To merge two given arrays A in ascending order, B in descending order into
third array C, which should be in ascending order. Suppose A, B, C are arrays of
integers of size M, N and M+N respectively. The numbers in array A appear in
ascending order while the numbers in array B appear in descending order Write a
user defined function in C++ to produce third array C by merging arrays A and B in
ascending order. Use A, B and C as arguments in the function.

b) An array Arr[35][15] is stored in the memory along the row with each of its elements occupying
4 bits. Find out the base address and the address of the element Arr[20][5], if the location Arr[4][4]
is stored at the address 2800.

c) Write a function in C++ to perform Push operation on a dynamically allocated Stack .

d) Write a function in C++ to find the sum of columns elements of a 2D array


i.e. A[8][8] containing integers.

e) Write the equivalent infix for 19, 12, +, 19, 5,*, +, 29, +
ANSWERS
a)
#include < iostream.h > void Merge(int [ ],int, int[ ], int, int[ ]) ; //
Function for merging 2 arrays void main() { int A[50], B[50], C[50], MN=0,
M, N; cout << "How many elements do you want to create first array with?
(max = 50)" ; cin >> M ; cout << "nEnter First Array’s elements
[ascending]… n" ; for(int i=0 ; i cin >> A[i] ; cout << "nHow many
elements do you want to create second array with? (max = 50)" ; cin >> N ;
MN = M + N ; // array C’s size calculated cout <<
"nEnter Second Array’s elements [descending]…n" ; for(i=0 ; i
Merge(A,M, B,N, C) ;
cout << "nnThe Merged array is as shown below… n" ; cin >> B[i] ; for(i = 0 ; i <
MN ; i++) { cout << C[i] << " "; } } void Merge (int A [ ], int M, int B[ ],
int N, int C[ ]) //function to perform merging {
int a,b,c ; //M – size of array A ; N – size of array B ; c – resultant array
for(a=0, b=N-1, c=0 ; a< M && b>=0 ;) //notice the initial values of
control vars. a,b,c {
if ( A[a]<=B[b]) C[c++]=A[a++] ;
else
C[c++] = B[b--]; } if (a < M) {
while(a < M) C[c++] = A[a++] ; } else {
while(b>=0) C[c++] = B[b--] ; } }
How many elements do you want to create first array with? (max = 50)…5
Enter First Array’s elements [ascending]…
2 5 8 9 12
How many elements do you want to create second array with? (max = 50)…7
Enter Second Array’s elements [descending]..
16 12 10 8 7 3 1
The Merged array array is as shown below…
1 2 3 5 7 8 8 9 10 12 12 16

b)
Row Major:
A[i][j] = B + W [ C ( I – Lr ) + ( J – Lc ) ]
B=? , W=4 , Lr=0, Lc=0
A[4][4] = B + 4[ 15(4-0) + (4-0)]
2800 = B + 4[ 60 + 4 ]
2800 = B + 4*64
2800 = B + 256
B= 2800 – 256
B= 2544

A[20][5]= ?
A[i][j] = B + W [ C ( I – Lr ) + ( J – Lc ) ]
A[20][5] = 2544 + 4[ 15( 20-0) +(5-0)]
= 2544 + 4 [ 300 +5]

= 2544 + 4*305

= 2544 + 1220

= 3768

c)
class stack
{
int element;
stack* next;
public:
stack* push(stack*,int);
}*head,object;

stack* stack::push(stack* head, int key)


{
stack* temp,*temp1;
temp1=head;
temp=new stack;
temp->element=key;
temp->next=NULL;
if(head==NULL)
head=temp;
else
{
while(head->next!=NULL)
head=head->next;
head->next=temp;
head=temp1;
}
return head;
}

d) The function is:

void Add(int A[8][8])


{
int sum, i,j;
for(i=0;i< 8;i++)
{
sum=0;
for(j=0;j< 8;j++)
sum=sum+A[j][i];
cout<< ”The sum of the column :”<< i+1<< ” is “<< sum<<
endl;
}
}

e)

S.No. Element Scanned Operation Infix Expression


1 19 Push 19 19
2 12 Push 12 19,12
3 + Pop, Pop, Push(19+12) 31
4 19 Push 19 31,19
5 5 Push 5 31,19,5
6 * Pop, Pop, Push (19*5) 31,95
7 + Pop, Pop, Push(31+95) 126
8 29 Push 29 126,29
9 + Pop, Pop, Push(126+29) 155

Вам также может понравиться