CS201 Collection of Old PApers

30
Question No. 2 Marks : 12 5 they have no relationship 4 a variable declaration has to the variable itself 3 a variable has to a variable declaration 2 an object declaration has to an object 1 a class definition has to an object definition A function declaration has the same relationship to a function definition that Question No. 1 Marks : 2 Total Marks: 100 Total Questions: 13 **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course. You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!) d. All coding questions should be answered using the C ++ syntax. c. Write all steps, missing steps may lead to deduction of marks. b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem. a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding. 2. Do not ask any questions about the contents of this examination from anyone. 1. Attempt all questions. Marks are written adjacent to each question. Please read the following instructions carefully before attempting any of the uestions: Time Allowed: 150 Minutes Final Term Examination - February 2005 CS201 Introduction to Programming www.vujannat.ning.com

description

CS201 Collection of Old PApers

Transcript of CS201 Collection of Old PApers

Page 1: CS201 Collection of Old PApers

Question No. 2 Marks : 12

5 they have no relationship 4 a variable declaration has to the variable itself 3 a variable has to a variable declaration 2 an object declaration has to an object 1 a class definition has to an object definition

A function declaration has the same relationship to a function definition that

Question No. 1 Marks : 2

Total Marks: 100 Total Questions: 13

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

d. All coding questions should be answered using the C ++ syntax. c. Write all steps, missing steps may lead to deduction of marks.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

2. Do not ask any questions about the contents of this examination from anyone.

1. Attempt all questions. Marks are written adjacent to each question.

Please read the following instructions carefully before attempting any of the uestions:

Time Allowed: 150 Minutes

Final Term Examination - February 2005

CS201 Introduction to Programming

www.vujannat.ning.com

Page 2: CS201 Collection of Old PApers

iii) PricesOfItems ii) Items i) OrderID

Create a class named Order. This class has the following attributes/ data members

Question No. 7 Marks : 20

3. Constructors 2. Instance methods 1. Instance variables

Briefly describe the role of each of the following within a class:

Question No. 6 Marks : 5

5 To private data declared in main() 4 Only to public data of the class 3 Only to private data of the class 2 Only to other friend functions of the class 1 To all data member and functions of the class

A friend function of a class has access

Question No. 5 Marks : 2

5 class template<class_name> 4 class class-name() 3 template < class T >, Here T can be replaced with any name but it is preferable. 2 template < class data_type> 1 template < class class_type>

When we write a class template the first line must be:

Question No. 4 Marks : 2

What is the difference between an array and a structure?

Question No. 3 Marks : 4

Write the main () to call the - operator and print the result also. This operator should subtract the items of one object from the other.

iii) PricesOfItems ii) Items i) OrderID

Write a function to overload subtraction operator for Class Order, which you created in previous question. The class has following attributes/ data members

Page 3: CS201 Collection of Old PApers

1 Student(); There is a class Student, Which one of the following is a valid destructor for this class.

Question No. 11 Marks : 2

5 fstream.h 4 seekp() 3 seekg() 2 tellp() 1 tellg()

If we open a file stream myfile for reading, what will give us the current position of the file pointer?

Question No. 10 Marks : 2

Write a program that inputs one string of max length of 10. If the string is identical to "Virtual", output the message "Correct Password"; otherwise, output the first four characters in the message and the length of the message.

Question No. 9 Marks : 15

5 can allocate an appropriate amount of memory for an object or variable 4 returns an address to an object or variable 3 names an object or variable 2 can not create and initialize an object 1 is used to declare objects or variables

The new operator

Question No. 8 Marks : 2

Also write the main () to create the object of class Order.

c) Write the setter functions for OrderID, Items, and PricesOfItems. And getter functions for OrderID and Items.

keyboard in PricesOfItems array and returns the result.

ii) SumPrices( ), this function will sum the prices of the items entered by the user from

invoice=SumPrices();

i) OrderBill ( ), this function will calculate the invoice of an order and display the result. The formula to calculate the invoice is

b) Write the following member functions of this class;

a) Create the object of this class using parameterized constructor in order to initialize OrderID and Items data members. Default values of both the data members must be equal to 1.

Page 4: CS201 Collection of Old PApers

0 2 4 6 8 10 12 14 16 18

Write code that will declare, initialize, and fill in an array of objects of type int. After your code executes, the array should look as follows.

Question No. 13 Marks : 6

What is a friend function? Explain with example?

Question No. 12 Marks : 5

5 ~ Student(int); 4 int~ Student(); 3 ~ Student(); 2 Student(int);

