Answer Key (Prelim)- Jan 2024
Sub:- Computer Science
1. D. No of Arguments are same
2. Error
3. B5
4. A. content of file will be deleted if file exists.
5. D. Exclusive NOR gate
6. Error Ans Repeater
7. A. Circuit Switching Technique
8. Advantages of inline function
i. Program speed increases
ii. It does not require function calling overhead.
9. If a class has more than one constructor it is called constructor over
loading .
10.A linked list is a linear data structure which consists of collection of
nodes , where each node consists of two parts the data part and the link to
the next node.
11.A text is a file of characters stored on a particular area on the hard disk.
12.
A B A.B
0 0 0
0 1 0
1 0 0
1 1 1
13. i. It is very cost effective/ fast than conventional mail
ii . Reusability
14.
15.
Class , object, inheritance , encapsulation, abstraction,
polymorphism
16. Local and global variables
i. Local variables can be used only in the function in which they
are defined./ Global variables can be used in the entire program
ii . Memory allotted to local variables is released when function
exits / memory space allotted to global variables is released when
program exits.
17. Data encapsulation:- It refers to wrapping up of data and functions
into a single unit called class.
Data abstraction: It refers to process of providing only the essential
details to the outside world and hiding the internal details
18.
Pass I Pass II Pass III
12 12 12 12 12 12
10 10 10 10 10 10
4 4 4 6 6 8
2 6 6 4 8 6
6 2 8 8 4 4
8 8 2 2 2 2
19. i. ifstream f1(“Info.txt”) ;
ii .f1.getline(s[], 80);
20.
a. ios:::ate - to add content anywhere in the file
b. ios::nocreate – file will not be created if file does not exists
c. seekp() - to move the put pointer to the specified position in the
file
d. tellg() - it gives the current position of the get pointer.
21.
22. Bus topology V/s Ring Topology
Nodes are connected on either side to a single cable. / Nodes are
connected in ring shape manner.
If node fails network is not affected/ one node failure causes
network failure.
23. Protocol :- is a set of rules that govern a transfer of data over the
internet.
HTTP – it stands for hyper text transfer protocol. Is a set of rules
that govern the transfer of hypertext / webpages over the internet.
24. Switching techniques
Circuit switching – path is reserved in advance , charging
algorithm is based on distance and time
Packet switching – path is not reserved, data is divided into
packets, charging algorithm is based on amount of data used.
Message switching – data is transferred as one mesaage, size of of
message is the limitation, charge is per message and depends on
distance.
25.
#include<iostream.h> #include<iostream.h>
main() main()
{ {
int n; int n;
cin>>n; cin >>n;
for(int i=1;i<=n;i++) for(int i=1; i<=n;i++)
{ {
for(int j=1;j<=n;j++) for(int j=0; j<=2*I; j+=2)
{ {
if(i==1||i==n||j==(n-i)) cout<<char(65+j);
cout<<1<<” “; }
else cout<<”\n”;
cout<<” “ }
} }
cout<<”\n”;
} }
}
26. i. ALPHA BETA GAMMA
ii . BETA ALPHA GAMMA
iii . multiple inheritance
27.
#include<iostream.h>
main()
{
int no,revno,digit;
for(int i=100;i<1000;i++)
{
no=i;
revno=0;
while(no!=0)
{
digit=no%10;
revno=revno*10+digit;
no=no/10;
}
if(revno==i)
cout<<i<<" , ";
}
}
28. Binary search method:- Precondition for this method is array
should be in ascending order. It works on the principle of divide and rule.
Each time array is divided into two half and mid is found . Element to be
searched is compared with mid position element . if its equal the search
stops otherwise search continues in one of the half. The process continues
till element is found or array cannot be further subdivided.
Bubble sort method:- In this method the consecutive elements are
compared and exchanged if required . The process continues till the
array is sorted . this method has internal passes.
29.
A%(B-C)*(D+E)/F
Step No symbol action Stack o/p
1 A O/P A
2 % PUSH % A
3 ( PUCH %,( A
4 B O/P %,( AB
5 - PUSH %,(,- AB
6 C O/P %,(,- ABC
7 ) POP %,( ABC-
POP % ABC-
8 * POP ABC-%
PUSH * ABC-%
9 ( PUSH *( ABC-%
10 D O/P *( ABC-%D
11 + PUSH *(+ ABC-%D
12 E O/P *(+ ABC-%DE
13 ) POP *( ABC-%DE+
POP * ABC-%DE+
14 / POP ABC-%DE+*
PUSH / ABC-%DE+*
15 F O/P / ABC-%DE+*
POP ABC-%DE+*/
10,5,*,6,5,/,+,13,3,%,-
Step No Symbol Action Stack
1 10 Push 10
2 5 Push 10,5
3 * Pop 10
Pop
10*5=50
Push 50
4 6 Push 50,6
5 5 Push 50,6,5
6 / Pop 50,6
Pop 50
6/5=1
Push 50,1
7 + Pop 50
Pop
50+1=51
Push 51
8 13 Push 51,13
9 3 Push 51,13,3
10 % Pop 51,13
Pop 51
13%3=1 51
Push 51,1
11 - Pop 51
Pop
51-1=50 Ans=50
30. void findsum(int A[][], int n)
{
int sum1=0, sum2=0;
for(int i=0; i<n;i++)
{
sum1=sum1+A[i][i];
sum2=sum2+A[i][n-i-1];
}
cout<<”sum1=”<<sum1<<”\n”;
cout<<”sum2=”<<sum2<<”\n”;
}
31.
c+d c+d’ c’+d’ c’+d
a+b 1 1
a+b’ 1 1
1 1
a’+b’
a’+b 1 1
f=f0.f1
f=(b+d’).(b’+d)
32.
a b c O/P
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
F=a’b’c+a’bc’+ab’c’+abc
33. class INSTITUTION
{
int insttutionid;
public:
INSTITUTION()
{
institutionid=0;
}
protected:
void display()
{
cout<<institutionid;
}
};
class INSTIINCOME
{
float income;
public:
INSTIINCOME()
{
income=0;
}
protected:
void display()
{
cout<<income;
}
};
class IOFFICE
{
char name[30];
INSTITUTION x;
INSTIINCOME y;
public:
IOFFICE()
{
name=” “;
}
void display()
{
cout<<name;
}
};
main()
{
IOOFICE i1;
i1.x.display();
i1.y.display();
i1.display();
}
34. main()
{
fstream fi;
f1.open (“emp.dat”,ios::in|ios::out|ios::binary);
EMPLOYEE e1;
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
e1.getdata();
f1.write((char *)&e1,sizeoif(e1));
}
f1.seekg(0);
while(f1)
{
f1.read((char *)&e1, sizeof(e1));
if(e1.empsal>100000)
e1.display();
}
f1.close();
}
OR
main()
{
fstream f1,f2,f3;
EMPLOYEE e1;
f1.open(“Empadm.dat”,ios::in|ios::binary);
f2.open(“Empprod.dat”,ios::in|ios::binary);
f3.open(“Emp.dat”,ios::out|ios::binary);
while(f1)
{
f1.read((char *)&e1, sizeof(e1));
f3.write((char *)&e1, sizeof(e1));
}
while(f2)
{
f2.read((char *)&e1, sizeof(e1));
f3.write((char *)&e1, sizeof(e1));
}
f1.close();
f2.close();
f3.close();
}
35.
void addnode() void display()
{ {
int pos; node *temp;
node *temp,*temp1; if(FIRST== NULL)
cin>>pos; cout<<”linked list is empty”;
temp=FIRST; else
for(int i=1;i<pos; i++) {
{ temp=first;
temp1=temp; while(temp!=NULL)
temp=temp->link; {
} cout<<temp->link<<”,”;
temp= new node; temp=temp->link;
cin>>temp->data; }
temp->link=temp1->link; }
temp1->link=temp1; }
if (pos==0)
first=temp;
}
OR
void push() void pop()
{ {
node *temp; node *temp;
temp=new node; if (top==NULL)
cin>>temp->data; cout<<”Stack is empty”;
temp->link=top; else
top=temp; {
} } temp=top;
top=top->link;
cout<<temp->data <<”deleted”;
delete temp;
}
}