# Computer Science Questions

## ZS Associates Questions asked in Computer Science Section

Questions asked in ZS associates for the Computer Science Section can be found out on this page.

There will be total 10 questions and the time will be shared with other sections of the test.

### ZS Associates Computer Science Papers

1. Use the following query to answer:

SELECT empno, e.deptno, dname, salary

FROM emp e, dept d

WHERE e.deptno = d.deptno;

Which of the following SQL statement is equivalent to the above query’?

1. SELECT empno, deptno, dname, salary FROM emp e JOIN dept d ON e.deptno = d.deptno:

2. SELECT empno, deptno, dname, salary FROM emp JOIN dept USING (e.deptno, d.deptno);

3. SELECT empno, deptno, dname, salary FROM emp NATURAL JOIN dept:

4. SELECT empno, deptno, dname, salary FROMemp WHERE deptno IN (SELECT deptno FROM dept);

Solution: We need to do a join to extract data from both the tables. For this, we also have to out the condition of e.deptno = d.deptno.

2. In SOL. group functions operate on

1. sets of rows to give one result per group.

2. selected columns.

3. operates on multiple tables.

4. none of the listed options

Solution: The SOL group functions operate on sets of rows to give one result per group.

3. Find the virtual functions present in the given code.

#include <iostream>

using namespace std:

class Student

{

public: virtual void display() {

cout « “Student”;

}

};

class CompScStud : public Student

public void display() {

cout « “Computer Science student”;

}

};

void main()

{ student *s:

S=new CompScStud();

S->display();

}

};

1. display() function defined in base class Student

2. display() function defined in derived class CompScStud

3. display function defined in base class as well as derived class

4. None of the listed options

Correct option is: A.

Solution: Virtual functions are always present in the base class.

1. An overloaded operator can be defined as a friend of a class member.

2. Overloaded operator cannot be defined as a friend of a class or it must be the class member.

3. Operator must be defined as a friend of a class and cannot be a class member

4. Overloaded operator is not defined as a function.

Solution: Operators and functions are different entities, and operator cannot be defined as a friend.

5. Use the following SQL query to answer:

WHERE deptno=10 and sal< ANY (select max (sal)

From emp

Where ename LIKE ‘%A%’);

Which of the following appropriate options can be used to complete the above query to modify the employees salaries by adding 2000 to it?

1. Modify emp sal=sal+2000

2. Attach emp set sal=sal+2000

3. Update emp set sal=sal+2000

4. Add emp sal to sal=sal+2000

Solution: SQL uses the keyword Update a value in the table.

6. Data modelling entities usually have one or more of which of the following?

1. Sub entities

2. Keys

3. Relations

4. Synonyms

Solution: The entities of a data model has sub entities.

7. Which of the following statements is true with respect to the given code?

class Book {

int bookID:

public:

Book(int i)

{

bookID =i;

cout <,Book ID = bookID;

}

};

void main() Book Cormp(10):

1. The constructor with single argument Is executed 10 times with the value of the argument = 0

2. A runtime error occurs

3. The default constructor is executed 10 times

4. A compilation error occurs since the class Book does not have a default constructor

8. The data structure that can be used to check if an expression has matching opening or closing parentheses is

1. Queue

2. List Hash

3. Table

4. Stack

Solution: Stack is used to check to check matching parenthesis.

9. Which of the commands identify the category of DDL commands,

1. CREATE. ALTER. DELETE

2. INSERT. UPDATE. DELETE

3. CREATE. UPDATE. DROP

4. CREATE. ALTER. DROP

Solution: The DDL commands can create, update and drop a table from a database.

10. Which of the statement is not true about primary key,

1. It Is a unique Identifier for the table

2. It is a unique identifier for the table.

3. It is key which allows null records

4. it is a key attribute to identify the non-key attributes

Solution: The primary key does not allow null records.

11. Which of the following statements are true with respect to access specifiers?

(i) Private members are not available outside the class

(II) Protected members are not available outside the class

(III) Public numbers are not available outside the Gass

1. (I) only

2. (II) only

3. (III) only

4. (IV) only

Solution: The private members cannot be accessed outside of the class.

12. How many comparisons are required to sort the given set of elements 1, 2, 3, 4, and 5 using the insertion sort technique?

1. 10

2. 5

3. 4

4. 2

Solution: It will take every element to compare its value with the element at its left. Therefore, the total comparisons will be 10.

13. Which of following operators cannot be overloaded?

i) Scope resolution operator denoted by ::

(II) Member access operator or the dot operator denoted by .

IlI) Conditional operator denoted by ?:

(iv) Pointer to member operator denoted by ,*

1. I AND II ONLY

2. I ,II,IV ONLY

3. I ,III,IV ONLY

4. I ,II,III,IV ONLY

Solution: All the above mentioned operators cannot be overloaded.

14. Which of the statement is true about full outer join,

1. Retrieves on, matching records from the Joining tables

2. Retrieves both matching as well as unmatched records from the Joining tables

3. Retrieves unmatched records from left table

4. Retrieves unmatched and matching records from right table

Solution: It is used to retrieve both matched as well as unmatched data by joining tables.

15. For the C++ code given below, what will be the output?

#include <iostream>

#include <string>

Using namespace std;

Class order

{

Private: int orderID;

String orderDesrciption;

Public

Order () {orderID = 100;}

Order(int ID, string orderDesrciption= “”) {orderID= ID;}

Order (int ID) {orderID = ID;}

Int getOrderID() {return orderID;}

};

Class LocalOrder; public Order

{

Public LocalOrder(); Order(10){}

};

Void main()

{

Order “o = new LocalOrder;

Cout << o->getOrderID();

}

1. Compilation error, since a class constructor must be defined outside the class

2. Compilation error, since a class cannot have constructor with default arguments

3. Compilation error, since a class can have only one constructor.

4. Compilation error, since there is an ambiguous call to overloaded constructor.

Solution: Since there is an ambiguous call to the overloaded constructor, it will show compilation error.

16. For the below C++ code, what will be the output?

Class Account

{

Private:

Int accNo;

Public:

Void SetAccount (int accNo)

{

AccNo = accNo;

}

Void Display()

{

Cout << accNo;

}

};

Int main()

{

Account a1;

A1. SetAccount(1001);

A1.Display();

Return 0;

}

1. 1001

2. Compilation error

3. Garbage value

4. Runtime Error

Solution: As the object created is a1, but the object that calls the member function is A1.

17. PRODUCT

———————–

———————-

Product ID

Product description

Manufacturer ID

MANUFACTURER

——-

——–

Manufacturer ID

Manufacturer Name

You are running a query against a relational database.

Referring to the scenario above, what clause or command do you use in the query for faster retrieval of data?

1. GROUP BY clause

2. INDEX command

3. Having Clause

4. FROM clause

Solution: We will be using index command as it creates an entry for each value allowing faster retrieval of records from the table.

18. Which of the following are the disadvantages of a linear queue implemented as an array?

1) A stage may arrive when both front and rear are equal and point to the last location of the array i.e the queue is full since rear>=n-1 as well as empty since front=rear.

2) At a given time, all the locations to the left of the front are always vacant and unutilized.

1. (I) only

2. (II) only

3. Both (I) and (II)

4. Neither (I) and (II)