Page 5: CS201 Collection of Old PApers

A friend function

Question No. 1 Marks : 02 Total Marks: 70 Total Questions: 10

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

d. All coding questions should be answered using the C ++ syntax.

c. Write all steps, missing steps may lead to deduction of marks.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

2. Do not ask any questions about the contents of this examination from anyone.

1. Attempt all questions. Marks are written adjacent to each question.

Please read the following instructions carefully before attempting any of the questions:

Time Allowed: 150 Minutes

Final Term Examination – Spring 2005

CS201 Introduction to Programming

www.vujannat.ning.com

Page 6: CS201 Collection of Old PApers

Create a class named Account, its data members are

Question No. 6 Marks : 20

Write a program that uses a function template called min to determine the smaller of two arguments. Test the program using integer, character and floating point number pairs in main ().

Question No. 5 Marks : 08

returns an address to an object or variable oo can allocate an appropriate amount of memory for an object or

variable

o names an object or variable o can not create and initialize an object o is used to declare objects or variables

The new operator Question No. 4 Marks : 02

Write a program that uses a function multiple(int,int) that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first and 0 (false) otherwise. Use this function in a program that inputs a series of pairs of integers.

Question No. 3 Marks : 10

o Insertion operator (>>)

XOR ( ^ ) oo Complement operator ( ~ )

o AND ( &&) o OR ( || )

Which one of the following operators is a unary operator?

Question No. 2 Marks : 02

o cannot access the data members of a class o can access the private data of the class that declares it a friend

must be invoked by the class that declares it a friend oo must be invoked by an object of the class that declares it a friend

o must be having a prototype with no arguments

Page 7: CS201 Collection of Old PApers

b) Write member functions to Overload the following Operators and Display the Results.

a) Write a parameterized constructor to initialize the data members. 2. width 1. height

Class Rectangle should have the following Private data members

Write a class Rectangle that performs the mathematical operations (Subtraction and Multiplication) on its height and width with the help of operator overloading.

Question No. 8 Marks : 15

o garbage values o 132 , 234 o The addresses of j and k o The addresses of q and r o The values of j and k

are executed, what will be displayed? cout<<*q<<' '<<*r; int* q, * r; k= 234; j = 123; int j,k; If the statements

Question No. 7 Marks : 02

Also write the getter and setter functions for the data members of this class

c) Write an other member function of this class named addToFile(), In this function write the values of the data members Account NO, Account Title and Balance in the file named Account.txt.

b) Write a member function of this class named deposit (), this function will calculate the current balance for the user's account. In deposit function user will be prompted to enter the amount to be deposited and displays the incremented balance.

a) Create the object of this class using parameterized constructor in order to initialize all the three data members i.e. Account NO. Account Title. Balance

iii. Balance ii. Account Title i. Account NO

Page 8: CS201 Collection of Old PApers

d) find the largest value in the array (use a loop) c) prompt the user for 8 integers and store those integers in the array b) initialize each element in the array to 0 a) declare a one-dimensional integer array with 8 elements Write the statements that will

Question No. 10 Marks : 07

o creates an object initialized with the same data as an existing object

o creates a new object that later may be assigned the data of an existing object

o takes an arbitrary number of arguments

takes no arguments oo copies the data of any two constructors in that class

A copy constructor

Question No. 9 Marks : 02

In main () create the objects of the class and assign values to their data members and then call the overloaded operators

ii. Check for zero values in multiplication. If any value is zero, displays a message" Height or width cannot be zero". And exit from the function.

i. Check for negative values in subtraction before and after the operation, change them into absolute values or negate them. (If width = -3 its absolute value is width=3.)

Implement the following checks in operator overloading functions: 2. * 1. –

Page 9: CS201 Collection of Old PApers

http://vujannat.ning.com BEST SITE TO HELP STUDENTS

FINALTERM EXAMINATION

SPRING 2006

CS201 - INTRODUCTION TO PROGRAMMING (Session - 3 )

Marks: 50

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Wednesday, August 23, 2006

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total

Marks

Question No: 1 ( Marks: 2 ) - Please choose one

Page 10: CS201 Collection of Old PApers

To access the 8th element of an int array named myArray of 15 elements, you would write ►

int[8]

int[7]

myArray[8]

myArray[7]

Question No: 2 ( Marks: 2 ) - Please choose one A friend function of a class has access ►

To all data member and functions of the class

Only to other friend functions of the class

Only to private data of the class

Only to public data of the class

Question No: 3 ( Marks: 2 ) - Please choose one A copy constructor is always called when ►

an object is initialized with another object data of the same class when it’s created

an object is initialized with another object of any class when it’s created

an object is initialized with a variable of a basic type when it’s created

an object is not initialized when it’s created

Question No: 4 ( Marks: 2 ) - Please choose one Consider the function below: template <class T> T abc (U x) { return (-x); } We call this function as cout << abc(-9.6) << endl; The answer will be: ► 9.6

Page 11: CS201 Collection of Old PApers

-9.6

9

-9

Question No: 5 ( Marks: 6 ) Calculate the following bitwise operations.

a) 01001000 & 10111000 =

b) 01001000 | 10111000 =

c) 01110010 ^ 10101010 =

Question No: 6 ( Marks: 10 ) Write a program that will create a class stat. the class stat has the following data members. A float array values of size 10. The variables sum and avg both of type float. The class stat has the following member functions. takedata() calculate() show() The function takedata() is used to read data from the user through keyboard into the array values. The function calculate() is used to calculate the sum of all values in the array values and store the value in the variable sum. The function calculate(), then calculates the average by using the formula sum/10 and stores the result in the variable avg. The function show() is used to display the value in avg on the screen. The program will create an object obj1 in the class stat. The program will read data into obj1 using takedata(), calculate the average using the function calculate() and then display the result using show() function.

Question No: 7 ( Marks: 10 ) Write a program that will create a class rectangle. The class rectangle has the data members width and height, both of type float. The class rectangle has one member function getdata(). The program will create two objects rect1 and rect2 of the class rectangle. The program will read data into rect1 and rect2 trough the function getdata(). The program will compare both the objects by overloading “==” operator to decide that rect1 and rect2 are same or not. If rect1 and rect2 are same then program will display the message “Both rectangles are same” otherwise the program will display “Both rectangles are not same”. Note: rectangles are called same if their heights and widths are same.

Question No: 8 ( Marks: 8 )

Page 12: CS201 Collection of Old PApers

Write a program that will calculate the volume of a sphere using function templates. The function name is volumecal(). Two arguments (i.e. radius and a constant pi) are passed to the function volumecal(). After calculating the volume the, the function volumecal() display the result on the screen. The formula for volume of sphere is volume= (4/3) * pi * (radius)

3

Where pi= π=3.141569

Question No: 9 ( Marks: 8 ) We have two classes Class1 and Class2 and we want to construct two way friendships between them. Write the coding sketch to achieve this friendship.

Page 13: CS201 Collection of Old PApers

www.vujannat.ning.com

Write the function definitions for the following: Question No. 1 Marks : 10

**WARNING: Please note that Virtual University takes serious note of

unfair means. Anyone found involved in cheating will get an `F` grade in this course.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

d. All coding questions should be answered using the C ++ syntax.

c. Write all steps, missing steps may lead to deduction of marks.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

2. Do not ask any questions about the contents of this examination from anyone.

1. Attempt all questions. Marks are written adjacent to each question.

Please read the following instructions carefully before attempting any of the questions:

Time Allowed: 90 Minutes Mid Term Examination – Spring 2006

CS201 Introduction to Programming

Page 14: CS201 Collection of Old PApers

10 bytes 8 bytes 4 bytes 2 bytes

The size of a double variable is Question No. 5 Marks : 2

ch1 and ch2 are characters ch2 is string and ch1 is character ch1 is string and ch2 is character ch1 and ch2 are strings

ch2=’a’; ch1=”a”; Carefully analyze the following lines of code and chose the correct option. Question No. 4 Marks : 2

70 8 76 146

The value of 2*15/3*7+3*2 is Question No. 3 Marks : 2 The variable x is of type integer. for x=-5 to 4

– 3x 2 The series is created by the formula 2xHint: 65, 44, 27, 14, 5, 0, -1, 2, 9, 20. Write a program that will create and display the following series: Question No. 2 Marks : 6 Note: The function sum() returns no value.

b) A function sum() that would take the one integer array myArray[ ] of size 10 (as parameter), calculate the sum of the elements of myArray[ ] and display the result.

a) A function test() that would take three integer values x, y and z (as parameters), find the largest and return the result to the calling function.

Page 15: CS201 Collection of Old PApers

{ cout <<x << endl; x =x >> 1; } return 0; }

#include <iostream.h> int main() { unsigned short x = 1024; while(x>=1)

b) Program2

{ cout << x << endl; x = x << 1; } return 0; }

#include <iostream> int main() { unsigned short x = 1; for (int i = 0; i < 10; i++)

a) Program1

What will be the output of the following programs? Question No. 7 Marks : 10

constant pointer struct array declaration an array variable

An array is also called Question No. 6 Marks : 2

Page 16: CS201 Collection of Old PApers

3) ++x*4*++y 2) 3*++x+--y 1) ++x++*++y

x=3 and y=2 Calculate the following expressions for Question No. 8 Marks : 6

Page 17: CS201 Collection of Old PApers

WWW.vujannat.ning.comhttp://vujannat.ning.com

Largest Online Community of VU Students MIDTERM EXAMINATION

SPRING 2007

CS201 - INTRODUCTION TO PROGRAMMING (Session - 1 )

Marks: 50

Time: 90min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Saturday, May 12, 2007

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the Dev-C++/C ++ syntax.

e. Choose the most appropriate choice (among the given) while answering the MCQs.

You are not allowed to use any compiler or IDE. **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

Page 18: CS201 Collection of Old PApers

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 10 Total

Marks Question 11 12 13 14

Marks Question No: 1 ( Marks: 1 ) - Please choose one Analysis is the -------------- step in designing a program ►

Last

Middle

Post Design

First

Question No: 2 ( Marks: 1 ) - Please choose one The remainder (%) operator is, ►

An arithmetic operator

A logical operator

A relational operator

A division operator

Question No: 3 ( Marks: 1 ) - Please choose one When a call to function statement is encountered, ►

The control is transfer to its Prototype

The control is transfer to its definition

Page 19: CS201 Collection of Old PApers

The compiler stop execution of whole program

The program hangs

Question No: 4 ( Marks: 1 ) - Please choose one In C/C++ language when an array is passed to a function then by default its passing Mechanism is, ►

Call by value

It depends on type of array

Call by Reference

It depends on the return type of function.

Question No: 5 ( Marks: 1 ) - Please choose one Computer can do, ►

More than what we tell it

Less then what we tell it

Like human being

Exactly what we tell it

Question No: 6 ( Marks: 1 ) - Please choose one int x = 2 * 3 + 4 * 5; What value will x contain in the sample code above? ► 22

Page 20: CS201 Collection of Old PApers

26

46

50

Question No: 7 ( Marks: 1 ) - Please choose one In flow chart process is represented by ►

Rectangle

Arrow symbol

Oval

Circle

Question No: 8 ( Marks: 1 ) - Please choose one Which one of the following will declare a pointer to an integer at address 0x22ff74 in memory? ►

int *x; *x = 0x22ff74;

int *x = &0x22ff74;

int *x = *0x22ff74;

int *x( &0x22ff740 );

Question No: 9 ( Marks: 1 ) - Please choose one

Page 21: CS201 Collection of Old PApers

When we are using const keyword with a variable x then initializing it at the time of declaration is ►

Must

Optional

Not necessary

A syntax error

Question No: 10 ( Marks: 1 ) - Please choose one int numarray[4][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does numarray [0][3] in the sample code above contain? ►

3

5

7

4

Question No: 11 ( Marks: 5 ) Write Header files for the functions,

i. sqrt(); ii. getline(); iii. printf(); iv. exit(); v. rand();

Question No: 12 ( Marks: 5 ) Write down the output of the following code?

Page 22: CS201 Collection of Old PApers

int array[7], sum = 0; for(int i=0;i<7;i++) { array[i] = i; sum+= array[i]; } cout<< “ Sum = “ <<sum; Question No: 13 ( Marks: 15 ) Write a program which consists of three variables Area, Per, Base, this program should find and display the area of triangle using the formula, Area = (Base * Per)/2 ; Take the value of variables Per and Base from the user. Question No: 14 ( Marks: 15 ) Write a function BalerAvg which calculate and display the average of a player (Baler), call this function in main program (function). Take input of runs given and ball delivered from the user in main funciton. The average may be calculated by the formula, Average = (Total Runs given * 60) / (Total number of balls delivered);

Page 23: CS201 Collection of Old PApers

Connecting VU Students

FINALTERM EXAMINATION SPRING 2006

CS201 - INTRODUCTION TO PROGRAMMING (Session - 1 )

Marks: 50

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Wednesday, August 23, 2006

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total

Page 24: CS201 Collection of Old PApers

Connecting VU Students

Marks

Question No: 1 ( Marks: 2 ) - Please choose one A for loop usually consist of __________ expressions. ►

1

3

2

4

Question No: 2 ( Marks: 2 ) - Please choose one A preprocessor directive is identified by _________ symbol ►

#

{

(

~

Question No: 3 ( Marks: 2 ) - Please choose one Which of the following operators can not be overloaded? ►

new

delete

+=

sizeof

Question No: 4 ( Marks: 2 ) - Please choose one

Page 25: CS201 Collection of Old PApers

Connecting VU Students

Analyze the following code class myclass { private: float x,y; public: void myclass(float a, float b) { x=a; y=b; } void diplay() { cout<<endl<<x<<endl<<y; } }; What is wrong with the above code? ►

The member functions should be private

constructor must not have a return type

The constructor should have no body

There is no error in the given code

Question No: 5 ( Marks: 6 ) Analyze the following code and list all the errors and line numbers in the given code. int i=2; for(i<=100;i++) { if(i%2==0) { cout<<i; cout<<” is even /n’; } } Question No: 6 ( Marks: 7 ) Declare a class student having the following data members and member functions in the

Page 26: CS201 Collection of Old PApers

Connecting VU Students

class. stdno(integer) stdname(character array of size 20) phone(long integer) getdata() function that will read data into members data. Display() function that will display the data on the screen. Question No: 7 ( Marks: 6 ) a. Write the statement that will create an array of 10 objects of the class student and place the base address of the array in a pointer ptr of the class student given in Question No. 6.

b. Write the code of the parameterized constructor for the class student given in Question No. 6.

Question No: 8 ( Marks: 15 ) Write a program that will create a class distance. The class distance consist of two data members feet and inches, both of types float. The class distance consist of two member functions, getdata() and show(). The function getdata() is used to read data from the user through keyboard into feet and inches. The show() function is used to display the values of feet and inches on the screen.

The program will create two objects dest1 and dest2 of the class distance. The program will read data into dest1 and dest2 using getdata(). The program will create another object dest3 of the class distance by overloading the minus “-“operator trough expression dest3=dest1-dest2. The program will then display dist3 on the screen using show() function. The program also takes care of the fact that distance can not be negative. If dest2 is larger then dest1 then dest3 should not be created and program should display the message “Distance can not be negative”. Question No: 9 ( Marks: 8 ) What are the benefits of the templates?

Page 27: CS201 Collection of Old PApers

Connecting VU Students

1

FINALTERM EXAMINATION SPRING 2006

CS201 - INTRODUCTION TO PROGRAMMING (Session - 2 )

Marks: 50

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Wednesday, August 23, 2006

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total

Page 28: CS201 Collection of Old PApers

Connecting VU Students

2

Marks

Question No: 1 ( Marks: 2 ) - Please choose one . A function that calls itself is known as ►

Iterative function

Inline function

Recursive function

main ()

Question No: 2 ( Marks: 2 ) - Please choose one The function call to a default constructor ►

looks like any function call, except there is no return value

never takes any arguments

creates but cannot initialize an object

is made automatically when an object is created

Question No: 3 ( Marks: 2 ) - Please choose one Static member functions ►

must be declared inside the class definition, but defined outside it

must be declared private

have multiple copies for the entire class

can access only static data

Question No: 4 ( Marks: 2 ) - Please choose one The reserved words public and private comes under the category

Page 29: CS201 Collection of Old PApers

Connecting VU Students

3

structures

strings

accessibility modifiers

types of functions

Question No: 5 ( Marks: 6 ) Write a program that will read any four digit number from the user through key board and stnumber into an Integer variable n. The program then calculates the sum of all the digits in tnumber n and display the result on the screen. Question No: 6 ( Marks: 10 ) Write a program that will create a class book. The class book has the following data members bookid( long integer) author( char array of size 20) yearpb( integer) The class book has a parameterized constructor and a member function show() that is used to display the data in a tabular form. The program creates three objects b1, b2 and b3 and assigned data trough the parameterized constructor. The program then display the using the show() function. Question No: 7 ( Marks: 8 ) Analyze the following code and list all the errors along the line numbers. class test { private: int a, b; public: test( int x, int y)a(x),b(y){}; void show() { cout<<endl<<a<<endl<<b; } test operator +(test t); } test operator+(test t) {

Page 30: CS201 Collection of Old PApers

Connecting VU Students 4

test temp; temp.x=a+a.t; temp.b=b+b.t return(temp); } Question No: 8 ( Marks: 10 ) Is it possible to define a two dimensional array of objects in a class? If yes justify your answer by giving an example program. If no then give reasons. Question No: 9 ( Marks: 8 ) Write a program that uses a function template divide(). The function divide() will take two values and return the reminder of these two values. Test the function with two integer values x=104 and y=49 and two float vales a=6.9 and b=2.7.