Docstoc

CS201

Document Sample
CS201 Powered By Docstoc
					            CS201 Solved Past Papers GURU            




                                 http://vusolutions.blogspot.com/ 
 
VUsolutions' Introduction:
We are pleased to inform you that "VUsolutions" is a PIONEER solution provider blog for VU
students, where u can find all type of study solutions i.e. current & Old Papers solutions,
Assignments solutions, Quizzes solutions, GDBs solutions, Final projects help, Internship Reports
and every type of study help. This blog also provide you "VU Toolbar", "Study Plan Tips",
"Handouts in PDF to download", "Old/Past SOLVED Papers", "Old/past SOLVED Assignments",
"Old/past SOLVED Quizzes" and "Islamic Downloads".

VUsolutions proudly introducing its own FREE VUsolutions TOOLBAR (visit our blog for setup of toolbar),
which help you & ALERT you promptly regarding every VU updates and also provide you SOLUTIONS of
past & CURRENT assignments/quizzes etc in a very fast & furious way on your PC's DESKTOP. It is highly
RECOMMENDED to you that you MUST install it on your PC (installation takes only 01 minute).

Toolbar contains:
1. VU Online Lectures                 2. SOLVED old/past papers/assignments/quizzes/gdbs/projects etc
3. VULMS login                        4. VU Gmail Login
5. Handouts of all subjects
6. Top Funny Site (SantaBanta, Punjabi Totay, Bankay Mian etc)
7. Top Video Site (YouTube, Metacafe, DailyMotion etc)
8. Social Network Logins (Facebook, Orkut, Twitter etc)
9. Send Greeting Cards                                       10. Top Email Login
11. Mobile Software Ringtones Wallpapers etc                 12. Cell Phone Companies Official site
13. Top Audio Song site                                      14. Watch Online TV Channels
15. Read NEWSPAPERS online                                   16. Free Software Download
17. Free Files Upload
18. Official Sites of Fast Food chains, Courier Services, Airlines, Railway, Bus Service etc
19. Pay VU Fee
and many more...

VUsolutions' more than 3000 documents are available on DocStoc which all are very useful for your
study/exams point of view. Visit our VUsolutions website for details.

If you don't have time for your assignments/quizzes/projects due to any unavoidable
circumstances/reasons, DONT WORRY, you just visit our blog (VUsolutions) on daily basis, we provide you
solutions of your on-going/current assignments/quizzes. If you dont have to visit this blog daily, you may
send us your cell number on "virtual.uni.help.updater@gmail.com", we will update you on your cell
numbers through text (SMS).

VUsolutions also want to thanks to all VU old students, those make VUsolutions a famous blog among
all. We feel proud whenever we see thousands of appreciating emails from old students and we
believe that its reward of our sincerity and continuous struggle to help you in every study matter
and it is also OUR MISSION to serve you with the UNIQUE, EASY and BEST way.  
  
Best of LUCK 
  
VUsolutions HelpDesk.. 
virtual.uni.help@gmail.com 
http://VUsolutions.blogspot.com/ 
                              


                                   virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU               




                                 http://vusolutions.blogspot.com/ 
 
Our Other Blogs/websites 
  
 VU study/Help related:‐ 
VUsolutions (Every VU related solution)                     http://VUsolutions.blogspot.com/  
Online VU Lectures (Videos)                                 http://onlineVUlectures.blogspot.com/  
VU SOLVED past Papers/Quizzes/Assignments/Final Projects    http://vusolutionsPapers.blogspot.com/  
VUsolutions GURU                                            http://vusolutionsGuru.blogspot.com/  
  
Interesting Site:‐ 
 


Islamic & History Movies (Prophets & Heroes):  http://www.islamic-prophet-movies.blogspot.com/
Naat & Songs of Hina Nasrullah:                  http://hinaNasrullah-naat-songs-tv-videos.blogspot.com/ 
Diamond Engagement Rings, Jewelry Designs:   http://diamonds-jewelry-engagement-rings.blogspot.com/
Birthday Cakes, Dresses, Wishes & Party Ideas   http://BirthdaysWishes.blogspot.com/ 
Mehndi Designs & Wedding related stuff:          http://MehndiWorld.blogspot.com/ 
Natural Home Remedies, Health Tips, Health Care  http://natural-home-remedies-healthy-foods.blogspot.com/  
Learn/Watch Famous Food Recipes:                 http://online‐food‐recipes.blogspot.com/ 
Political Talk Sows:                             http://awaztv.blogspot.com/  
Paksitani WikiLeaks:                             http://paki‐wiki‐leaks.blogspot.com/  
Fashion Central, Current Fashions:               http://only4shefashion.blogspot.com/  
Good Morning Shows:                              http://masala‐morningshow.blogspot.com/  
All Famous TV Dramas:                            http://pak‐topdramas.blogspot.com/  
Watch & Learn Magic Tricks:                      http://biggest‐magic‐tricks.blogspot.com/  
Latest Innovation & latest NEWS of the world:   http://its‐latest.blogspot.com/  
Text SMS funny friendship sad love Joke etc    http://sms‐world.blogspot.com/  
  
Funny Videos:‐ 
Santa Banta (Funny Sardar Jokes Videos)      http://santabanta‐videos.blogspot.com/  
Bankay Mian Ki Qawali (All Videos)           http://bankay‐mian‐ki‐qawali.blogspot.com/  
Funny Punjabi Tootay                         http://funny‐punjabi‐totay.blogspot.com/  
Geo KhabarNak Funny show with Aftab Iqbal    http://khabarnakwithaftabiqbal.blogspot.com/  
Dar & Darling Funny Show                     http://daranddarling.blogspot.com/  
Hum Sab Umeed Say Hain (Geo TV show) http://hum‐sab‐umeed‐say‐hain‐geotv.blogspot.com/  
Aaj ka Cartoon Funny:                        http://aajcartoon.blogspot.com/  
Alif Noon Dunya TV (Funny Videos)            http://alif‐noon‐dunya‐tv.blogspot.com/  
Bulbulay (Funny Drama) ARY TV                http://bulbulay‐ary‐tv.blogspot.com/  
Geo Cartoon (Funny Geo TV)                   http://geo‐cartoon.blogspot.com/  
“Naram Garam” Popular Funny Game show   http://naramgaram‐samaa‐tv.blogspot.com/  


                                    virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
CS201 - Introduction to programming
Final Term Spring 2010

Operator overloading can be performed through__________________.
 ► Classes
   ► Functions
 ► Operators
 ► Reference

Question No: 2      ( Marks: 1 ) - Please choose one
When a value is referred by a normal variable then it is known as,
   ► Direct Reference
     ► Indirect Reference
   ► Partial Reference
   ► Proper Reference
When a value is referred by a normal variable is known as direct reference

Question No: 3     ( Marks: 1 ) - Please choose one
Which of the following function is used to increase the size of already allocated
memory chunk?

    ► malloc
      ► calloc
        ► realloc
        ► free

Question No: 4       ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
    ► #error
    ► #define
    ► #line

     ► #ndefine

list of preprocessors
• #include • #include “filename” • #define • #undef • #ifdef • #ifndef • #if • #else •
#elif    •    #endif     •    #error    •    #line   •     #pragma       •     #assert


Question No: 5      ( Marks: 1 ) - Please choose one
The stream objects cin and cout are included in which header file?
      ► iostream.h
    ► fstream.h
    ► istream.h
                                                                         ► ostream.h

Question No: 6      ( Marks: 1 ) - Please choose one
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
Overloaded delete operator function takes the same parameter as an argument
returned by new operator function.
     ► True
     ► False
 The same pointer that is returned by the new operator, is passed as an argument to
the delete operator. These rules apply to both, if operators (new and delete) are
overloaded as member or non-member operators (as global operators).

Question No: 7     ( Marks: 1 ) - Please choose one
When an array of object is created dynamically then there is no way to provide
parameterized constructors for array of objects.
     ► True

     ► False
if we are allocating an array of objects, there is no way to pass arguments to objects’
constructors. Therefore it is required that the objects that are stored in such an array
have                    a                    no-argument                     constructor.


Question No: 8      ( Marks: 1 ) - Please choose one
C is widely known as development language of _______ operating system.
     ► Linux
     ► Windows
      ► Unix
  ► Mac OS
In the start C became widely known as the development language of the UNIX
operating system, and the UNIX operating system was written by using this C
language. The C language is so powerful that the compiler of C and other various
operating           systems           are         written          in         C.

Question No: 9    ( Marks: 1 ) - Please choose one
Computer can understand only machine language code.
    ► True

    ► False
Question No: 10       ( Marks: 1 ) - Please choose one
We can not define a function as a friend of a Template class.
    ► True
     ► False

Class templates can have friends. A class or class template, function, or function
template can be a friend to a template class. Friends can also be specializations of a
class   template   or   function   template,     but   not   partial  specializations.

Question No: 11 ( Marks: 1 ) - Please choose one
What will be the value of ‘a’ and ‘b’ after executing the following
statements?
a = 3;
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
b = a++;
    ► 3, 4
    ► 4, 4
    ► 3, 3
    ► 4, 3

Question No: 12        ( Marks: 1 ) - Please choose one
Consider the following code segment. What will be the output of following code?
int addValue (int *a){
int b = (*a) + 2;
return b ;
}
main () {
int x =6 ;
cout << x << “,” ;
cout << addValue(&x) << “,” ;
cout << x ;
}
     ► 6,8,6

    ► 6,6,8
    ► 6,8,8
    ► 6,6,6

Question No: 13      ( Marks: 1 ) - Please choose one
_______ is used to trace the logic of the program and correct the logical errors.
   ► Compiler
   ► Editor
   ► Linker
   ► Debugger

Question No: 14      ( Marks: 1 ) - Please choose one
new and delete are _____ whereas malloc and free are _____.
    ► Functions, operators
    ► Classes, operators
    ► Operators, functions
    ► Operators, classes
Hence,       we        can       call new and delete operators, P#  342
we have allocated a memory space for our use by malloc function. P# 285

Question No: 15      ( Marks: 1 ) - Please choose one
Like member functions, ______ can also access the private data members of a class.
     ► Non-member functions
     ► Friend functions
     ► Any function outside class
     ► None of the given options

Question No: 16       ( Marks: 1 ) - Please choose one
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Which situation would require the use of a non-member overloaded operator?
    ► The overloaded operator is an Assignment operator.
    ► The left most operand is an object of a class.
    ► The left operand is built-in data type.
    ► The operator returns a reference.

When an operator function is implemented as a non-member function, the left-most
operand may be an object of the operator’s class, an object of a different class, or a
built-in type

Question No: 17     ( Marks: 1 ) - Please choose one
The stream insertion and stream extraction operators are already overloaded for
______.
    ► User-defined data types
    ► Built-in data types
    ► User-defined and built-in data types
    ► None of the given options

Question No: 18        ( Marks: 1 ) - Please choose one
If we define an identifier with the statement #define PI 3.1415926 then during the
execution of the program the value of PI __________.
     ► can not be replaced
     ► None of the given options
     ► Remain constant.
     ► can be changed by some operation

Question No: 19       ( Marks: 1 ) - Please choose one
Assignment operator is -------------------------associative.
      ► right
      ► left
      ► binary
      ► unary
You can assign values to several variables in a single statement. For example, the
following code sets the contents of apples and oranges to the same value:
apples = oranges = 10;
The assignment operator is right associative, so this statement executes by first
storing the value 10 in oranges and then storing the value in oranges in apples, so it
is effectively
apples = (oranges = 10);

Question No: 20      ( Marks: 1 ) - Please choose one
When ever dynamic memory allocation is made in C/C++, it is freed_____________.
   ► Explicitly
   ► Implicitly
   ► Both explicitly and implicitly
   ► None of the given options

Question No: 21      ( Marks: 1 ) - Please choose one
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU       




                         http://vusolutions.blogspot.com/ 
 
The appropriate data type to store the number of rows and colums of the matrix
is____________.
    ► float
    ► int
    ► char
              ► none            of         the          given          options.


Question No: 22       ( Marks: 1 ) - Please choose one
Which of the following function do NOT initialize the chunk of memory to all zero?
    ► calloc() function
    ► Both malloc() and calloc()
    ► None of the above
    ► malloc() function

The malloc function differs from calloc in the way that the space allocated
by malloc is not initialized and contains any values initially.
Question No: 23        ( Marks: 1 ) - Please choose one
The function free() returns back the allocated memory got thorough calloc and malloc
to _____ .
     ► stack
     ► heap
     ► stack and heap
     ► None of the given options

Question No: 24     ( Marks: 1 ) - Please choose one
width() is member function of _____________
    ► cin object
    ► cout object
    ► Both cin and cout object
    ► None of the given option


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

Templates are not type safe.
   ► true
   ► false

Templates are type-safe. This is because the types that templates act upon are
known at compile time, so the compiler can perform type checking before errors
occur.

Question No: 26      ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to
handle this , _______________
    ► Write a separate class to handle each
    ► Use templates
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
     ► Use strings to store all types
     ► None of the given options
A Matrix can be composed of ints, floats or doubles as their elements. Instead of
handling these data types separately, we can write Matrix class as a template class
and write code once for all native data types. While writing this template class, the
better approach to write will be, to go with a simple data type (e.g.double) first to
write a Matrix class and then extend it to a template class later.


Question No: 27        ( Marks: 2 )
Give the general syntax of class template.
template
class myclass { ---} ;

Question No: 28       ( Marks: 2 )
What is a truth Table?
There are some areas where the decision structures become very complicated.
Sometimes, we find it difficult to evaluate a complicated logical expression.
Sometimes the logic becomes extremely complicated so that even writing it as a
simple syntax statement in any language. It becomes complicated to determine what
will be evaluated in what way. We know the concept of truth table. The truth tables
are very important. These are still a tool available for analyzing logical expressions.
We will read logic design in future, which is actually to do with chips and gates. How
we put these things together.

Question No: 29       ( Marks: 2 )
What will be the output of following code, if user input a number 123?
int input ;
cin >> oct >> input;
cout << hex << input ;

53
Rational: it will take 123 as octal and print it in hex form which is 53.

Question No: 30           ( Marks: 2 )
What is principle of friendship in the context of functions and classes?
Class can declare a friend function and someone from outside the class cannot declare
itself friend of a class.
A friend function can access the private variables of class just like a member function

Question No: 31         ( Marks: 3 )
What are the limitations of the friendship relation between classes?
Class can declare a friend class from inside and someone from outside the class
cannot declare itself friend of a class.

Question No: 32        ( Marks: 3 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first? a
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU        




                           http://vusolutions.blogspot.com/ 
 
(ii) The destructor of which class will be called first?b

Question No: 33        ( Marks: 3 )
Define static variable. Also explain life time of static variable?
When you declare a static variable (native data type or object) inside a function, it is
created and initialized only once during the lifetime of the program

Question No: 34        ( Marks: 5 )
 Write a program which defines three variables of type double which store three
different values including decimal points, using setprecision manipulators to print all
these values with different number of digits after the decimal number.
#include
#include
main () {
double a = 12.12345;
double b = 13.123456;
double c = 14.1234567;
cout << setprecision (5) << a << endl;
cout << setprecision (2) << a << endl;
cout << setprecision (3) << a << endl;
}
Question No: 35        ( Marks: 5 )
Let we have a class,
class String
{
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String object to
other object. Your code should also avoid self assignment

Answer:
void String::operator = ( const String &other )
 { int length ;
 length = other.length();
delete buf;
 buf = new char [length + 1];
 strcpy( buf, other.buf ); }

Question No: 36         ( Marks: 5 )
Read the given below code and explain what task is being performed by this function
Matrix :: Matrix ( int row , int col )
{
  numRows = row ;
  numCols = col ;
  elements = new ( double * ) [ numRows ] ;
  for ( int i = 0 ; i < numRows ; i ++ )
{
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
     elements [ i ] = new double [ numCols ] ;
     for ( int j = 0 ; j < numCols ; j ++ )
            elements [ i ] [ j ] = 0.0 ;
   }
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols




                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

Marks: 58

Question No: 1        ( Marks: 1 ) - Please choose one
In if structure the block of statements is executed only,
      ► When the condition is false
      ► When it contain arithmetic operators
      ► When it contain logical operators
      ► When the condition is true

Question No: 2      ( Marks: 1 ) - Please choose one
Header file: fstream.h includes the definition of the stream classes __________.
    ► ifstream, fstream, cout
    ► ifstream, fstream, ofstream
    ► fstream, cin, cout
    ► None of the above

Question No: 3      ( Marks: 1 ) - Please choose one
To access the data members of structure _______ is used.
    ► dot operator (.)
    ► * operator
    ► operatorà
    ► None of given.

Question No: 4       ( Marks: 1 ) - Please choose one
eof( ), bad( ), good( ), clear( ) all are manipulators.
     ► True
     ► False

Question No: 5       ( Marks: 1 ) - Please choose one
Which kind of functions can access private member variables of a class?
    ► Friend functions of the class
    ► Private member functions of the class
    ► Public member functions of the class
    ► Friend, private and public functions

Question No: 6      ( Marks: 1 ) - Please choose one
The return type of operator function must always be void.
    ► True
    ► False

Question No: 7       ( Marks: 1 ) - Please choose one
Friend function of a class is ______________ .
     ► Member function
     ► Non-member function
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
    ► Private function
    ► Public function

Question No: 8     ( Marks: 1 ) - Please choose one
Function implementation of friend function must be defined outside the class.
    ► True
    ► False (any where in the class)

Question No: 9     ( Marks: 1 ) - Please choose one
The normal source of cin object is,
    ► File
    ► Disk
    ► Keyboard
    ► RAM

Question No: 10       ( Marks: 1 ) - Please choose one
Which of the following is correct way to initialize a variable x of int type with value
10?
    ► int x ; x = 10;
    ► int x = 10;
    ► int x, x = 10;
    ► x = 10;

Question No: 11      ( Marks: 1 ) - Please choose one
Consider the following code segment. What will be the output of the following
program?
int func(int) ;
int num = 10 ;
int main(){
int num ;
num = 5 ;
cout << num ;
cout << func(num) ;
}
int func(int x){
return num ;
}
      ► 5, 5
      ► 10, 5
      ► 5, 10
      ► 10, 10

Question No: 12     ( Marks: 1 ) - Please choose one
With template function, the compiler automatically detects the passed data and
generates a new copy of function using passed data.
    ► True
    ► False

                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
Question No: 13       ( Marks: 1 ) - Please choose one
What will be the correct syntax to declare two-dimensional array of float data type?
   ► float arr{2}{2} ;
   ► float arr[2][2] ;
   ► float arr[2,2] ;
   ► float[2][2] arr ;

Question No: 14       ( Marks: 1 ) - Please choose one
The first parameter of operator function for << operator,
     ► Must be passed by value
     ► Must be passed by reference
     ► Can be passed by value or reference
     ► Must be object of class
Question No: 15       ( Marks: 1 ) - Please choose one
Heap is constantly changing in size.
     ► True
     ► False

Question No: 16        ( Marks: 1 ) - Please choose one
While calling function, the arguments are assigned to the parameters from
    ► left to right.
    ► right to left
    ► no specific order is followed
    ► none of the given options.

Question No: 17       ( Marks: 1 ) - Please choose one
Classes defined inside other classes are called ________ classes
     ► looped
     ► nested
     ► overloaded
     ► none of the given options.

Question No: 18        ( Marks: 1 ) - Please choose one
If we define an identifier with the statement #define PI 3.1415926 then during the
execution of the program the value of PI __________
     ► can not be replace
     ► None of the given options
     ► Remain constant.
     ► can be changed by some operation
Question No: 19        ( Marks: 1 ) - Please choose one
Which value is returned by the destructor of a class?
     ► A pointer to the class.
     ► An object of the class.
     ► A status code determining whether the class was destructed correctl
     ► Destructors do not return a value.
Question No: 20        ( Marks: 1 ) - Please choose one
Every class contains _______________.
     ► Constructor
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
    ► Destructor
    ► Both a constructor and a destructor
    ► None of the given options
Question No: 21      ( Marks: 1 ) - Please choose one
A template function must have
    ► One or more than one arguments
    ► Only one argument
    ► Zero argument
    ► None of the given options

Question No: 22           ( Marks: 1 ) - Please choose one
Structured Query Language is used for ______________
     ► Databases Management
     ► Networks
     ► Writing Operating System
     ► none of the given options
Question No: 23           ( Marks: 1 ) - Please choose one
When a call to a user-defined function finishes, the variable defined inside the
function is still in existence.
     ► True
     ► False
Question No: 24           ( Marks: 1 ) - Please choose one
The precedence of an operator can be changed through operator overloading.
     ► True
     ► False
Question No: 25           ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to
handle this , _______________
     ► Write a separate class to handle each
     ► Use templates
     ► Use strings to store all types
     ► None of the given options
A Matrix can be composed of ints, floats or doubles as their elements. Instead of
handling these data types separately, we can write Matrix class as a template class
and write code once for all native data types.
Write Matrix class as a template class and write code once for all native data types
Question No: 26           ( Marks: 1 ) - Please choose one
"delete" operator is used to return memory to free store, which is allocated by the
"new" operator.
     ► True
     ► False
Question No: 27           ( Marks: 2 )
What is the difference between switch statement and if statement.
Question No: 28           ( Marks: 2 )
How can we initialize data members of contained object at construction time?
Question No: 29           ( Marks: 2 )
How the data members of a class are initialized with meaningful values?
Question No: 30           ( Marks: 2 )
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Can we overload new and delete operators?
Question No: 31         ( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32         ( Marks: 3 )
 What is the keyword ‘this’ and what are the uses of ‘this’ pointer?
Question No: 33         ( Marks: 3 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first?
(ii) The destructor of which class will be called first?
Question No: 34         ( Marks: 5 )
Write the general syntax of a class that has one function as a friend of a class along
with definition of friend function.
Question No: 35         ( Marks: 5 )
Write down the disadvantages of the templates.
Question No: 36         ( Marks: 5 )
Write a program which defines five variables which store the salaries of five
employees, using setw and setfill manipulators to display all these salaries in a
column.
Note: Display all data with in a particular width and the empty space should be filled
with character x
Output should be displayed as given below:
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000




                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2010
CS101- Introduction to Computing (Session - 4)

Time: 60 min
Marks: 38

Question No: 1 ( Marks: 1 ) - Please choose one
JavaScript does not support_______________
    ► User interaction
    ► Graphics
    ► Network operations
    ► Both Graphics and Network operations

Question No: 2 ( Marks: 1 ) - Please choose one
_________ language is very good for writing well-structured and readable programs,
but it is not as flexible as the C programming language

    ► BASIC
    ► PASCAL
    ► JAVA
    ► FORTRAN
Question No: 3 ( Marks: 1 ) - Please choose one
__________ is the example of Shrink-wrapped software

      ► PIA information system
      ► WinZip trial pack
      ► Linux
      ► MS Word
Question No: 4 ( Marks: 1 ) - Please choose one
___________ refers to the firmware code which is run by an IBM compatible PC when
first powered on.
      ► DOS
      ► BIOS
      ► Utility Program
      ► None of these

Question No: 5 ( Marks: 1 ) - Please choose one
RTOS stands for____________________

    ►   Real Task Operating System
    ►   Random Time Operating System
    ►   Rational Time Operating System
    ►   Real Time Operating System

Question No: 6 ( Marks: 1 ) - Please choose one
------------- is an electronic path within a Computer System along which bits are
transmitted.
                           virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 

    ►   Port
    ►   Slots
    ►   Bus
    ►   Modem

Question No: 7 ( Marks: 1 ) - Please choose one
A microprocessor can be made more powerful by increasing its ________

    ►   Clock frequency
    ►   Word length
    ►   Clock frequency and Word length
    ►   None of above

Question No: 8 ( Marks: 1 ) - Please choose one
Which one of these translates the program once at a time ?
    ► Interpreter
    ► Compiler
    ► Operating system
    ► Translator

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

RAM ►
ROM ►
Hard Disk ►
CD ROM ►

Question No: 10 ( Marks: 1 ) - Please choose one
A British scientist named John A. Fleming made a vacuum tube known today as a
diode. Then the diode was known as a "valve," Is it true?

σεΨ ►       True
οΝ ►      False

Question No: 11 ( Marks: 1 ) - Please choose one
<form> Tags always placed between the <BODY> and </BODY> tags of a Web page
►     True
False ►

Question No: 12 ( Marks: 1 ) - Please choose one
_____________ is generally measured in terms of the number of steps required to
execute an algorithm.

    ► Space
    ► Time
    ► Memory and time
                            virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU   




                         http://vusolutions.blogspot.com/ 
 
        ► Bandwidth

Question No: 13 ( Marks: 1 ) - Please choose one
Programs where no user interaction found during program execution are called
__________.

Batch programs ►
Event-driven programs ►
Graphics based programs ►
 None of the given ►

Question No: 14 ( Marks: 1 ) - Please choose one
For connector the following symbol is used:
Square ►
Rectangle ►
Diamond ►
Circle ►

Question No: 15 ( Marks: 1 ) - Please choose one
After starting computer, which module of operating system activates first?

►    Linker
Kernel ►
 Loader ►
Device manager ►

Question No: 16 ( Marks: 1 ) - Please choose one
"Every minute dies a man, And one and a sixteenth is born" said by?

    ►   Alfred, Lord Tennyson
    ►   Charles Babbage
    ►   Ada, Countess of Lovelace
    ►   Babbage and Lord Tennyson

Question No: 17 ( Marks: 2 )
Why JavaScript is called Object-based language, why not Object-Oriented ?

JavaScript is not a true object-oriented language like C++ or Java

It is so because it lacks two key features:
– A formal inheritance mechanism
– Strong typing
Nevertheless, JavaScript shares many similarities with object-oriented
languages, and therefore is called an object-based language
 Everything that JavaScript manipulates, it treats as an object – e.g. a window or a
button
An object has properties – e.g. a window has size, position, status, etc.

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU    




                          http://vusolutions.blogspot.com/ 
 
Properties are modified with methods – e.g. a resize a window with resizeTo(150,
200)

Question No: 18 ( Marks: 2 )
Draw flow chart symbols for "process" and "off page connector" ?

Process

Off Page Connector

Question No: 19 ( Marks: 2 )
How can you open a link in a new browser window?
We can open by using these two commands:

<A Href = "URL">
document.write (title.link("URL"));

Question No: 20 ( Marks: 3 )
List down the names of any three parameters on which we analyze an algorithm.

Question No: 21 ( Marks: 3 )
What is the difference between user requirements and development specification.

Question No: 22 ( Marks: 5 )
Which two phases of the SW lifecycle do you think are the most important and effort
consuming steps? Explain with reasons.
concept and decommissioning
Concept ka reason yeh key it gives the first idea about WHAT is required
and    decommissioning     ensures     that     WHAT     is   required   has been
achieved

Question No: 23 ( Marks: 5 )
Write down the algorithm for converting decimal number to binary?




                             virtual.uni.help@gmail.com 
              CS201 Solved Past Papers GURU      




                              http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Fall 2008

CS201- Introduction to Programming (Session - 2)
Time: 60 min
Marks: 38

Question No: 1 ( Marks: 1 ) - Please choose one
What is the output of the following statement?

    int i = 2.5; do { cout i * 2; } while (i > 3 && i < 10);

        ►   510
        ►   5
        ►   48
        ►   error

Question No: 2 ( Marks: 1 ) - Please choose one
What does !(7) evaluate to in decimal where ! is a NOT operator?

        ►   7
        ►   8
        ►   9
        ►   10

Question No: 3 ( Marks: 1 ) - Please choose one
 The condition in while loop may contain logical expression but not relational
expression.

        ► True
        ► False

Question No: 4 ( Marks: 1 ) - Please choose one
 Searching is easier when an array is already sorted
     ευρΤ    ►
εσλαΦ     ►

Question No: 5 ( Marks: 1 ) - Please choose one
If an array has 100 elements, what is allowable range of subscripts?


        ►0 - 99
        ► 1 - 99
        ► 0 - 100
        ► 1 - 100

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

                                 virtual.uni.help@gmail.com 
             CS201 Solved Past Papers GURU   




                          http://vusolutions.blogspot.com/ 
 
 What will be the value of ‘a’ and ‘b’ after executing the following
statements?
a = 3;
b = a++;

    ►   3,   4
    ►   4,   4
    ►   3,   3
    ►   4,   3

Question No: 7 ( Marks: 1 ) - Please choose one
 What will be the correct syntax to initialize all elements of two-dimensional array to
value 0?


    ► int arr[2][3] = {0,0} ;

    ► int arr[2][3] = {{0},{0}} ;

    ► int arr[2][3] = {0},{0} ;

    ► int arr[2][3] = {0} ;

Question No: 8 ( Marks: 1 ) - Please choose one
Which of the following functionreturns the size of a string variable?

    ►strlength()

    ►stringlen()

    ►strlen()

    ►strLength()

Question No: 9 ( Marks: 1 ) - Please choose one
What will be the range of numbers generated by function rand () % 9?

     ► 0 to 9

     ►1 to 9

     ►0 to 8

     ►1 to 8

Question No: 10 ( Marks: 1 ) - Please choose one
 ?3∗3/72+6 νοισσερπξε χιτεμητιρα φο τλυσερ εητ εβ λλιω ταηΩ
33 ►
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
54 ►
9►
03 ►

Question No: 11 ( Marks: 1 ) - Please choose one
Computer can understand only machine language code.
   ► ευρΤ
   ► εσλαΦ

Question No: 12 ( Marks: 1 ) - Please choose one
 .μετσψσ γνιταρεπο _______ φο εγαυγναλ τνεμπολεϖεδ σα νωονκ ψλεδιω σι Χ
ξυνιΛ ►
σωοδνιΩ ►
ξινΥ ►
ΣΟ χαΜ ►

Question No: 13 ( Marks: 1 ) - Please choose one
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?

1►
2►
3►
4►

Question No: 14 ( Marks: 1 ) - Please choose one
If the file is not properly closed in the program, the program ____________.

►Terminate normally
►Indicate Runtime error
►Indicate Compile time error
►Crashes

Question No: 15 ( Marks: 1 ) - Please choose one
Which of the following header file include string conversion functions?

►string.h
►stdlib.h
►ctype.h
►sconvert.h

Question No: 16 ( Marks: 1 ) - Please choose one
 In Program commenting the code liberally is
λυφεσΥ ►
γνιμυσνοχ εμιΤ ►
ψρασσεχεν τοΝ ►
 τσυΜ ►

Question No: 17      ( Marks: 1 )
                              virtual.uni.help@gmail.com 
             CS201 Solved Past Papers GURU     




                             http://vusolutions.blogspot.com/ 
 
    Which header file must be included while handling files?

Question No: 18 ( Marks: 1 )
What is meant by C++ statement:         const int *ptr = &x;

Question No: 19 ( Marks: 2 )
What is a truth Table?

Question No: 20 ( Marks: 3 )
 (i) An array day is declared as: int day[] = {1, 2, 3, 4, 5, 6, 7};
How many elements does array 'day' has?
(ii) If the declaration is changed as: int day[7] = {1, 2, 3, 4, 5, 6, 7};
How many elements does array 'day' has?

Question No: 21 ( Marks: 5 )
 What are similarities and differences between Structures and Unions?

Question No: 22 ( Marks: 10 )
 Write a void function( ); that takes integer numbers from the user and then
displays the sum of odd and even numbers entered by the user. Your program should
terminate if user enters a negative number




                                virtual.uni.help@gmail.com 
                 CS201 Solved Past Papers GURU 
                                           




                         http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming (Session - 1)

Question No: 1 ( Marks: 1 ) - Please choose one
To access the data members of structure _______ is used.
    ► dot operator (.)
    ► * operator
    ► à operator
    ► None of given.

Question No: 2 ( Marks: 1 ) - Please choose one
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?

         ►   1
         ►   2
         ►   3
         ►   4

Question No: 3 ( Marks: 1 ) - Please choose one
 If constructor contains a return statement in its body then compiler will give
__________
     ► No error
     ► Syntax error
     ► Logical error
     ► Run time error

Question No: 4 ( Marks: 1 ) - Please choose one
 We can use New keyword inside of Class Constructor.

         ► True
        ►False

Question No: 5 ( Marks: 1 ) - Please choose one
 When an operator function is define as member function for a Unary operator then
the number of argument it take is/are,

    ►     Zero
    ►     One
    ►     Two
    ►     N arguments



The declarator of Plus (+) member operator function is




                            virtual.uni.help@gmail.com 
             CS201 Solved Past Papers GURU        




                             http://vusolutions.blogspot.com/ 
 
►        Class-Name operator + (Class-Name rhs)

    ►    operator Class-Name + ( )

    ►    operator Class-Name + ( rhs)

    ►    Class-Name operator + ( )

Question No: 7 ( Marks: 1 ) - Please choose one
Friend function of a class is ______________ .


    ►    Member function

    ►    Non-member function

    ►    Private function

    ►    Public function

Question No: 8 ( Marks: 1 ) - Please choose one
We can also create an array of user define data type.

    ►    True
        ►False

Question No: 9 ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when deallocating memory using delete operator?
►   Only block of memory is deallocated for objects

    ►    Only destructor is called for objects

    ►    Memory is deallocated first before calling destructor

    ►    Destructor is called first before deallocating memory

Question No: 10 ( Marks: 1 ) - Please choose one
Deleting an array of objects without specifying [] brackets may lead to memory leak
►    True
  ►False

Question No: 11 ( Marks: 1 ) - Please choose one
Which of the following data type(s) can operate on modulus operator ‘%’?
   ► float, int
   ► float, double
   ► int
   ► char

                                virtual.uni.help@gmail.com 
             CS201 Solved Past Papers GURU   




                            http://vusolutions.blogspot.com/ 
 
Question No: 12 ( Marks: 1 ) - Please choose one
Array is passed by value to a function by default.
   ►True
►   False

Question No: 13 ( Marks: 1 ) - Please choose one
 With template function, the compiler automatically detects the passed data and
generates a new copy of function using passed data.

        ►True
►        False

Question No: 14 ( Marks: 1 ) - Please choose one
 What will be the correct syntax to initialize all elements of two-dimensional array to
value 0?

►        int arr[2][3] = {0,0} ;
►        int arr[2][3] = {{0},{0}} ;
►        int arr[2][3] = {0},{0} ;
►        int arr[2][3] = {0} ;

Question No: 15 ( Marks: 1 ) - Please choose one
 When an operator function is define as member function then operand on the left
side of operator must be an object.
    ►True
►     False

Question No: 16 ( Marks: 1 ) - Please choose one
break statement can be used outside a loop or switch statement.

        ►True
►        False

Question No: 17 ( Marks: 1 ) - Please choose one
The keyword_______ is used to return some value from a function.

    ►    return
    ►    break
    ►    continue
    ►    goto

Question No: 18 ( Marks: 1 ) - Please choose one
 Every data member or function inside the structure is ___ by default whereas
everything declared inside a class is ____ by default.

    ►  private, public
      ►public, private
    ►  private, protected
                               virtual.uni.help@gmail.com 
              CS201 Solved Past Papers GURU     




                             http://vusolutions.blogspot.com/ 
 
    ►    public, protected

Question No: 19 ( Marks: 1 ) - Please choose one
Which of the following is true for the C++ statement given below?
int &ref = val ;

    ►    It creates a synonym for variable ‘val’
    ►    It creates an alias for variable ‘val’
    ►    It’s a new name for variable ‘val’
        ►All of the given options

Question No: 20 ( Marks: 1 ) - Please choose one
 If overloaded plus operator is implemented as non-member function then which of
the following statement will be true for the statement given below?
obj3 = obj1 + obj2 ;

►    obj2 will be passed as an argument to + operator whereas obj2 will drive the +
operator
►    obj1 will drive the + operator whereas obj2 will be passed as an argument to +
operator
►    Both objects (obj1, obj2) will be passed as arguments to the + operator
►    Any of the objects (obj1, obj2) can drive the + operator

Question No: 21 ( Marks: 1 ) - Please choose one
 Unary operator implemented as member function takes ____ arguments whereas
non-member function takes _____ arguments.

    ►  One, zero
      ►Zero, one
    ►  One, two
    ►  Two, one

Question No: 22 ( Marks: 1 ) - Please choose one
The input/output streams cin and cout are ________ therefore have _______.




        ►   Structures, function
        ►   Objects, member functions
        ►   Functions, objects
        ►   None of the given options

Question No: 23 ( Marks: 1 ) - Please choose one
If a symbolic constant has been defined, it will be an error to define it again.
     ► True
     ► False
                                 virtual.uni.help@gmail.com 
              CS201 Solved Past Papers GURU  




                           http://vusolutions.blogspot.com/ 
 

Question No: 24 ( Marks: 1 ) - Please choose one
Every class contains _______________.
    ► Constructor
    ► Destructor
    ► Both a constructor and a destructor
    ► None of the given options

Question No: 25 ( Marks: 1 ) - Please choose one
new and delete keywords are _____________ in C++ language.

        ►   Built-in- Function
        ►   Operators
        ►   Memory Allocation Function
        ►   None of the given options

Question No: 26 ( Marks: 1 ) - Please choose one
Consider the following code segment.

class M {
public:
   M &operator+(const M &);
...
};

p+q                 //code of line implies that   p.operator+(q)
      ...
Let assume if p and q are class objects then function is implemented as _______

    ►   Member function
    ►   Non-member function
    ►   Friend function
    ►   None of the given options

Question No: 27 ( Marks: 1 ) - Please choose one
Assignment operator is -------------------------associative.

    ► right
    ► left
    ►binary
    ► unary

Question No: 28 ( Marks: 1 ) - Please choose one
Static variable which is defined in a function is initialized __________.
    ► Only once during its life time
    ► Every time the function call
    ► Compile time of the program
    ► None of the above
                              virtual.uni.help@gmail.com 
             CS201 Solved Past Papers GURU   




                          http://vusolutions.blogspot.com/ 
 

Question No: 29 ( Marks: 1 ) - Please choose one
Wecan not define a variable of user-defined data type in the class.

    ► True
    ►False

Question No: 30 ( Marks: 1 ) - Please choose one
 A constructor that will create a new object with a full copy of the other object, is
copy is known as ___________
►     deep copy
►     shallow copy
►     constructor copy
►     none of the options

Question No: 31 ( Marks: 1 )
What is the use of reference data type?

A reference data type is a variable that can contain an address. The reference data
types in Java are arrays, classes and interfaces. You'll hear often say that Java does
not have pointers. Yet, you could consider a reference data type to be a pointer

Question No: 32 ( Marks: 1 )
What are the main types of operators in terms of number of arguments they take?

The difference is in the number of arguments used by the function. In the case of
binary operator overloading, when the function is a member function then the number
of arguments used by the operator member function is one (see below example).
When the function defined for the binary operator overloading is a friend function,
then it uses two arguments.

Question No: 33 ( Marks: 2 )
 What is the this pointer? Give an example of its use
In a C++ program, if you create object A of class X, you can then obtain the address
of A by using the "this" pointer. The address is available as a local variable in the
non-static member functions of X, and its type is const X*. The "this" pointer works
because C++ creates instances of its data members, and it keeps one copy of each
member function.

Question No: 34 ( Marks: 2 )
What are manipulators? Give one example.

Manipulators are operators used in C++ for formatting output. The data is
manipulated by the programmer’s choice of displayed endl manipulator. This
manipulator has the same functionality as the ‘\n’ newline character.

Question No: 35 ( Marks: 3 )
What will be the output of following functions if we call these functions three times?
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 

1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}

Output will be:
1
1
1

2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}

Output will be:
1
2
3



Question No: 36 ( Marks: 3 )
 If the requested memory is not available              in   the   system   then   what
does calloc/malloc and new operator return?

malloc returns a void pointer to the allocated space or NULL if there is insufficient
memory available. To return a pointer to a type other thanvoid, use a type cast on
the return value. The storage space pointed to by the return value is guaranteed to
be suitably aligned for storage of any type of object. If size is 0, malloc allocates a
zero-length item in the heap and returns a valid pointer to that item.
By default, malloc does not call the new handler routine on failure to allocate
memory. You can override this default behavior so that, when malloc fails to allocate
memory, malloc calls the new handler routine in the same way that the new operator
does when it fails for the same reason.


Question No: 37 ( Marks: 3 )
 If we want to send the data by reference and don’t want that original data should be
affected then what can we do to prevent any change?

Question No: 38 ( Marks: 5 )
Write down the disadvantages of the templates.
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

The disadvantages of templates are:
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is
large and spread over several header and source files.
• Then, there are times, when templates can "excellently" produce nearly
meaningless compiler errors thus requiring extra care to enforce syntactical and other
design constraints. A common mistake is the angle bracket problem.

Question No: 39 ( Marks: 5 )
 The following code segment has errors. Locate as many as you can and explain
briefly.

class Circle // no need to enter colon here , so I removed it
{
private : //colon missing
double centerX;
double centerY;
double radius;
public: //colon missing
void setCenter(double, double);
void setRadius(int);
};//semi colon missing


Question No: 40 ( Marks: 10 )
 Write a program which consists of two classes, Date and Person.
Date class should contain three data members day, month, year and setter and
getter    function for   these     data    members.    Date   class should also
contain showdate() member function to display date.

Person class should contain three data members Name, Address, and Bday, where
Name and Address are char pointer while Bday(Date of birth) is of type Date, Person
class should further contain two member functions Display() and setdate().

In main program Create an object of Class person and call the member functions with
it.

Please find the Answer in following Box

#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;

class Date
{
public:
                             virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU       




                            http://vusolutions.blogspot.com/ 
 
          int day;
          int month;
          int year;

public:
          Date()
                   {
                            day=0;
                            month=0;
                            year=0;

                   }

          void setDay(int);
          void setMonth (int);
          void setYear(int);

          int getDay();
          int getMonth();
          int getYear();

        void showDate();
};
void Date: :setDay(int d)
{
        if{d<1 | | d>31)
        cout<<"Invalid month Renter it";
        cin>>d;
}
        day=d;
}

void Date: :setMonth (int m)
{
        if(m<1 | | m>12)
{
        cout<<"Invalid month Renter it";
        cin>>m;
}
        month=m;
}
        void Date: :setYear (int y)
{
        year=y;

          int Date: :getDay()
{
          return day;
                                 virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
}
          int Date: :getMonth()
{
          return month:
}
          int Date: :getYear()
{
          return year;
}
          void Date: :showDate()
{
          cout<<day<<"-"<<month<<"-"<<year<<end1;
}
Class Person
{
public:

          char *Name;
    char *Address
          Date Bday;

public:
          Student()
          {
          Name=new char[20];
          Address=new char[10];
          cin.getline(Name,20);
          cout<<"Enter Address:";
          cin.getline(Address,10);
          }

void setDate()
{
        cout<<"Enter Day:";
        cin>>Ad_date.day;
        cout<<"Enter month:";
        cin>>Ad_date.month;
        cout<<"Enter Year:";
        cin>>Ad_date.year;
        }
void Display()
        {
        cout<<"Name: "<<end1;
        cout<<"Address: "<<Address<<end1;
        cout<<"Date of Birth: ";
        Ad-date.showDate();
        }
};
                                 virtual.uni.help@gmail.com 
               CS201 Solved Past Papers GURU       




                                  http://vusolutions.blogspot.com/ 
      
     void main()
     {
             Person object;
             object.setDate();

              object.Display();

              system("pause");
     }


     Question No: 41 ( Marks: 10 )
      Write a C++ program that contains a class ‘myClass’ having two data members of
     type int.
     The class must have
·     A default constructor which must initialize all the data members to their meaningful
     values.
·     A destructor with no implementation.
·     Setter member functions to set all data members of class
·     Getter member functions to get all data members of class

     In main function of the program

5.       Prompt the user to enter the number of objects to be created.
6.       Dynamically allocate memory to objects according to the size entered by user.
7.       De-allocate memory that was allocated to objects

     Find solution in following box:

     #include <stdio.h>
     #include <iostream>
     #include <cstring>
     using namespace std;

     class myclass

     {

     public:
     int a;
     int b;
     int *iptr, *sptr;

     construct{int,int.int}

              void seta(int);
              void setb(int);

                                    virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU     




                             http://vusolutions.blogspot.com/ 
 
         void setc(int);

         int geta();
         int getb();
         int getc();


};

void Person: :seta(int aa)
{

         a=aa;
}

void Person: :setb (int bb)
{

         b=bb;
}
         void Person: :setc (int cc)
{
         c=cc;
}

main()

{

int num;

cout<<"Enter the number of objects to be created";

cin>>num;

for (int i =1;i==num;i++)
{

Person i_

}


}

CS201 – Introduction to Programmming
Solved Subjective Questions
From spring 2010 Final Term Papers
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 

Question No: 1      ( Marks: 2 )

Write a declaration statement for an array of 10 elements of type float.
Include an initialization statement of the first four elements to 1.0, 2.0, 3.0
and 4.0.

Answer:
float floatArry[10] = {1.0,2.0,3.0,4.0};

Question No: 2      ( Marks: 2 )

Write the general syntax for the declaration of pre-increment and post-
increment member operator function.

Answer:
Classname operator ++(); ---- pre increment
Classname operator ++(int) ---- post increment


Question No: 3      ( Marks: 2 )

Give the general syntax of class template.

Answer:
template
class myclass { ---} ;

Question No: 4      ( Marks: 2 )

What is a truth Table?

Answer:
There are some areas where the decision structures become very complicated.
Sometimes, we find it difficult to evaluate a complicated logical expression.
Sometimes the logic becomes extremely complicated so that even writing it as a
simple syntax statement in any language. It becomes complicated to determine what
will be evaluated in what way. We know the concept of truth table. The truth tables
are very important. These are still a tool available for analyzing logical expressions.
We will read logic design in future, which is actually to do with chips and gates. How
we put these things together.

Question No: 5      ( Marks: 2 )

What will be the output of following code, if user input a number 123?

int input ;
cin >> oct >> input;
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
cout << hex << input ;

Answer:

53

Rational: it will take 123 as octal and print it in hex form which is 53.

Question No: 6       ( Marks: 2 )

What is principle of friendship in the context of functions and classes?

Answer:
Class can declare a friend function and someone from outside the class cannot declare
itself friend of a class.
A friend function can access the private variables of class just like a member function

Question No: 7       ( Marks: 2 )

How many arguments a Unary Operator take? Can we make a binary
operator as unary operator?

Answer:
Unary operator takes only one argument like i++ or i— (Post increment or post
decrement operators for integers) or ++i,--i (Pre increment or pre decrement
operators for integers) ,we can not make Unary operator as binary or binary as Unary
operator.

Question No: 8       ( Marks: 2 )

Which arithmetic operators cannot have a floating point operand?

Answer:
Modulus operator:
This operator can only be used with integer operands ONLY

Question No: 9   ( Marks: 2 )
What are manipulators? Give one example.

Answer:
The manipulators are like something that can be inserted into stream, effecting a
change in the behavior. For example, if we have a floating point number, say pi (л),
and have written it as float pi = 3.1415926 ; Now there is need of printing the value
of pi up to two decimal places i.e. 3.14. This is a formatting functionality. For this, we
have a manipulator that tells about width and number of decimal points of a number
being printed.

Question No: 10        ( Marks: 2 )
                              virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 

Write down piece of code that will declare a matrix of 3x3. And initialize all
its locations with 0;

Answer:
int matrix [3] [3] ;

include


main () {
  int matrix [3][3];
  int inivalue = 0;

     for (int a=0;a<3;a++)
     { for (int b = 0;b<3;b++)
    { matrix[a][b]= inivalue;
     cout<
}

Question No: 11        ( Marks: 2 )

What is the difference between switch statement and if statement.
Answer:
The “If” statement is used to select among two alternatives. It uses a Boolean
expression to decide which alternative should be executed. The switch statement is
used to select among multiple alternatives. It uses an int expression to determine
which alternative should be executed.

Question No: 12        ( Marks: 2 )

How can we initialize data members of contained object at construction
time?

Answer:
Initializer list is used to initialize the contained objects at the construction time.

Question No: 13        ( Marks: 2 )

Can we overload new and delete operators?

Answer:
Yes, it is possible to overload new and delete operators to customize memory
management. These operators can be overloaded in global (non-member) scope and
in class scope as member operators.

Question No: 14        ( Marks: 2 )

                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
 Suppose there is a template function ‘func’ having argument of type U and
return type T. What will be the C++ syntax to call this function, passing a
variable ‘x’ of type double and returning an int type?

Answer:
template
T func (T a, U b) {
  return (a
}
calling
int i;
double x;
x = func




Question No: 15       ( Marks: 2 )

Which variable will be used in inner code block if we have the same names of
variable at outer code block and inner code block?

Answer:
Simply: variable of the inner code is use in the inner code block.

Question No: 16       ( Marks: 2 )


What is the benefit of reference and where can we use it?

 Answer:
In references we give the memory address of the object, due to references we pass
values without making the copy. Hence, when we have many values & we want
efficiency we use references to avoid copy.


Question No: 17       ( Marks: 2 )

Write the C++ code for the declaration of overloaded stream insertion and
stream extraction operator for the object d of type Date.

Answer:
Date operator >> (date & d1){
cout<<<”-”<<<”-”<
}

Question No: 18       ( Marks: 2 )

                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
What is difference between endl and \n?

Answer:
Endl is manipulator and it inserts new line character and flushes the stream.

\n is control character which is used to insert line break.

Question No: 19       ( Marks: 2 )

What does code optimization mean?

Answer:
It is process by which we make our code in such a way that it improves the speed of
program. By use of optimization we refine program codes in such a way that it run
faster and consume less memory. We do it in such a way that output quality is not
compromised.

Question No: 20       ( Marks: 3 )

How is the following cout statement interpreted by compiler?

cout << a << b << c ;

Answer:
It will give a compiler error because a,b,c are not declared.

Question No: 21       ( Marks: 3 )

Suppose an object of class A is declared as data member of class B.

(i)                          The constructor of which class will be called first?
Answer: A
(ii)                        The destructor of which class will be called first?
Answer: B


Question No: 22       ( Marks: 3 )

What will be the output of following functions if we call these functions three
times?

1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}

                             virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU    




                          http://vusolutions.blogspot.com/ 
 
Answer:

1
1
1
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}

Answer:
1
2
3

Question No: 23       ( Marks: 3 )

If    is     not     available    in     the             system        then       what
does calloc/malloc and new operator return?

Answer:
calloc/malloc and new operator return returns a null pointer to indicate that no
memory is available

    Question No: 24    ( Marks: 3 )

What is the keyword ‘this’ and what are the uses of ‘this’ pointer?

Answer:
'this' is use to refer the current class member without using the name of the class.


Question No: 25       ( Marks: 3 )

Which one (copy constructor or assignment operator) will be called in each
of the following code segment?

1) Matrix m1 (m2);
2) Matrix m1, m2;
m1 = m2;
3) Matrix m1 = m2;

Answer:

1) Matrix m1 (m2);    copy constructor
2) Matrix m1, m2;
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 
m1 = m2;           assignment operator
3) Matrix m1 = m2; assignment operator

Question No: 26      ( Marks: 3 )

What will be the output of following function if we call this function by
passing int 5?

template T reciprocal(T x) {return (1/x); }

Answer:

0
The output will zero as 1/5 and its .05 but conversion to int make it zero
Above is prototype of template class so assume passing an int and returning an int



Question No: 27      ( Marks: 3 )

Identify the errors in the following member operator function and also
correct them.

math * operator(math m);
math * operator (math m)
{
  math temp;
  temp.number= number * number;
  return number;

}

Answer:

The errors are in the arguments of the member operation function and also in the
body of operator member function.
Correct function should be
math *operator (math *m)
{
   math temp;
   temp = m;
   temp.number= number * number;
   return temp.number;

}


Question No: 28      ( Marks: 3 )
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 

What are the limitations of the friendship relation between classes?

Answer:
friendship relation between classes is a one way relation that is if one class
declare friend another class then the another class is the friend of first class
but not the first class if the friend of another class.


Question No: 29       ( Marks: 3 )

Define static variable. Also explain life time of static variable?

Answer:
When you declare a static variable (native data type or object) inside a function, it
is created and initialized only once during the lifetime of the program.

Question No: 30       ( Marks: 5 )

What is difference between Unary and binary operators and how they can be
overloaded?

Answer:
Unary operator takes one argument.
a ++ is an example of unary operator

Binary take two operators
+,-,* are example of binary operators
Overloaded binary operator may return any type

Here is general syntax of overloading
Return-type operator symbol (parameters);

Operator is keyword

Question No: 31       ( Marks: 5 )

What steps we must follow to design good program?

Answer 1:

Hence to design a program properly, we must:
  Analyze a problem statement, typically expressed as a word problem.
  Express its essence, abstractly and with examples.
  Formulate statements and comments in a precise language.
  Evaluate and revise the activities in light of checks and tests and
  Pay attention to detail.

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                             http://vusolutions.blogspot.com/ 
 
Answer 2:

Details: we must check very details of any program. It is very important aspect of
any program. We must pay complete attention to calculation.
We must give attention to logic and its flow should be smooth.

Reusable: We must write program in such a way that we can reuse them in other
program. Like we define function in such a way that in future if we need any similar
kind of function is requires in that case we can easily modify or reuse it.

Comments: we write the details of important steps in the form of comments. We
should use comments in such a way if any body else wanted to reuse or debug or
codes he can easily understand it.


Code readability: We should use Tab and spaces so codes are easily readable.

User interface: we make interface user friendly. Use polite prompts for user while
take input.

Question No: 32           ( Marks: 5 )

Write a program which defines five variables which store the salaries of five
employees, using setw and setfill manipulators to display all these salaries in
a column.
Note: Display all data with in a particular width and the empty space should
be filled with character x
Output should be displayed as given below:
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000

Answer:

#include
#include
main(){
     int sal1   =1000;
     int sal2   =1500;
     int sal3   =20000;
     int sal4   =30000;
     int sal5   =60000;


cout << setfill ('x') << setw (10);
cout<< sal1<
                                virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
cout << setfill ('x') << setw (10);
cout<< sal2<
cout << setfill ('x') << setw (10);
cout<< sal3<
cout << setfill ('x') << setw (10);
cout<< sal4<
cout << setfill ('x') << setw (10);
cout<< sal5<
int i=0;
cin>>i; // to stop the screen to show the output
}



Question No: 33       ( Marks: 5 )

Suppose we have the following class.

class Matrix
{
private:
int Elements[3][3];
};

Write the operator function of stream extraction operator (>>) for this class.

Answer:
Element operator >> (Element &element){
cout<
cout<
cout<
}

Question No: 34       ( Marks: 5 )


What is meant by user interface and class interface in C++ ? And what role a
class interfaces can play in user interface [Marks 5]

Question No: 35       ( Marks: 5 )

Write the general syntax of a class that has one function as a friend of a
class along with definition of friend function.

Answer:
class frinedclass{
public:
friend int compute(exforsys e1)
                            virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU        




                            http://vusolutions.blogspot.com/ 
 
};
Int                                     compute(exforsys                                  e1)
{
//Friend      Function     Definition      which       has    access    to      private   data
return                                                                       int(e1.a+e2.b)-5;
}

Question No: 36          ( Marks: 5 )

What are the advantages and disadvantages of using templates?

Answer:
Many things can be possible without using templates but it does offer several clear
advantages not offered by any other techniques:

Advantages:
                                               Templates are easier to write than writing
    several versions of your similar code for different types. You create only one
    generic version of your class or function instead of manually creating
    specializations.
                                               Templates are type-safe. This is because
    the types that templates act upon are known at compile time, so the compiler can
    perform type checking before errors occur.
                                               Templates can be easier to understand,
    since they can provide a straightforward way of abstracting type information.
                                               It helps in utilizing compiler optimizations
    to the extreme. Then of course there is room for misuse of the templates. On one
    hand they provide an excellent mechanism to create specific type-safe classes from
    a generic definition with little overhead.

Disadvantages:
On the other hand, if misused
                                                    Templates can make code difficult to read
    and follow depending upon coding style.
                                            They can present seriously confusing
    syntactical problems esp. when the code is large and spread over several header
    and source files.
                                            Then, there are times, when templates
    can "excellently" produce nearly meaningless compiler errors thus requiring extra
    care to enforce syntactical and other design constraints. A common mistake is the
    angle bracket problem.

Question No: 37          ( Marks: 5 )

Suppose a program has a math class having only one data member number.
Write the declaration and definition of operator function to overload +
operator for the statements of main function.
     math obj1, obj2;
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
      obj2= 10 + obj1 ;

Answer:
#include
math
{
mth operator + (obj1,int x)
{

number temp;
temp=obj1.number+x;
return temp.number;
}
}

Question No: 38    ( Marks: 5 )
Write a program which defines three variables of type double which store
three different values including decimal points, using setprecision
manipulators to print all these values with different number of digits after
the decimal number.

Answer:

#include
#include
main () {
double a = 12.12345;
double b = 13.123456;
double c = 14.1234567;
cout << setprecision (5) << a << endl;
cout << setprecision (2) << a << endl;
cout << setprecision (3) << a << endl;
}

Question No: 39       ( Marks: 5 )

Let we have a class,
class String
{
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String
object to other object. Your code should also avoid self assignment

Answer:
void String::operator = ( const String &other )
 { int length ;
                              virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 
 length = other.length();
delete buf;
 buf = new char [length + 1];
 strcpy( buf, other.buf ); }

Question No: 40      ( Marks: 5 )

Read the given below code and explain what task is being performed by this
function
Matrix :: Matrix ( int row , int col )
{
  numRows = row ;
  numCols = col ;
  elements = new ( double * ) [ numRows ] ;
  for ( int i = 0 ; i < numRows ; i ++ )
{
     elements [ i ] = new double [ numCols ] ;
     for ( int j = 0 ; j < numCols ; j ++ )
           elements [ i ] [ j ] = 0.0 ;
   }
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols

Answer:
In the above mentioned code, first of all programmer call the constructor who have
two parameters for the number of rows & columns in the matrix. Then this
constructor also dynamically allocates the memory for the elements of the matrix &
also initializes the value of the all elements of matrix with 0.0




                            virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU        




                              http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

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

If it is required to copy an array to another array then,

     ►   Both   arrays   must be of the same size and data type
     ►   Both   arrays   may be of different size
     ►   Both   arrays   may be of different data type
     ►   Both   arrays   may be of different size and type

For being copy able, both arrays need to be of same data type and same size

Question No: 2      ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical
method

     ► True
     ► False

Passing by reference is the most economical method of dealing with structures
and functions. The function will access the actual address locations of where the
structures are stored as opposed to working with copies of the structures.

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

eof( ), bad( ), good( ), clear( ) all are manipulators.

     ► True
     ► False

Question No: 4    ( Marks: 1 ) - Please choose one
Overloaded new operator function takes parameter of type size_t and returns

     ►   void (nothing)
     ►   void pointer
     ►   object pointer
     ►   int pointer

new operator takes a parameter of type size_t. This parameter holds the size of the
object being allocated, and the compiler automatically sets its value whenever we use
new. Also note that the new operator returns a void pointer. Any new operator we
write must have this parameter and return type.

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

                                 virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
When new operator is overloaded at global level then corresponding built-in new
operator will not be visible to whole of the program.

    ► True

    ► False

If we overload new or delete operator at global level, the corresponding built-in new
or delete operator will not be visible to whole of the program
Question No: 6      ( Marks: 1 ) - Please choose one

If there is more than one statement in the block of a for loop, which of the following
must be placed at the beginning and the ending of the loop block?

    ► parentheses ( )

    ► braces { }

    ► brackets [ ]

    ► arrows < >

BLOCK – is a group of one ore more statements enclosed in curly braces {}.
Question No: 7     ( Marks: 1 ) - Please choose one

The return type of a function that do not return any value must be ________

    ► float

    ► int

    ► void

    ► double

There may be some functions which do not return any value. For such functions, the
 return_value_type is void

Question No: 8     ( Marks: 1 ) - Please choose one
UNIX has been developed in ________ language.

    ►   JAVA
    ►   B
    ►   C
    ►   FORTRAN

UNIX operating system was written by using this C language

                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
Question No: 9      ( Marks: 1 ) - Please choose one

Like member functions, ______ can also access the private data members of a class.

    ► Non-member functions

    ► Friend functions

    ► Any function outside class

    ► None of the given options

If a data is private, it will be available only to member functions of the class. No
other function outside the class (except friend functions) can access the private data

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

Which of the following statement is best regarding declaration of friend function?

    ► Friend function must be declared after public keyword.

    ► Friend function must be declared after private keyword.

    ► Friend function must be declared at the top within class definition.

    ► It can be declared anywhere in class as these are not affected by the public
and private keywords.

Friend is a very strong statement. It is too strong to be affected by public or
privatewe can put it anywhere in the class


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


The operator function overloaded for an Assignment operator (=) must be


    ► Non-member function of class

    ► Member function of class

    ► Friend function of class

    ► None of the given options

The operator overloading functions for overloading (), [], -> or the assignment (=)
Operators must be declared as class members
                             virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU        




                          http://vusolutions.blogspot.com/ 
 

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


The endl and flush are _______

     ► Functions

     ► Operators

     ► Manipulators

     ► Objects

Similarly flush was a manipulator for which we could write cout << flush that means
flushing the output buffer. So it manipulates the output

Question No: 13       ( Marks: 1 ) - Please choose one
If a symbolic constant has been defined, it will be an error to define it again.

     ► True

     ► False

If   a   symbolic   constant   is   defined,       it   will   be   error   to   define   it   again


Question No: 14      ( Marks: 1 ) - Please choose one
The operator used for casting, in C, is standard ________ operator.

     ► none of the given options.

     ► cast

     ► cost

     ► const

The operator used for casting, in C, is standard cast operator.

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

Constructors can not be overloaded like ordinary functions.

     ► True

     ► False

                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                            http://vusolutions.blogspot.com/ 
 
Just like ordinary methods, constructors can be overloaded in order to make it so that
an      object    can   be     created     with    different   attributes    specified


Question No: 16       ( Marks: 1 ) - Please choose one
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );


    ► defaultParameters (5);


    ► defaultParameters (5, ‘8’);


    ► defaultParameters (6, ‘#’);


    ► defaultParameters (0, 0, ‘*’, 0);


Question No: 17      ( Marks: 1 ) - Please choose one
When an operator function is defined as member function for a binary Plus (+)
operator then the number of argument it take is/are.

    ►   Zero
    ►   One
    ►   Two
    ►   N arguments

Question No: 18      ( Marks: 1 ) - Please choose one
Wecan not define a variable of user-defined data type in the class.

    ► True
    ► False

Question No: 19      ( Marks: 1 ) - Please choose one
When an object of a class is defined inside an other class then,

    ►   Constructor   of enclosing class will be called first
    ►   Constructor   of inner object will be called first
    ►   Constructor   and Destructor will be called simultaneously
    ►   None of the   given options

The order of destruction of an object is reverse to this construction order, where the
outer object is destroyed first before the inner data members.

Question No: 20         ( Marks: 1 ) - Please choose one
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU        




                          http://vusolutions.blogspot.com/ 
 
The appropriate data type to store the number of rows and colums of the matrix
is____________.

    ►   float
    ►   int
    ►   char
    ►   none of the given options.

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

Class is a user defined___________.

    ►   data type
    ►   memory referee
    ►   value
    ►   none of the given options.

A class is a user defined data type

Question No: 22       ( Marks: 1 ) - Please choose one
A pointer variable can be,

    ►   Decremented
    ►   Incremented
    ►   Multiplied
    ►   Both Decremented and Decremented


Question No: 23     ( Marks: 1 ) - Please choose one
NULL value has been defined in ______ and _________ header files.

    ►   strings.h and iostream.h
    ►   ctype.h and conio.c
    ►   conio.c and conio.h
    ►   stdlib.h and stddef.h

NULL    has    been   defined      in   the       header   files   stdlib.h   and   stddef.h.

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

A Matrix can be composed of ints, floats or doubles as their elements. Best way is to
handle this , _______________

    ►   Write a separate class to handle each
    ►   Use templates
    ►   Use strings to store all types
    ►   None of the given options

                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

Question No: 25      ( Marks: 1 ) - Please choose one
"setprecision" manipulator will set

     ► The number of digits after the decimal point

     ► The number of digits before the decimal point

     ► The number of digits in a number

     ► None of the given options

setprecision. This is the parameterized, inline- manipulator that sets the places after
the decimal point.

Question No: 26       ( Marks: 1 ) - Please choose one
Which of the following option will be true, if we overload "-=" operator?


     ► only - operator needs to be overloaded (not sure)

     ► Minus (-) and = operators need to be overloaded

     ► the -= operator need to be overloaded explicitly

     ► the - and = operators need to be overloaded implicitly


Question No: 27       ( Marks: 2 )
Suppose there is a template function ‘func’ having argument of type U and return
type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type
double and returning an int type?

Question No: 28       ( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable
at outer code block and inner code block?

Question No: 29        ( Marks: 2 )
What is the benefit of reference and where can we use it?

Question No: 30       ( Marks: 2 )
Write the C++ code for the declaration of overloaded stream insertion and stream
extraction operator for the object d of type Date.

Question No: 31       ( Marks: 3 )
What will be the output of following functions if we call these functions three times?

1)
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}

Question No: 32     ( Marks: 3 )
If the requested memory is not available               in   the   system   then   what
does calloc/malloc and new operator return?

Question No: 33        ( Marks: 3 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first?
(ii) The destructor of which class will be called first?

Question No: 34     ( Marks: 5 )
What is difference between Unary and binary operators and how they can be
overloaded?

Question No: 35     ( Marks: 5 )
Suppose we have the following class.

class Matrix
{
private:
int Elements[3][3];
};

Write the operator function of stream extraction operator (>>) for this class.

Question No: 36        ( Marks: 5 )
What is meant by user interface and class interface in C++ ? And what role a class
interface can play in user interface [Marks 5]




                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

Time: 90 min
Marks: 58

Question No: 1         ( Marks: 1 ) - Please choose one
If it is required to copy an array to another array then,
       ► Both arrays must be of the same size and data type
       ► Both arrays may be of different size
       ► Both arrays may be of different data type
       ► Both arrays may be of different size and type

Question No: 2      ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical
method
     ► True
     ► False

Question No: 3       ( Marks: 1 ) - Please choose one
eof( ), bad( ), good( ), clear( ) all are manipulators.
     ► True
     ► False

Question No: 4     ( Marks: 1 ) - Please choose one
Overloaded new operator function takes parameter of type size_t and returns
    ► void (nothing)
    ► void pointer
    ► object pointer
    ► int pointer

Question No: 5       ( Marks: 1 ) - Please choose one
When new operator is overloaded at global level then corresponding built-in new
operator will not be visible to whole of the program.
    ► True
    ► False



Question No: 6      ( Marks: 1 ) - Please choose one
If there is more than one statement in the block of a for loop, which of the following
must be placed at the beginning and the ending of the loop block?
     ► parentheses ( )
     ► braces { }
     ► brackets [ ]
     ► arrows < >

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                          http://vusolutions.blogspot.com/ 
 

Question No: 7       ( Marks: 1 ) - Please choose one
The return type of a function that do not return any value must be ________
    ► float
    ► int
    ► void
    ► double

Question No: 8     ( Marks: 1 ) - Please choose one
UNIX has been developed in ________ language.
    ► JAVA
    ►B
    ►C
    ► FORTRAN

Question No: 9       ( Marks: 1 ) - Please choose one
Like member functions, ______ can also access the private data members of a class.
     ► Non-member functions
     ► Friend functions
     ► Any function outside class
     ► None of the given options

Question No: 10       ( Marks: 1 ) - Please choose one
Which of the following statement is best regarding declaration of friend function?
    ► Friend function must be declared after public keyword.
    ► Friend function must be declared after private keyword.
    ► Friend function must be declared at the top within class definition.
    ► It can be declared anywhere in class as these are not affected by the public
and private keywords.

Question No: 11       ( Marks: 1 ) - Please choose one
The operator function overloaded for an Assignment operator (=) must be
    ► Non-member function of class
    ► Member function of class
    ► Friend function of class
    ► None of the given options

Question No: 12     ( Marks: 1 ) - Please choose one
The endl and flush are _______
    ► Functions
    ► Operators
    ► Manipulators
    ► Objects

Question No: 13       ( Marks: 1 ) - Please choose one
If a symbolic constant has been defined, it will be an error to define it again.
      ► True
      ► False
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

Question No: 14      ( Marks: 1 ) - Please choose one
The operator used for casting, in C, is standard ________ operator.
    ► none of the given options.
    ► cast
    ► cost
    ► const

Question No: 15      ( Marks: 1 ) - Please choose one
Constructors can not be overloaded like ordinary functions.
    ► True
    ► False



Question No: 16       ( Marks: 1 ) - Please choose one
Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );
    ► defaultParameters (5);
    ► defaultParameters (5, ‘8’);
    ► defaultParameters (6, ‘#’);
    ► defaultParameters (0, 0, ‘*’, 0);



Question No: 17      ( Marks: 1 ) - Please choose one
When an operator function is defined as member function for a binary Plus (+)
operator then the number of argument it take is/are.
    ► Zero
    ► One
    ► Two
    ► N arguments



Question No: 18      ( Marks: 1 ) - Please choose one
We can not define a variable of user-defined data type in the class.
    ► True
    ► False



Question No: 19      ( Marks: 1 ) - Please choose one
When an object of a class is defined inside an other class then,
   ► Constructor of enclosing class will be called first
   ► Constructor of inner object will be called first
   ► Constructor and Destructor will be called simultaneously
   ► None of the given options
                              virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 




Question No: 20      ( Marks: 1 ) - Please choose one
The appropriate data type to store the number of rows and colums of the matrix
is____________.
    ► float
    ► int
    ► char
    ► none of the given options.



Question No: 21        ( Marks: 1 ) - Please choose one
Class is a user defined___________.
     ► data type
     ► memory referee
     ► value
     ► none of the given options.



Question No: 22       ( Marks: 1 ) - Please choose one
A pointer variable can be,
    ► Decremented
    ► Incremented
    ► Multiplied
    ► Both Decremented and Decremented



Question No: 23      ( Marks: 1 ) - Please choose one
NULL value has been defined in ______ and _________ header files.
    ► strings.h and iostream.h
    ► ctype.h and conio.c
    ► conio.c and conio.h
    ► stdlib.h and stddef.h



Question No: 24      ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to
handle this , _______________
    ► Write a separate class to handle each
    ► Use templates
    ► Use strings to store all types
    ► None of the given options

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 




Question No: 25      ( Marks: 1 ) - Please choose one
"setprecision" manipulator will set
     ► The number of digits after the decimal point
     ► The number of digits before the decimal point
     ► The number of digits in a number
     ► None of the given options



Question No: 26       ( Marks: 1 ) - Please choose one
Which of the following option will be true, if we overload "-=" operator?
    ► only - operator needs to be overloaded
    ► Minus (-) and = operators need to be overloaded
    ► the -= operator need to be overloaded explicitly
    ► the - and = operators need to be overloaded implicitly



Question No: 27        ( Marks: 2 )
Suppose there is a template function ‘func’ having argument of type U and return
type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type
double and returning an int type?
Question No: 28        ( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable
at outer code block and inner code block?
Question No: 29        ( Marks: 2 )
What is the benefit of reference and where can we use it?
Question No: 30        ( Marks: 2 )
Write the C++ code for the declaration of overloaded stream insertion and stream
extraction operator for the object d of type Date.
Question No: 31        ( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 32        ( Marks: 3 )
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
If the requested memory is not available in the system then what
does calloc/malloc and new operator return?
Question No: 33        ( Marks: 3 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first?
(ii) The destructor of which class will be called first?
Question No: 34        ( Marks: 5 )
What is difference between Unary and binary operators and how they can be
overloaded?
Question No: 35        ( Marks: 5 )
Suppose we have the following class.
class Matrix
{
private:
int Elements[3][3];
};
Write the operator function of stream extraction operator (>>) for this class.
Question No: 36        ( Marks: 5 )
What is meant by user interface and class interface in C++ ? And what role a class
interface can play in user interface [Marks 5]




                           virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                           http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

Time: 90 min
Marks: 58

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

&& is -------------------- operator.
     ► An arithmetic
     ► Logical
     ► Relational
     ► Unary

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

Which of the following function(s) is/are included in ctype.h header file?
    ► isdigit(int c)
    ► isxdigit(int c )
    ► tolower(int c)
    ► All of the above

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

Disks are _______________ devices having access time of _________ milliseconds.
    ► Electro-physical, 6
    ► Electro-Mechanical, 4
    ► Electro-physical, 5
    ► Electro-Mechanical, 7

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

All preprocessor directives are started with the symbol______.
     ►*
     ► ++
     ►@
     ►#

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

When we use manipulators in our program then which header file should be included?
   ► iostream.h
   ► stdlib.h
   ► stdio.h
   ► iomanip.h

Question No: 6       ( Marks: 1 ) - Please choose one
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU        




                           http://vusolutions.blogspot.com/ 
 

setprecision is a parameter less manipulator.
     ► True
     ► False

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

Which of the following is NOT a preprocessor directive?
    ► #error
    ► #define
    ► #line
    ► #ndefine

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

We can do arithmetic with references like pointers.
    ► True
    ► False

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

What does (*this) represents?
   ► The current function of the class
   ► The current pointer of the class
   ► The current object of the class
   ► A value of the data member

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

Friend function of a class is ______________ .
     ► Member function
     ► Non-member function
     ► Private function
     ► Public function

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

A function can declare itself a friend of a class.
     ► True
     ► False

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

Overloaded delete operator function takes the same parameter as an argument
returned by new operator function.
     ► True
     ► False

                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
Question No: 13       ( Marks: 1 ) - Please choose one

The second parameter of operator functions for << and >> are objects of the class
for which we are overloading these operators.
     ► True
     ► False

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

A template function must have at least ---------- generic data type
    ► Zero
    ► One
    ► Two
    ► Three

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

A template function must have only generic data types.
    ► True
    ► False

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

We can not make a member function of a class as template function.
    ► True
    ► False

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

Which character is inserted at the end of string to indicate the end of string?
    ► new line
    ► tab
    ► null
    ► carriage return

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

Assignment operator is used for ___________.
     ► calculation
     ► reading
     ► assigning value to variables
     ► None of the given options.

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

The object _______________may be used both for file input and file output
    ► fstream,
    ► ifstream,
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU       




                         http://vusolutions.blogspot.com/ 
 
    ► ofstream,
    ► none of the given options.

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

Which of the following function calling mechanism is true for the function prototype
given below?
float func(float &);
     ► Call by value
     ► Call by reference using pointer
     ► Call by reference using reference variable
     ► None of the given options

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

The programs, in which we allocate static memory, run essentially on ________
    ► Heap
    ► System Cache
    ► None of the given options
    ► Stack

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

Overloaded delete operator function takes parameter of void pointer and returns
________.
    ► void
    ► void pointer
    ► pointer to an object
    ► pointer of type int

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

What should be the return type of the constructor?
   ► void pointer
   ► int
   ► same as object type
   ► constructors do not return any thing

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

It is a way of reusing the code when we contain objects of our already written classes
into a new class,
      ► True
      ► False

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

Templates are not type safe.
                               virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
     ► true
     ► false

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

The functions used for dynamic memory allocation return pointer of type ______

     ►   int
     ►   float
     ►   void
     ►   double

Question No: 27        ( Marks: 2 )

Write a declaration statement for an array of 10 elements of type float. Include an
initialization statement of the first four elements to 1.0, 2.0, 3.0 and 4.0.
Answer:
float floatArry[10] = {1.0,2.0,3.0,4.0};
Question No: 28        ( Marks: 2 )

Write the general syntax for the declaration of pre-increment and post-increment
member operator function.
Classname operator ++(); ---- pre increment
Classname operator ++(int) ---- post increment
Question No: 29     ( Marks: 2 )

What is difference between endl and \n?
Question No: 30       ( Marks: 2 )

What does code optimization mean?
Question No: 31     ( Marks: 3 )

How is the following cout statement interpreted by compiler?szuv
cout << a << b << c ;
Question No: 32       ( Marks: 3 )

Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first? Answer : A
(ii) The destructor of which class will be called first? Answer : B
Question No: 33        ( Marks: 3 )

Define static variable. Also explain life time of static variable?
Question No: 34        ( Marks: 5 )

What is difference between Unary and binary operators and how they can be
overloaded?
Question No: 35     ( Marks: 5 )
What steps we must follow to design good program?
                              virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
 Question No: 36       ( Marks: 5 )
 Write a program which defines five variables which store the salaries of five
employees, using setw and setfill manipulators to display all these salaries in a
column.
Note: Display all data with in a particular width and the empty space should be filled
with character x
Output should be displayed as given below:
xxxxxx1000
xxxxxx1500
xxxxx20000
xxxxx30000
xxxxx60000




                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

Marks: 58

Question No: 1       ( Marks: 1 ) - Please choose one
*.doc is _____________ by type.
.
    ► Sequential File
    ► Random Access File
    ► Data File
    ► Record File
Question No: 2       ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
    ► #error
    ► #define
    ► #line
    ► #ndefine

Question No: 3       ( Marks: 1 ) - Please choose one
The return type of operator function must always be void.
     ► True
     ► False
The syntax of the prototype of the overloaded operator function is: return-
type operator operator-symbol (parameter-list);
Question No: 4       ( Marks: 1 ) - Please choose one
What does (*this) represents?
     ► The current function of the class
     ► The current pointer of the class
     ► The current object of the class
     ► A value of the data member
Whenever an object calls a member function, the function implicitly gets a pointer
from the calling object. That pointer is known as this pointer. ‘this’ is a key word. We
cannot use it as a variable name. ‘this’ pointer is present in the function, referring to
the calling object. For example, if we have to refer a member, let’s say buf, of
our Stringclass, we can write it simply as: buf ;

Question No: 5     ( Marks: 1 ) - Please choose one
The statement cin.get (); is used to,
    ► Read a string from keyboard
    ► Read a character from keyboard
    ► Read a string from file
    ► Read a character from file

Question No: 6      ( Marks: 1 ) - Please choose one
 When we do dynamic memory allocation in the constructor of a class, then it is
necessary to provide a destructor.
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
     ► True
     ► False
Question No: 7      ( Marks: 1 ) - Please choose one
 Overloaded new operator function takes parameter of type size_t and returns
     ► void (nothing)
     ► void pointer
     ► object pointer
     ► int pointer
Question No: 8      ( Marks: 1 ) - Please choose one
The second parameter of operator functions for << and >> are objects of the class
for which we are overloading these operators.
     ► True
     ► False
The second parameter to operator << is an object of the class that we are
overloading the operator for. Similar is the case for operator >>.

Question No: 9       ( Marks: 1 ) - Please choose one
 C++ is a case-sensitive language
     ► True
     ► False
Question No: 10        ( Marks: 1 ) - Please choose one
 To include code from the library in the program, such as iostream, a directive would
be called up using this command.
     ► #include “iostream.h”
     ► include
     ► include
     ► #include
Question No: 11        ( Marks: 1 ) - Please choose one
 A template function must have only generic data types.
     ► True
     ► False
Its not compulsory, only min we have one generic data type but we can have native
data type as well.

Question No: 12       ( Marks: 1 ) - Please choose one
 Template class can not have static variables.
     ► True
     ► False
Question No: 13       ( Marks: 1 ) - Please choose one
What will be the correct syntax to assign an array named arr of 5 elements to a
pointer ptr?
     ► *ptr = arr ;
     ► ptr = arr ;
     ► *ptr = arr[5] ;
     ► ptr = arr[5] ;
Question No: 14       ( Marks: 1 ) - Please choose one
What will be the correct syntax to access the value of fourth element of an array
using pointer ptr?
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
     ► ptr[3]
     ► (ptr+3)
     ► *(ptr+3)
     ► Both 1and 3
try this demo program to confirm result I wrote for you.
2 option will print the reference rest 1,3 are righ options

#include
 #include
// #include

main()
{
int myarr [4]= {0,1,2,3};
int *ptr ;
ptr = myarr;
cout<
cout<<*(ptr+3);
cout<<(ptr+3);
int i = 0;
cin>> i;
}

Question No: 15         ( Marks: 1 ) - Please choose one
 If most significant bit of un-signed number is 1 then it represents a positive number.
     ► True
     ► False
The most significant bit is used as a sign bit. If this bit is zero, the number is
considered positive. However, if it is 1, the number will be considered negative.

Question No: 16        ( Marks: 1 ) - Please choose one
 If there is a symbol (& sign) used with the variable name followed by data type then
it refers to _____ and if & is being used with variable name then it refers to _____.
      ► Address of variable, reference variable
      ► Reference variable, value of variable
      ► Reference variable, address of variable
      ► Address of variable, value of variable
we see a data type followed by & sign, it’s a reference. And when the & sign is being
used in the code with a variable name then it is the address of the variable

Question No: 17     ( Marks: 1 ) - Please choose one
We can also do conditional compilation with preprocessor directives.
   ► True
   ► False

Question No: 18       ( Marks: 1 ) - Please choose one
The default value of a parameter can be provided inside the ________________
    ► function prototype
                              virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
     ► function definition
     ► both function prototype or function definition
     ► none of the given options.
The default value of a parameter is provided inside the function prototype or function
definition.

Question No: 19       ( Marks: 1 ) - Please choose one
Classes defined inside other classes are called ________ classes
    ► looped
    ► nested
    ► overloaded
    ► none of the given options.

Question No: 20       ( Marks: 1 ) - Please choose one
What purpose do classes serve?
    ► Data encapsulation
    ► Providing a convenient way of modeling real-world objects
    ► Simplifying code reuse
    ► All of the given options
Question No: 21       ( Marks: 1 ) - Please choose one
Every class contains _______________.
    ► Constructor
    ► Destructor
    ► Both a constructor and a destructor
    ► None of the given options

Question No: 22        ( Marks: 1 ) - Please choose one
new operator is used to allocate memory from the free store during
     ► Compile Time
     ► Run Time
     ► Link Time
     ► None of the given options
Question No: 23        ( Marks: 1 ) - Please choose one
When an object of a class is defined inside another class then,
     ► Destructor of enclosing class will be called first
 ► Destructor of inner object will be called first
     ► Constructor and Destructor will be called simultaneously
     ► None of the given options
Question No: 24        ( Marks: 1 ) - Please choose one
It is possible to define a class within another class.
     ► True
     ► False
Question No: 25        ( Marks: 1 ) - Please choose one
New and Delete are also used with ___________ and data types as well.
     ► Class, Objects
     ► Structures, Pointers
     ► Both Class and structures
     ► None of above
                            virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU      




                           http://vusolutions.blogspot.com/ 
 
we prefer to use new and delete operators as they are designed to work with classes
and objects
Question No: 26        ( Marks: 1 ) - Please choose one
 With New keyword, data types and class members are initialized with meaningful
values instead of garbage.
      ► True
      ► False
Question No: 27        ( Marks: 2 )
 How many arguments a Unary Operator take? Can we make a binary operator as
unary operator?
Ans: Unary operator takes only one aurgument like i++ or i— (Post increment or post
decrement operators for intergers) or ++i,--i (Pre increment or pre decrement
operators for intergers) ,we can not make Unary operator as binary or binary as
Unary operator.
Question No: 28        ( Marks: 2 )
 Which arithmetic operators cannot have a floating point operand?
Ans:
Modulus operator
This operator can only be used with integer operands ONLY
Question No: 29        ( Marks: 2 )
 What are manipulators? Give one example.
Ans:
The manipulators are like something that can be inserted into stream, effecting a
change in the behavior. For example, if we have a floating point number, say pi (л),
and have written it as float pi = 3.1415926 ; Now there is need of printing the value
of pi up to two decimal places i.e. 3.14 . This is a formatting functionality. For this, we
have a manipulator that tells about width and number of decimal points of a number
being printed.
Some manipulators are parameter less. We simply use the name of the manipulator
that works. For example, we have been using endl, which is actually a manipulator,
not data. When we write cout << endl ; a new line is output besides flushing the
buffer. Actually, it manipulates the output stream.
Question No: 30        ( Marks: 2 )
 Write down piece of code that will declare a matrix of 3x3. And initialize all its
locations with 0;
Ans:
int matrix [3] [3] ;

include<iostream.h>


main () {
  int matrix [3][3];
  int anyvalue = 12

     for (int a=0;a<3;a++)
     { for (int b = 0;b<3;b++)
    { matrix[a][b]= anyvalue;
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
    cout<<matrix[a][b]<<endl;}}
    int i=0;
    cin>>i;
}
Question No: 31       ( Marks: 3 )
 Which one (copy constructor or assignment operator) will be called in each of the
following code segment?
1) Matrix m1 (m2);
2) Matrix m1, m2;
m1 = m2;
3) Matrix m1 = m2;
Ans:
1) Matrix m1 (m2); copy constructor
2) Matrix m1, m2;
m1 = m2;            assignment operator
3) Matrix m1 = m2; assignment operator
Question No: 32       ( Marks: 3 )
 What will be the output of following function if we call this function by passing int 5?
template T reciprocal(T x) {return (1/x); }
Ans:
1/5
Question No: 33       ( Marks: 3 )
 Identify the errors in the following member operator function and also
correct them.
math * operator(math m);
math * operator (math m)
{
    math temp;
    temp.number= number * number;
    return number;

}
ANS:
The errors are in the arguments of the member operation function and also in the
body of operator member function.
Correct function should be
math *operator(math *m);
math *operator (math *m)
{
   math temp;
   temp = m;
   temp.number= number * number;
   return temp.number;

}

Question No: 34       ( Marks: 5 )

                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
 Write a program which defines three variables of type double which store three
different values including decimal points, using setprecision manipulators to print all
these values with different number of digits after the decimal number.
Ans:
#include
#include
int main ()
{
  double x1 = 12345624.72345
double x2 = 987654.12345
double x3 = 1985.23456
  cout << setprecision (3) << x1<< endl;
  cout << setprecision (4) << x2 << endl;
cout << setprecision (5) << x3<< endl;
  return 0;
}
Question No: 35         ( Marks: 5 )
 What are the advantages and disadvantages of using templates?
Ans:
Many thing can be possible without using templates but it do offer several clear
advantages not offered by any other techniques:
Advanatages:
 • Templates are easier to write than writing several versions of your similar code for
different types. You create only one generic version of your class or function instead
of manually creating specializations.
• Templates are type-safe. This is because the types that templates act upon are
known at compile time, so the compiler can perform type checking before errors
occur.
 • Templates can be easier to understand, since they can provide a straightforward
way of abstracting type information.
• It help in utilizing compiler optimizations to the extreme. Then of course there is
room for misuse of the templates. On one hand they provide an excellent mechanism
to create specific type-safe classes from a generic definition with little overhead.
Disadvantages:
On the other hand, if misused
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is
large and spread over several header and source files.
 • Then, there are times, when templates can "excellently" produce nearly
meaningless compiler errors thus requiring extra care to enforce syntactical and other
design constraints. A common mistake is the angle bracket problem.

Question No: 36      ( Marks: 5 )
 Suppose a program has a math class having only one data member number.
Write the declaration and definition of operator function to overload + operator for
the statements of main function.
      math obj1, obj2;
      obj2= 10 + obj1 ;
                             virtual.uni.help@gmail.com 
        CS201 Solved Past Papers GURU  




                      http://vusolutions.blogspot.com/ 
 
Ans:
#include
math
{
mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
{
 mth operator + (obj1,obj2)
mth operator + (obj1,obj2)
}
}




                        virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
 FINALTERM EXAMINATION
CS201 - Introduction to programming
Final Term Spring 2010

Operator overloading can be performed through__________________.
    ► Classes
    ► Functions

     ► Operators
     ► Reference


Question No: 2      ( Marks: 1 ) - Please choose one
When a value is referred by a normal variable then it is known as,
    ► Direct Reference
     ► Indirect Reference
    ► Partial Reference
    ► Proper Reference
When a value is referred by a normal variable is known as direct reference
Question No: 3      ( Marks: 1 ) - Please choose one
Which of the following function is used to increase the size of already allocated
memory chunk?

    ► malloc
      ► calloc
        ► realloc
        ► free

Question No: 4       ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
    ► #error
    ► #define
    ► #line


     ► #ndefine

list of preprocessors
• #include • #include “filename” • #define • #undef • #ifdef • #ifndef • #if • #else •
#elif    •    #endif     •    #error    •    #line   •     #pragma       •     #assert


Question No: 5      ( Marks: 1 ) - Please choose one
The stream objects cin and cout are included in which header file?
      ► iostream.h
    ► fstream.h
    ► istream.h

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
    ► ostream.h

Question No: 6      ( Marks: 1 ) - Please choose one
Overloaded delete operator function takes the same parameter as an argument
returned by new operator function.
     ► True
     ► False
 The same pointer that is returned by the new operator, is passed as an argument to
the delete operator. These rules apply to both, if operators (new and delete) are
overloaded as member or non-member operators (as global operators).

Question No: 7     ( Marks: 1 ) - Please choose one
When an array of object is created dynamically then there is no way to provide
parameterized constructors for array of objects.
     ► True

     ► False
if we are allocating an array of objects, there is no way to pass arguments to objects’
constructors. Therefore it is required that the objects that are stored in such an array
have                    a                    no-argument                     constructor.


Question No: 8      ( Marks: 1 ) - Please choose one
C is widely known as development language of _______ operating system.
     ► Linux
     ► Windows
      ► Unix
  ► Mac OS
In the start C became widely known as the development language of the UNIX
operating system, and the UNIX operating system was written by using this C
language. The C language is so powerful that the compiler of C and other various
operating           systems           are         written          in         C.

Question No: 9    ( Marks: 1 ) - Please choose one
Computer can understand only machine language code.
    ► True

    ► False
Question No: 10       ( Marks: 1 ) - Please choose one
We can not define a function as a friend of a Template class.
    ► True
     ► False

Class templates can have friends. A class or class template, function, or function
template can be a friend to a template class. Friends can also be specializations of a
class   template   or   function   template,     but   not   partial  specializations.


                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
Question No: 11 ( Marks: 1 ) - Please choose one
What will be the value of ‘a’ and ‘b’ after executing the following
statements?
a = 3;
b = a++;
    ► 3, 4
    ► 4, 4
    ► 3, 3
    ► 4, 3

Question No: 12        ( Marks: 1 ) - Please choose one
Consider the following code segment. What will be the output of following code?
int addValue (int *a){
int b = (*a) + 2;
return b ;
}
main () {
int x =6 ;
cout << x << “,” ;
cout << addValue(&x) << “,” ;
cout << x ;
}
     ► 6,8,6

    ► 6,6,8
    ► 6,8,8
    ► 6,6,6


Question No: 13      ( Marks: 1 ) - Please choose one
_______ is used to trace the logic of the program and correct the logical errors.
   ► Compiler
   ► Editor
   ► Linker
   ► Debugger



Question No: 14      ( Marks: 1 ) - Please choose one
new and delete are _____ whereas malloc and free are _____.
    ► Functions, operators
    ► Classes, operators
    ► Operators, functions
    ► Operators, classes
Hence,       we        can       call new and delete operators, P#  342
we have allocated a memory space for our use by malloc function. P# 285


                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
Question No: 15      ( Marks: 1 ) - Please choose one
Like member functions, ______ can also access the private data members of a class.
     ► Non-member functions
     ► Friend functions
     ► Any function outside class
     ► None of the given options
Question No: 16      ( Marks: 1 ) - Please choose one
Which situation would require the use of a non-member overloaded operator?
     ► The overloaded operator is an Assignment operator.
     ► The left most operand is an object of a class.

    ► The left operand is built-in data type.
    ► The operator returns a reference.

When an operator function is implemented as a non-member function, the left-most
operand may be an object of the operator’s class, an object of a different class, or a
built-in type
Question No: 17        ( Marks: 1 ) - Please choose one
The stream insertion and stream extraction operators are already overloaded for
______.
     ► User-defined data types
     ► Built-in data types
     ► User-defined and built-in data types
     ► None of the given options
Question No: 18        ( Marks: 1 ) - Please choose one
If we define an identifier with the statement #define PI 3.1415926 then during the
execution of the program the value of PI __________.
     ► can not be replaced
     ► None of the given options
     ► Remain constant.
     ► can be changed by some operation


Question No: 19       ( Marks: 1 ) - Please choose one
Assignment operator is -------------------------associative.
      ► right
      ► left
      ► binary
      ► unary
You can assign values to several variables in a single statement. For example, the
following code sets the contents of apples and oranges to the same value:
apples = oranges = 10;
The assignment operator is right associative, so this statement executes by first
storing the value 10 in oranges and then storing the value in oranges in apples, so it
is effectively
apples = (oranges = 10);

Question No: 20      ( Marks: 1 ) - Please choose one
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU       




                         http://vusolutions.blogspot.com/ 
 
When ever dynamic memory allocation is made in C/C++, it is freed_____________.
    ► Explicitly
    ► Implicitly
    ► Both explicitly and implicitly
    ► None of the given options
Question No: 21       ( Marks: 1 ) - Please choose one
The appropriate data type to store the number of rows and colums of the matrix
is____________.
    ► float
    ► int
    ► char
               ► none              of         the         given          options.


Question No: 22       ( Marks: 1 ) - Please choose one
Which of the following function do NOT initialize the chunk of memory to all zero?
    ► calloc() function
    ► Both malloc() and calloc()
    ► None of the above
    ► malloc() function

The malloc function differs from calloc in the way that the space allocated
by malloc is not initialized and contains any values initially.
Question No: 23        ( Marks: 1 ) - Please choose one
The function free() returns back the allocated memory got thorough calloc and malloc
to _____ .
     ► stack
     ► heap
     ► stack and heap
     ► None of the given options

Question No: 24     ( Marks: 1 ) - Please choose one
width() is member function of _____________
    ► cin object
    ► cout object
    ► Both cin and cout object
    ► None of the given option


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

Templates are not type safe.
   ► true
   ► false

Templates are type-safe. This is because the types that templates act upon are
known at compile time, so the compiler can perform type checking before errors
occur.
                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU       




                           http://vusolutions.blogspot.com/ 
 
Question No: 26       ( Marks: 1 ) - Please choose one
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to
handle this , _______________
     ► Write a separate class to handle each
     ► Use templates
     ► Use strings to store all types
     ► None of the given options
A Matrix can be composed of ints, floats or doubles as their elements. Instead of
handling these data types separately, we can write Matrix class as a template class
and write code once for all native data types. While writing this template class, the
better approach to write will be, to go with a simple data type (e.g.double) first to
write a Matrix class and then extend it to a template class later.


Question No: 27        ( Marks: 2 )
Give the general syntax of class template.
template
class myclass { ---} ;

Question No: 28       ( Marks: 2 )
What is a truth Table?
There are some areas where the decision structures become very complicated.
Sometimes, we find it difficult to evaluate a complicated logical expression.
Sometimes the logic becomes extremely complicated so that even writing it as a
simple syntax statement in any language. It becomes complicated to determine what
will be evaluated in what way. We know the concept of truth table. The truth tables
are very important. These are still a tool available for analyzing logical expressions.
We will read logic design in future, which is actually to do with chips and gates. How
we put these things together.

Question No: 29        ( Marks: 2 )

What will be the output of following code, if user input a number 123?
int input ;
cin >> oct >> input;
cout << hex << input ;

53
Rational: it will take 123 as octal and print it in hex form which is 53.

Question No: 30           ( Marks: 2 )
What is principle of friendship in the context of functions and classes?
Class can declare a friend function and someone from outside the class cannot declare
itself friend of a class.
A friend function can access the private variables of class just like a member function

Question No: 31       ( Marks: 3 )
What are the limitations of the friendship relation between classes?
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
Class can declare a friend class from inside and someone from outside the class
cannot declare itself friend of a class.

Question No: 32        ( Marks: 3 )
Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first? a
(ii) The destructor of which class will be called first?b

Question No: 33        ( Marks: 3 )
Define static variable. Also explain life time of static variable?
When you declare a static variable (native data type or object) inside a function, it is
created and initialized only once during the lifetime of the program

Question No: 34        ( Marks: 5 )
 Write a program which defines three variables of type double which store three
different values including decimal points, using setprecision manipulators to print all
these values with different number of digits after the decimal number.
#include
#include
main () {
double a = 12.12345;
double b = 13.123456;
double c = 14.1234567;
cout << setprecision (5) << a << endl;
cout << setprecision (2) << a << endl;
cout << setprecision (3) << a << endl;
}
Question No: 35        ( Marks: 5 )
Let we have a class,
class String
{
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String object to
other object. Your code should also avoid self assignment

Answer:
void String::operator = ( const String &other )
 { int length ;
 length = other.length();
delete buf;
 buf = new char [length + 1];
 strcpy( buf, other.buf ); }

Question No: 36         ( Marks: 5 )
Read the given below code and explain what task is being performed by this function
Matrix :: Matrix ( int row , int col )
                             virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU    




                           http://vusolutions.blogspot.com/ 
 
{
    numRows = row ;
    numCols = col ;
    elements = new ( double * ) [ numRows ] ;
    for ( int i = 0 ; i < numRows ; i ++ )
{
        elements [ i ] = new double [ numCols ] ;
        for ( int j = 0 ; j < numCols ; j ++ )
               elements [ i ] [ j ] = 0.0 ;
    }
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols




                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Fall 2009
CS201- Introduction to Programming

Time: 120 min
Marks: 75

If we write a statement like s2 = s1; ___ will be the calling object and ____ will be
passed to the = operator as an argument.
     ► s1, s1
     ► s1, s2
     ► s2, s1
     ► s2, s2
If we write a statement like s2 = s1; s2 will be the calling object and s1 will be
passed to the = operator as an argument. P# 397

cout << setfill(‘0’) << setw(7) << 128 ;

    ►   0000128
    ►   0128128
    ►   1280000
    ►   0012800

default alignment is from left due to this it first prints 4 Zeros(setw=7, digit=3 i.e 1-
2-8,) 7-3=4 Zeros

The stream insertion and extraction operators are not already overloaded for
_______
    ► Built-in data types
    ► User-defined data types
    ► Both built-in and user-defined types
    ► None of the given options

Constructors can not be overloaded like ordinary functions.
    ► True
    ► False

The constructors can be overloaded. We can write as many constructors as we
require. At one time, the compiler will call the correct version of the constructor".P#
323

Overloaded new operator function takes parameter of type size_t and returns
    ► void (nothing)
    ► void pointer
    ► object pointer
    ► int pointer


                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

Also note that the new operator returns a void pointer. Any new operator we write
must have this parameter and return type.


Which of the following is the correct way to declare a variable x of integer type?
    ► x int ;
    ► integer x ;
    ► int x;
    ► x integer

Reserve words cannot be used as a variable name.
    ► True
    ► False
There are few data types in C language. These data types are reserved words of C
language. The reserve words can not be used as a variable manes. P# 17


A template function must have at least ---------- generic data type

    ►   Zero
    ►   One
    ►   Two
    ►   Three

The function arguments must contain at least one generic data type. P# 499


Template functions can also be overloaded
   ► True
   ► False

We can write overloaded template functions as long as there is use of different
number or type of arguments.. P # 503


We can not make a member function of a class as template function.
    ► True
    ► False not sure

When break statement is encountered in switch statement, it
   ► Stops the entire program
   ► Stops the execution of current statement
   ► Exits from switch statement
   ► None of the given options


We can also define a variable of user define data type (object) as static.
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU         




                         http://vusolutions.blogspot.com/ 
 
    ► True
    ► False

The declarator of Plus (+) member operator function is

    ►   Class-Name operator + (Class-Name rhs)
    ►   operator Class-Name + ( )
    ►   operator Class-Name + ( rhs)
    ►   Class-Name operator + ( )

 Let suppose
   int a, b, c, d, e;
  a = b = c = d = e = 42;
This can be interpreted by the complier as:

     ► a = (b = (c = (d = (e = 42))));
     ► (a = b = (c = (d = (e = 42))));
     ► a = b = (c = (d = (e = 42)));
     ► (a = b) = (c = d) = (e = 42);
a = (b = (c = (d = (e = 42) ) ) );


What will be the range of numbers generated by function rand () % 9?
     ► 0 to 9
     ► 1 to 9
     ► 0 to 8
     ► 1 to 8
When 6 divides any number, the remainder will always be less than 6. Ther
result will be between therefore we will add 1. 1 + rand ( ) % 6;
Which of the following is the correct function call having array named student of 10
elements as a parameter.
     ► addRecord(student[]) ;
     ► addRecord(student) ;
     ► addRecord(student[10]) ;
     ► addRecord(*student) ;
when we pass array we don’t give limit of array
Example:
Pass array to function




                            virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU        




                               http://vusolutions.blogspot.com/ 
 
#include<stdio.h>
  #include<conio.h>
  void read(int *,int);
  void dis(int *,int);

    void main()
    {
     int a[5],b[5],c[5],i;

     printf("Enter the elements of first list \n");
     read(a,5);
     printf("The elements of first list are \n");
     dis(a,5);
    }

    void read(int c[],int i)
    {
     int j;
     for(j=0;j<i;j++)
       scanf("%d",&c[j]);
     fflush(stdin);
    }

    void dis(int d[],int i)
    {
     int j;
     for(j=0;j<i;j++)
     printf("%d ",d[j]);
     printf("\n");
    }


Declaring structures does not mean that memory is allocated.
Example:
    ► True
    ► False

structures do not occupy any memory until it is associated with the structure variable

Identifier is a name that can be given to variables, labels and functions.
    ► True
    ► False

An 'Identifier' means any name that the user creates in his/her program. These
names can be of variables, functions and labels



                                 virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
If a class A declares itself a friend of class B and a class B declares itself a friend of
class C then
     ► Class A is also a friend of class C.
     ► Class B is also a friend of class A.
     ► Class A is also a friend of class C if A declares C as its friend.
     ► Class A is also a friend of class C if C declares A as its friend.
If we want a two-way relationship, OtherClass will have to declare ClassOne as a
friend class, resulting in a complete two-way relationship



Which of the following statement is best regarding declaration of friend function?

    ►    Friend function must be declared after public keyword.
    ►    Friend function must be declared after private keyword.
    ►    Friend function must be declared at the top within class definition.
    ►    It can be declared anywhere in class as these are not affected by the
public   and private keywords.



Friend is a very strong statement. It is too strong to be affected by public or
private we can put it anywhere in the class

A pointer is a special type of variable that contain ___________
    ► Memory Address
    ► Data values
    ► Both Values and Memory
    ► None of given of options

Pointer is a special type of variable that contains a memory address.

When memory for a program is allocated at run time then it is called ________

     ► static memory allocation
     ► dynamic memory allocation
     ► stack memory allocation
     ► virtual memory allocation
When we create an object of the class at run time, it will allocate memory according
to our requirement. So there is no waste of memory and the situations in which we
want to store large data in small memory or vice versa are prevented. So we do
dynamic memory allocation inside these classes.

What purpose do classes serve?
   ► Data encapsulation
   ► Providing a convenient way of modeling real-world objects
   ► Simplifying code reuse
   ► All of the given options
                              virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU     




                           http://vusolutions.blogspot.com/ 
 




Which of the following function cannot be overloaded?
     ► Member functions
     ► Utility functions
     ► Constructor
     ► Destructor
The destructors can be summarized as The destructors cannot be overloaded. The
destructors take no arguments. The destructors don’t return a value



The following prototype of unary operator function indicates that it is ____________ .
Date operator++(int )

     ► Member functions of post increment operator
     ► Member functions of pre increment operator
     ► Non-member functions of post increment operator
     ► Non-member functions of pre increment operator
Overloading Unary Operators
// Preincrement operator overloaded as a member function.
Date Date::operator++()
{
  helpIncrement();
  return *this; // value return; not a reference return
}

// Postincrement operator overloaded as a member function.
// Note that the dummy integer parameter does not have a
// parameter name.
Date Date::operator++(int)
{
  Date temp = *this;
  helpIncrement();

    // return non-incremented, saved, temporary object
    return temp; // value return; not a reference return
}



Static variable which is defined in a function is initialized __________.
     ► Only once during its life time
     ► Every time the function call
     ► Compile time of the program
     ► None of the above

                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

Once the static variables are created, they exist for the life of the program. They do
not die.

In the member initialize list, the data members are initialized,
     ► From left to right
     ► From right to left
     ► In the order in which they are defined within class
     ► None of the given options



If we do not indent the code properly it will __________________
     ► Be a syntax error
     ► Be a logical error
     ► Not be an error at all
     ► None of the given options



we Indent the code for better readability and understanding


Truth tables are used for analyzing ___________.
    ► logical expressions
    ► arithmetic expressions
    ► both logical and arithmetic expressions
    ► none of the given options.

The truth tables are very important. These are still a tool available for analyzing
logical expressions.


Static memory allocation is also known as ____________
     ► Dynamic allocation
     ► Compile time allocation
     ► Run time allocation
     ► None of the given options
This type of memory static allocation. It is also known as compile time allocation.



( Marks: 1 )
What does getline() member function of cin stream do?

Another member function of cin is getline(). It reads a complete buffer i.e. the
number of character specified up to a delimiter we specify. We can write something
like:
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
       cin.getline(char *buffer, int buff_size, char delimiter = ‘\n’)
  ( Marks: 1 )
When memory is allocated dynamically using new operator within the
constructor of class then what is an appropriate place to de-allocate the
memory?

Whenever we allocate memory with the new operator, it is our responsibility to de-
allocate this memory after the termination of the program. To do this de-allocation,
we have an operator delete. To de-allocate the memory, allocated with p = new int
; we will write delete

(p) ;
It will not delete the p rather, it will send the memory gotten and pointed by p back
to the free store.
( Marks: 2 )
What will be the output of following code, if user input a number 123?
int input ;
cin >> oct >> input;
cout << hex << input ;


( Marks: 2


What is memory leak?
suppose, the heap size is decreased as we had allocated memory from it despite the
fact that it was never utilized. If this step of allocating memory and then destroy the
pointer to this memory carries on then the size of the heap will going on to decrease.
It may become of zero size. When there is no memory on heap, the computer will
stop running and there may be a system crash. This situation is called a memory leak

( Marks: 3 )
When we call calloc function to allocate memory and its return a NULL
pointer what does it mean?

Calloc function takes two arguments. The first argument is the required space in
terms of numbers while the second one is the size of the space
Now we have to see what happens when either we ask for too much memory at a
time of non-availability of enough memory on the heap or we ask for memory that is
available on the heap , but not available as a single chunk?. In this case, the call to
calloc will fail. When a call to memory allocation functions fails, it returns a NULL
pointer.

( Marks: 3 )
Read the given code and explain code functionality.

Matrix :: Matrix ( const Matrix & m )
{
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU         




                            http://vusolutions.blogspot.com/ 
 
    numRows = m.numRows ;
    numCols = m.numCols ;
    elements = new ( double * ) [ numRows ] ;
    for ( int i = 0 ; i < numRows ; i ++ )
{
      elements [ i ] = new double [ numCols ] ;
      for ( int j = 0 ; j < numCols ; j ++ )
              elements [ i ] [ j ] = m.elements [ i ] [ j ] ;
   }
}
( Marks: 3 )
What is the keyword ‘this’ and what are the uses of ‘this’ pointer?

Whenever an object calls a member function, the function implicitly gets a pointer
from the calling object. That pointer is known as this pointer. ‘this’ is a key word. We
cannot use it as a variable name. ‘this’ pointer is present in the function, referring to
the calling object.
this pointer points to the current object.
 ( Marks: 5 )

What do you mean by garbage collection and how it works in JAVA and C++
?

JAVA gives the concept of garbage collection with the use of references. Due to this
garbage collection, we are free from the headache of de- allocating the memory. We
allocate and use the memory. When it is no longer in use, JAVA automatically deletes
(frees) it through garbage collection But in C and C++ languages, we have to take
care of de-allocating the memory. In classes where we use dynamic memory, we
have to provide destructors to free this memory. The languages keep evolving, new
constructs will keep evolving in existing or new languages.
 ( Marks: 5 )

Explain the concept of separation of interface from the implementation in the context
of classes, using a real world example.
 ( Marks: 10 )

Write a simple program using the get() member function of cin object reading a text
of 30 characters from the keyboard, store them in an array and then
using put() member function of cout object to display them on the screen.
 ( Marks: 10 )

Overload the Binary Assignment (=) Operator.
Write a program which has a class List, This class should have Two data members,
an array of integers list[] and an integer variable length (i.e. number of elements in
the list).The class should further contain a default constructor, a Print() function
which display the list and a Functioninsert() which insert an element in the list
and Assignment (= ) Operator function, which contain code for the assignment of
one object to other. .
                               virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
In main function define two objects list1 and list2 and use the statement list2 =
list1; and use (call ) print function with both objects




                           virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming

Question No: 1( Marks: 1 ) - Please choose one
There are mainly -------------------- types of software
 ► Two
 ► Three
 ► Four
 ► Five
Software is categorized into two main categories
System Software
Application Software

Question No: 2( Marks: 1 ) - Please choose one
When x = 7; then the expression x%= 2; will calculate the value of x as,
►1
►3
►7
►2

\Question No: 3( Marks: 1 ) - Please choose one
 A pointer variable can be,
 ► Decremented only
 ► Incremented only
 ► Multiplied only
 ► Both 1 and 2
Question No: 4( Marks: 1 ) - Please choose one
setprecision is a parameter less manipulator.
 ► True
 ►False
Question No: 5( Marks: 1 ) - Please choose one
 We can change a Unary operator to Binary operator through operator overloading.
 ►False
 ► True
Question No: 6( Marks: 1 ) - Please choose one
delete operator is used to return memory to free store which is allocated by
the new operator
 ► True
 ►False
The objects are created with the new operator on free store, they will not be
destroyed and memory will not be de-allocated unless we call delete operator to
destroy the objects and de-allocate memory.
Question No: 7( Marks: 1 ) - Please choose one
When we do dynamic memory allocation in the constructor of a class, then it is
necessary to provide a destructor.
 ► True
 ►False
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
whenever we have a class in which the constructor allocates dynamic memory, it is
necessary to provide a destructor that frees the memory.
Question No: 8( Marks: 1 ) - Please choose one
What is the functionality of the following statement?
String str[5] = {String(“Programming”), String(“CS201”)};
 ► Default constructor will call for all objects of array
 ► Parameterized constructor will call for all objects of array
 ► Parameterized constructor will call for first 2 objects and default
constructor for remaining objects
 ► Default constructor will call for first 3 objects and Parameterized constructor for
remaining objects


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

What is the sequence of event(s) when allocating memory using new operator?
 ► Only block of memory is allocated for objects
 ► Only constructor is called for objects
 ► Memory is allocated first before calling constructor
 ► Constructor is called first before allocating memory
·
If a single object is allocated, operator new is called to allocate memory, and then
the constructor is called to initialize the object.
·               If an array of objects is allocated, operator new[] is called to allocate
memory for the whole array, and then the constructor is called for each element of
the array.
·               When a single object is deleted, the destructor for the object is called
first, and then operator delete is called to free the memory occupied by the object.
·               When an array of objects is deleted, the destructor for each element
of the array object is called first, and then operator delete[] is called to free the
memory occupied by the array.

Question No: 10( Marks: 1 ) - Please choose one
Deleting an array of objects without specifying [] brackets may lead to memory leak
 ► True
 ►False
Question No: 11( Marks: 1 ) - Please choose one
Which of the following data type will be assumed if no data type is specified with
constant?
 ► short
 ► float
 ► int
 ► double

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

There is an array of characters having name ‘course’ that has to be initialized by
string ‘programming’ which of the following is the correct way to do this,
                             virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU             




                               http://vusolutions.blogspot.com/ 
 
i. course[] = {‘p’, ’r’, ’o’, ’g’, ’r’, ’a’, ’m’, ’m’, ’i’, ’n’, ’g’};
ii.course[] = ‘programming’ ;
iii. course[12] = “programming” ;
iv. course = “programming” ;
Choose the correct options.
 ► (i) and (ii) only
 ► (i) and (iv) only
 ► (i) and (iii) only
 ► (ii) and (iii) only


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

What will be the correct syntax of the following statement?
ptr is a constant pointer to integer.
 ► const int *ptr ;
 ► const *int ptr ;
 ► int const *ptr ;
 ► int *const ptr ;
The keyword const for pointers can appear before the type, after the type, or in both
places. The following are legal declarations:
const int * ptr1;     /* A pointer to a constant integer:
                     the value pointed to cannot be changed */
int * const ptr2;     /* A constant pointer to integer:
                     the integer can be changed, but ptr2
                     cannot point to anything else        */
const int * const ptr3; /* A constant pointer to a constant integer:
                     neither the value pointed to
                     nor the pointer itself can be changed */
Declaring an object to be const means that the this pointer is a pointer to
a const object. A const this pointer can by used only with const member functions


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

Overloaded member operator function is always called by _______
 ► Class
 ► Object
 ► Compiler
 ► Primitive data type
As discussed in the example of overloaded functions, the automatic part is also there.
But we wrote all those functions separately. Here the automatic part is even deeper.
In other words, we write one template function without specifying a data type. If it is
to be called for int data type, the compiler will itself write an int version of that
function. If it is to be called for double, the compiler will itself write it. This does not
happen at run time, but at compile time. The compiler will analyze the program and
see for which data type, the template function has been called. According to this, it
will get the template and write a function for that data type. P# 498
                                   virtual.uni.help@gmail.com 
              CS201 Solved Past Papers GURU 
                                            




                         http://vusolutions.blogspot.com/ 
 
Question No: 15( Marks: 1 ) - Please choose one
Loader loads the executable code from hard disk to main memory.
 ► True
 ►False
Loader fter a executable program is linked and saved on the disk and it is ready for
execution. We need another process which loads the program into memory and then
instruct the processor to start the execution of the program from the first instruction
(the starting point of every C program is from the main function). This processor is
known as loader. P# 13
Question No: 16( Marks: 1 ) - Please choose one
Which of the following is the correct C++ syntax to allocate space dynamically for an
array of 10 int?

 ► new int(10) ;
 ► new int[10] ;
 ► int new(10) ;
 ► int new[10];
For example, we want to allocate an array of 10 ints dynamically. Then the statement
will be like this: int *iptr; iptr = new int[10]; P# 332
Question No: 17( Marks: 1 ) - Please choose one
The prototype of friend functions must be written ____ the class and its definition
must be written ____

 ► inside, inside the class
 ► inside, outside the class
 ► outside, inside the class
 ► outside, outside the class
So their definition will be always outside the class. However, the prototype of the
function will be written in the class. P#346

Question No: 18( Marks: 1 ) - Please choose one
Like member functions, ______ can also access the private data members of a class.
 ► Non-member functions
 ► Friend functions
 ► Any function outside class
 ► None of the given options
If a data is private, it will be available only to member functions of the class. No
other function outside the class (except friend functions) can access the private data.
P# 320

Question No: 19( Marks: 1 ) - Please choose one
To perform manipulation with input/output, we have to include _____ header file.

    ►   iostream.h
    ►   stdlib.h
    ►   iomanip.h
    ►   fstream.h

                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
To do stream manipulations, we have to include a header file having the
name iomanip.h. We can understand that iomanip is a short hand for input output
manipulation. P# 427
Question No: 20( Marks: 1 ) - Please choose one
The endl and flush are _______

 ► Functions
 ► Operators
 ► Manipulators
 ► Objects
Similarly flush was a manipulator for which we could write cout << flush that means
flushing the output buffer. So it manipulates the output.
P # 435 / 436
Question No: 21( Marks: 1 ) - Please choose one
 If we want to use stream insertion and extraction operators with _______ then we
have to overload these operators.
 ► int, float, double
 ► objects of class
 ► int, float, object
 ► int, char, float


stream extraction operator is used with different data types of int, double and float.
The three lines given above can be written in one cascading line: cin >> i >> d >> f;

In order to use these insertion ( << ) and extraction ( >> ) operators with classes,
we have to overload these operators.

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

The static data members of a class can be accessed by ________
 ► only class
 ► only objects (not sure ) .....
 ► both class and objects
 ► none of given options

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

Classes defined inside other classes are called ________ classes
 ► looped
 ► nested
 ► overloaded
 ► none of the given options.
we can have structures or classes defined inside classes. Classes defined within other
classes are called nested classes


Question No: 24( Marks: 1 ) - Please choose one
                            virtual.uni.help@gmail.com 
                CS201 Solved Past Papers GURU     




                                http://vusolutions.blogspot.com/ 
     

    Which value is returned by the destructor of a class?
    ► A pointer to the class.
    ► An object of the class.
    ► A status code determining whether the class was destructed correctly
    ► Destructors do not return a value.


    Destructors obey the following syntactical requirements:

•   a destructor's name is equal to its class name prefixed by a tilde;
•   a destructor has no arguments;
•   a destructor has no return value.


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

    Consider the following code segment
    class M {
     friend int operator!(const M &);
    ...
    };
    !s // code of line implies that operator!(s)
    ...
    Let assume if s is an object of the class then function is implemented as
    ___________
     ► Member function
     ► Non-member function
     ► Binary operator function
     ► None of the given options
    None of the given options


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

    When the compiler overloads the assignment (=) operator by default then
    __________


        ► compiler does member wise assignment.

        ► compiler does not allow default overload of assignment (=) operator
        ► member of the class are not assigned properly
        ► None of the given options


    Assignment Operator

                                   virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
At first, we ascertain whether there is need of an assignment operator or not? It is
needed when we are going to assign one object to the other, that means when we
want
to have expression like a = b. C++ provides a default assignment operator. This
operator does a member-wise assignment.

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

If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
 ► Creates an array of 5 string objects statically
 ► Creates an array of 5 string objects dynamically
 ► Creates an array of pointers to string
 ► Creates a string Object



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

Static variable which is defined in a function is initialized __________.
 ► Only once during its life time
 ► Every time the function call
 ► Compile time of the program
 ► None of the above
When you declare a static variable (native data type or object) inside a function, it is
created and initialized only once during the lifetime of the program


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

The appropriate data type to store the number of rows and is____________.
 ► floatcolums of the matrix
 ► int
 ► char
 ► none of the given options.


Int is right becuase columns and row cannot be in fractions

Question No: 30( Marks: 1 ) - Please choose one
Copy constructor becomes necessary while dealing with _______allocation in the
class.
 ► Dynamic memory
 ► Static memory
 ► Both Dynamic and Static memory
 ► None of the given options
Copy constructor becomes necessary while dealing with dynamic memory allocation in
the class
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 



Question No: 31( Marks: 1 )

What is drawback of writing the definitions of all the functions before main function?
Question No: 32( Marks: 1 )
How do we provide the default values of function parameters?
Question No: 33( Marks: 2 )
What is difference between endl and \n?
Question No: 34( Marks: 2 )
When does an object get destroyed?
Question No: 35( Marks: 3 )
What is the difference between structure and class?
Question No: 36( Marks: 3 )
What will be the output of following functions if we call these functions three times?
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Question No: 37( Marks: 3 )
Why stream insertion and stream extraction operators cannot be overloaded as
member functions?

Question No: 38( Marks: 5 )
What is difference between Unary and binary operators and how they can be
overloaded?
Question No: 39( Marks: 5 )
What steps we must follow to design good program?
Question No: 40( Marks: 10 )
Write the program that inputs an octal number from the user and then display the
entered octal number into hexadecimal number using manipulators (parameter-
less, parameterized) and member function of input/output streams.

Question No: 41( Marks: 10 )
Develop a class Vector having two data members; x and y.
The class should also provide the following Overloaded operator capabilities.
a) Overload the addition operator(+) to add two Vectors
b) Overload the assignment operator(=) to assign Resultant Vector
c) Write function Display() to display x, y coordinates

                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
Note:Addition of vector Let suppose there are two vectors A and B with their x, y
coordinates.




                           virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
FINALTERM EXAMINATION
Fall 2008
CS201- Introduction to Programming

Question No: 1      ( Marks: 1 ) - Please choose one
There are mainly -------------------- types of software
    ► Two
    ► Three
    ► Four
    ► Five

Software is categorized into two main categories
o System Software
o Application Software P# 9
Question No: 2       ( Marks: 1 ) - Please choose one
seekg() and write() are functionally _________________ .
    ► Different
    ► Identical
    ► Two names of same function
     ► None of the above

Question No: 3       ( Marks: 1 ) - Please choose one
When a pointer is incremented, it actually jumps the number of memory addresses
    ► According to data type
    ► 1 byte exactly
    ► 1 bit exactly
    ► A pointer variable can not be incremented
“When a pointer is incremented, it actually jumps the number of memory spaces
according to the data type that it points to”
Question No: 4       ( Marks: 1 ) - Please choose one

setw is a parameterized manipulator.
    ► True
    ► False

We have a manipulator setw (a short for set width), it takes as an argument the
width in number of spaces. So to print our numbers in four spaces we write cout <<
setw(4) << number ;
Question No: 5       ( Marks: 1 ) - Please choose one
eof( ), bad( ), good( ), clear( ) all are manipulators.
     ► True
     ► False
Stream Manipulations P# 433

Question No: 6       ( Marks: 1 ) - Please choose one
In functions that return reference, use __________variables.
     ► Local
     ► Global
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
     ► Global or static
     ► None of the given option
In functions that return reference, use global or static variables. P# 369

Question No: 7       ( Marks: 1 ) - Please choose one
The declarator of Plus (+) member operator function is
    ► Class-Name operator + (Class-Name rhs)
    ► operator Class-Name + ( )
    ► operator Class-Name + ( rhs)
    ► Class-Name operator + ( )

Page 371,373 example are here
Complex operator + (Complex & );
Complex operator + (parameter-list);
The syntax of the prototype of the overloaded operator function is:
return-type operator operator-symbol (parameter-list);
operator is the keyword here. An example of this will be as follows:
Complex operator + (Complex & );
Question No: 8       ( Marks: 1 ) - Please choose one
The compiler does not provide a copy constructor if we do not provide it.
     ► True
     ► False
C will provide the default copy constructor. P#476

Question No: 9       ( Marks: 1 ) - Please choose one
What is the functionality of the following syntax to delete an array of 5 objects
named arr allocated using new operator?
delete arr ;
     ► Deletes all the objects of array
     ► Deletes one object of array
     ► Do not delete any object
     ► Results into syntax error
This statement will call the destructor only for the object pointed by the arr and
deallocate        the        space       allocated       to       this      object

Question No: 10       ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when allocating memory using new operator?
     ► Only block of memory is allocated for objects
     ► Only constructor is called for objects
     ► Memory is allocated first before calling constructor
     ► Constructor is called first before allocating memory
For new operator, memory block is allocated first before calling the constructor.
P#414

Question No: 11      ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when deallocating memory using delete operator?
   ► Only block of memory is deallocated for objects
   ► Only destructor is called for objects
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 
     ► Memory is deallocated first before calling destructor
     ► Destructor is called first before deallocating memory
For delete operator, destructor for the object is called first and then the memory
block is deallocated. P# 414

Question No: 12    ( Marks: 1 ) - Please choose one
new and delete operators cannot be overloaded as member functions.
   ► True
   ► False

The overloaded new operator returns void * when it is overloaded as non-member
(global). However, it returns an object pointer like the built-in new operator, when
overloaded as a member function. P# 414
Question No: 13       ( Marks: 1 ) - Please choose one
The operator function of << and >> operators are always the member function of a
class.
     ► True
     ► False

there are two ways of overloading operators, either as class members or non-
members. But these insertion ( << ) and extraction ( >> ) operators cannot be
overloaded as members. P#446
Question No: 14        ( Marks: 1 ) - Please choose one
A template function must have at least ---------- generic data type
     ► Zero
     ► One
     ► Two
     ► Three
We generally use the variable name as T (T evolves from template). However, it is
not something hard and fast. After the variable name, we start writing the function
definition. The function arguments must contain at least one generic data type. P#
499


Question No: 15     ( Marks: 1 ) - Please choose one
If we do not mention any return_value_type with a function, it will return
an _____ value.
    ► int
    ► void
    ► double
    ► float
The default return_value_type is of int data type i.e. if we do not mention
any return_value_type with a function, it will return an int value. P# 79


Question No: 16    ( Marks: 1 ) - Please choose one
Suppose a program contains an array declared as int arr[100]; what will be the size
of array?
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
    ►0
    ► 99
    ► 100
    ► 101

As we know, the array index is one less than the size of the array. P# 103
The size of array is 100. but it's index will be from 0 to 99. we will initlize all the
elements of the array to 0.
Question No: 17        ( Marks: 1 ) - Please choose one
The name of an array represents address of first location of array element.
      ► True
      ► False
The name of the array is a constant pointer which contains the memory is the address
of first element of the array



Question No: 18       ( Marks: 1 ) - Please choose one
Reusing the variables in program helps to save the memory
    ► True
    ► False
Question No: 19       ( Marks: 1 ) - Please choose one
Which of the following option is true about new operator to dynamically allocate
memory to an object?
    ► The new operator determines the size of an object
    ► Allocates memory to object and returns pointer of valid type
    ► Creates an object and calls the constructor to initialize the object
    ► All               of              the                given           options


Question No: 20       ( Marks: 1 ) - Please choose one
new and delete are _____ whereas malloc and free are _____.
     ► Functions, operators
     ► Classes, operators
     ► Operators, functions
     ► Operators, classes
Hence,       we         can       call new and delete operators,     P#        342
we have allocated a memory space for our use by malloc function. P# 285
Question No: 21       ( Marks: 1 ) - Please choose one
Like member functions, ______ can also access the private data members of a class.
     ► Non-member functions
     ► Friend functions
     ► Any function outside class
     ► None of the given options
The friend functions of a class have access to the private data members of class

Question No: 22       ( Marks: 1 ) - Please choose one
Which of the following statement is best regarding declaration of friend function?
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
     ► Friend function must be declared after public keyword.
     ► Friend function must be declared after private keyword.
     ► Friend function must be declared at the top within class definition.
     ► It can be declared anywhere in class as these are not affected by the
public and private keywords.
To declare a friend function, we can put it anywhere in the class. According to the
definition of the friend functions, they have access to the private data members of the
class.

Question No: 23       ( Marks: 1 ) - Please choose one
The operator function overloaded for an Assignment operator (=) must be
    ► Non-member function of class
    ► Member function of class
    ► Friend function of class
    ► None of the given options

Restrictions on Operator Overloading
The operator overloading functions for overloading (), [], -> or the assignment (=)
Operators must be declared as class members.

Question No: 24        ( Marks: 1 ) - Please choose one
For non-member operator function, object on left side of the operator may be
     ► Object of operator class
     ► Object of different class
     ► Built-in data type
     ► All of the given options

When an operator function is implemented as a non-member function, the left-most
operand may be an object of the operator’s class, an object of a different class, or a
built-in type. Now we discuss it in a detailed manner. (handouts)

Question No: 25      ( Marks: 1 ) - Please choose one
The operator function will be implemented as _____, if obj1 drive the - operator
whereas obj2 is passed as arguments to - operator in the statement given below.
obj3 = obj1 - obj2;
    ► Member function
    ► Non-member function
    ► Friend function
    ► None of the given options

For member operator, the object on the left side of the + operator is driving
this + operation. Therefore, the driving object on the left is available by this pointer
to + operator function. But the object on the right is passed explicitly to
the + operator as an argument.
Question No: 26       ( Marks: 1 ) - Please choose one
Which one of the following is the declaration of overloaded pre-increment operator
implemented as member function?
     ► Class-name operator +() ;
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
    ► Class-name operator +(int) ;
    ► Class-name operator ++() ;
    ► Class-name operator ++(int) ;

Question No: 27      ( Marks: 1 ) - Please choose one
The static data members of a class are initialized _______
    ► At file scope
    ► within class definition
    ► within member function
    ► within main function

 Initialization of static data members is done at file scope which means almost at the
global scope. We initialize it outside of the main.
Question No: 28          ( Marks: 1 ) - Please choose one
Class is a user defined___________.
      ► data type
      ► memory referee
      ► value
      ► none of the given options.



A class is a user defined data type and it can be used inside other classes in the same
way as native data types are used.
Question No: 29        ( Marks: 1 ) - Please choose one
We can also define a user-defines manipulators.
     ► True
     ► False
Parameterized manipulators require one or more arguments. setfill (near the bottom
of the iomanip.h header file) is an example of a parameterized manipulator. You can
create your own parameterized manipulators and your own simple manipulators.

Question No: 30       ( Marks: 1 ) - Please choose one
Automatic variable are created on ________.
    ► Heap
    ► Free store
    ► static storage
    ► stack

On the stack, automatic variables are being created and destroyed all the time
Question No: 31      ( Marks: 1 )
How do we provide the default values of function parameters?

Question No: 32      ( Marks: 1 )
Why do java consider pointer as dangerous
JAVA, describe pointers as dangerous . if we assign a memory through a pointer
where the pointer is destroyed, the memory remains allocated and is wasted. To
address these things, there are only references in JAVA instead of pointers. JAVA
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
gives the concept of garbage collection with the use of references. Due to this
garbage collection, we are free from the headache of de- allocating the memory. We
allocate and use the memory. When it is no longer in use, JAVA automatically deletes
(frees) it through garbage collection

Question No: 33       ( Marks: 2 )
What is memory leak?
There is a requirement that if the constructor of a class allocates the memory, it is
necessary to write a destructor of that class. We have to provide a destructor for that
class, so that when that object ceases to exist, the memory allocated by the
constructor, is returned to the free store. It is critically important. Otherwise, when
the object is destroyed, there will be an unreferenced block of memory. It cannot be
used by our program or by any other program. It’s a memory leak that should be
avoided.

Question No: 34        ( Marks: 2 )
What does optimization the of code means?
Optimization is the process of transforming a piece of code to make more efficient
without changing its output or side-effects. The only difference visible to the code’s
user should be that it runs faster and/or consumes less memory.

Question No: 35     ( Marks: 3 )
What is the difference between structure and class?


The ONLY DIFFERENCES between classes and structures are

1) classes DEFAULT to having private members. Structures DEFAULT to having
public members. These defaults can be changed so classes can be made to work like
structures and vice versa.

2) classes DEFAULT to inheriting privately from base classes. Structures DEFAULT to
inheriting public from base classes. These defaults can be changed so classes can be
made to work like structures and vice versa.

Question No: 36       ( Marks: 3 )
See the following code segment.
template
class myclass {
private:
T x;
public:
myclass (T a) {
 x = a;
}
};
Write the main function which creates two objects of class for int and double data
types.
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 

Question No: 37         ( Marks: 3 )
Is it possible to define two functions as given below? Justify your answer.
func(int x, int y)
func(int &x, int &y)

Question No: 38      ( Marks: 5 )
Write a program using getline() member function to inputs a string up to delimiter
character comma (,) and then display the string on the screen.

Question No: 39       ( Marks: 5 )
Do you think that friend functions violate encapsulation? Justify your answer.

Question No: 40      ( Marks: 10 )
Write a simple program using the get() member function of cin object reading a text
of 30 characters from the keyboard, store them in an array and then
using put() member function of cout object to display them on the screen.

Question No: 41      ( Marks: 10 )
Write  a   small    program    which   defines two   user-defined  manipulators
named octal and hexadecimal. These manipulators should display the decimal
numbers into octal and hexadecimal.
In the main function, input a decimal number from the user and then display this
decimal number into octal and hexadecimal using user-define manipulators
named octal and hexadecimal.




                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming

Question No: 1      ( Marks: 1 ) - Please choose one
C language is developed by
► Bill Gates
► Robert Lafore
► Dennis Ritchie
► Deitel & Deitel



Question No: 2       ( Marks: 1 ) - Please choose one
Which of the following choice is not an example of an int datatype?
►0
► -32
► 65531
► -4.0



Question No: 3       ( Marks: 1 ) - Please choose one
In flow chart, the symbol used for decision making is,
► Rectangle
► Circle
► Arrow
► Diamond



Question No: 4      ( Marks: 1 ) - Please choose one
Switch statement deals with,
► Integer data only
► float data only
► character data only
► Integer and character data



Question No: 5       ( Marks: 1 ) - Please choose one
Default case in switch statement is,
► Must
► Optional
► syntax error
► Necessary


                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 




Question No: 6     ( Marks: 1 ) - Please choose one
*.doc is _____________ by type.
.
► Sequential File
► Random Access File
► Data File
► Record File



Question No: 7      ( Marks: 1 ) - Please choose one
Member function tellg() returns the current location of the _____________ pointer.
► tellptr()
► write()
► seekg()
► get()



Question No: 8      ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical
method
► True
► False



Question No: 9      ( Marks: 1 ) - Please choose one
In C/C++ all character strings are terminated with,
► Null character
► String
► Zero
► Full stop



Question No: 10      ( Marks: 1 ) - Please choose one
Word processor is
► Operating system
► Application software
► Device driver
► Utility software




                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU     




                          http://vusolutions.blogspot.com/ 
 
Question No: 11       ( Marks: 1 ) - Please choose one
Which of the following can not be a variable name?
► area
► _area
► 10area
► area2



Question No: 12       ( Marks: 1 ) - Please choose one
Which looping process is best, when the number of iterations is known?
► for
► while
► do-while
► all looping processes require that the iterations be known



Question No: 13       ( Marks: 1 ) - Please choose one
By default an array of characters is passed by value to a function,
► True
► False



Question No: 14       ( Marks: 1 ) - Please choose one
Which of the following operator is used to access the address of a variable?
► * operator
► -> operator
► && operator
► & operator



Question No: 15      ( Marks: 1 ) - Please choose one
The name of an array represents address of first location of array element.
► True
► False



Question No: 16   ( Marks: 1 ) - Please choose one
Let suppose
Union intorDouble{
Int ival;
Double charvar;
};
main(){
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
intorDouble VAZ;
int size ;
size = sizeof(VAZ);
}
What will be the value of variable "size", if int occupies 4 bytes and double occupies
 8 bytes?
►2
►4
►8
► 12



Question No: 17          ( Marks: 2 )
What is the difference between for loop and while loop?
Question No: 18          ( Marks: 2 )
Consider the structure
struct Customer
{
       int custnum;
       int salary;
       float commission;
};
A programmer wants to assign 2000 for the structure member salary in the above
example of structure Customer with structure variable cust1 What line of code should
he write
Question No: 19          ( Marks: 2 )
When a pointer is incremented then how many bytes will it move to change its
address?
Question No: 20          ( Marks: 3 )
If there are 2n elements in an array then what would be the number of iterations
required to search a number using binary search and linear search?
Question No: 21          ( Marks: 3 )
Perform left shift operation on a binary number 0101 and write the result in binary
and decimal.
Question No: 22          ( Marks: 5 )
What will be the output of following code segment?
void func(int [], int);
main(){
int arr[5] = {2, 3, 5, 6, 7} ;
func(arr, 5) ;
for (int i = 0; i<5; i++)
cout << arr[i] << “ ”;
}
void func(int a[], int size){
for (int i = 0; i<size; i++)
a[i] = 2*a[i];
}
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Question No: 23      ( Marks: 5 )
What is random access file and how data can be read and write into random access
file?
MIDTERM EXAMINATION
Spring 2010
CS201- Introduction to Programming


Question No: 1      ( Marks: 1 ) - Please choose one
In C/C++ the string constant is enclosed
► In curly braces
► In small braces
► In single quotes
► In double quotes

In fact, C's only truly built-in string-handling is that it allows us to use string
constants (also called string literals) in our code. Whenever we write a string,
enclosed in double quotes, C automatically creates an array of characters for us,
containing that string, terminated by the \0character. For example, we can declare
and define an array of characters, and initialize it with a string constant:

          char string[] = "Hello, world!";
Question No: 2       ( Marks: 1 ) - Please choose one
For one byte there are _____ combinations of values that can be stored in computer.
► 26
► 27
► 28
► 24

Question No: 3      ( Marks: 1 ) - Please choose one
Switch statement deals with,
► Integer data only
► float data only
► character data only
► Integer and character data

Question No: 4       ( Marks: 1 ) - Please choose one
A record is a group of related _____________.
► Files
► Bytes
► Fields
► Data

Question No: 5      ( Marks: 1 ) - Please choose one
C++ views each file as a sequential stream of _______________.
► Bytes
► Bits
► 0’s or 1’s
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 
► Words

http://books.google.com/books?id=3tvRMQEq2f4C&pg=PA420&lpg=PA420&dq=C%2
B%2B+views+each+file+as+a+sequential+stream+of&source=bl&ots=DYfDhp-
FoE&sig=HLa4f0MbMU85du1EPEBnIgovCL0&hl=en&ei=paj-S5C9DdG-
rAebm6C9Dg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBIQ6AEwAA#v=o
nepage&q&f=false

Question No: 6         ( Marks: 1 ) - Please choose one
To access the element of two dimensional array we use,
► Single referencing
► Single dereferencing
► Double dereferencing
► Double referencing
to access the elements of the two-dimensional array, we do double dereferencing like
**multi'.
Question No: 7         ( Marks: 1 ) - Please choose one
If it is required to copy an array to another array then,
► Both arrays must be of the same size and data type
► Both arrays may be of different size
► Both arrays may be of different data type
► Both arrays may be of different size and type

Question No: 8        ( Marks: 1 ) - Please choose one
The precedence of * is higher than dot operator (.)operator
► True
► False
Postfix operators have the highest precedence .
(.) operator is post prefix variable so it has higher precedence over *
Question No: 9        ( Marks: 1 ) - Please choose one
Pointers works by pointing to a data type, which can be of the form,
► Integer only
► double only
► character only
► All of the given options
Question No: 10         ( Marks: 1 ) - Please choose one
Which of the following data type(s) can operate on modulus operator ‘%’?
► float, int
► float, double
► int
► char
There is a restriction in C language while using the modulus operator.
it can operator only on integers and cannot operate on floats or double
Question No: 11         ( Marks: 1 ) - Please choose one
What will be the output of following code?
int x = 10 ;
cout << “x =” << x ;
► 10
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
► “x=10”
► x=10
► 10=x
Question No: 12       ( Marks: 1 ) - Please choose one
Which looping process checks the test condition at the end of the loop?
► for
► while
► do while
► no looping process checks the test condition at the end
Question No: 13       ( Marks: 1 ) - Please choose one
What will be the correct syntax of the following statement?
ptr is a constant pointer to integer.
► const int *ptr ;
► const *int ptr ;
► int const *ptr ;
► int *const ptr ;
http://books.google.com/books?id=hwpqHb5NBSoC&pg=PA357&lpg=PA357&dq=ptr+
is+a+constant+pointer+to&source=bl&ots=7JBdNwevtW&sig=dstpjCzWgYkwihQL85r
_hn-ORhM&hl=en&ei=Z6z-S_mPI8-
2rAfrpszkDg&sa=X&oi=book_result&ct=result&resnum=10&ved=0CEoQ6AEwCQ#v=o
nepage&q=ptr%20is%20a%20constant%20pointer%20to&f=false

Question No: 14      ( Marks: 1 ) - Please choose one
A function must always return value.
► True
► False

Question No: 15      ( Marks: 1 ) - Please choose one
C is a/an ______ language
► low level
► object based
► object oriented
► function oriented

Question No: 16       ( Marks: 1 ) - Please choose one
Assignment operator is used for ___________.
► calculation
► reading
► assigning value to variables
► None of the given options.

Question No: 17       ( Marks: 2 )
What is the difference between switch statement and if statement.
ANSWER:
SWITCH:
The switch structure is a multi selection construct that is used in multi way
decision
IF:
                          virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
If statement is computationally one of the most expensive statements in
programe
Question No: 18    ( Marks: 2 )
What is wrong with following code and also give the reason of error?
int x , y ;
int *ptr1 = &x ;
int *ptr2 =&y ;
ptr1+ptr2 ;
Answer:
We need one more variable in which we put sum of ptr1 and ptr2 like
Int z;
z=ptr1+ptr2;

Question No: 19       ( Marks: 2 )
Which bit of the number is used as a sign bit?
Answer:
The most significant bit of the number is used as a sign bit (to denote the sign of the
number).

Question No: 20          ( Marks: 3 )
What is the difference between tellg() and tellp() functions?
ANSWER:
tellg():function gives us the current get position of the file pointer. It returns a whole
number of type long, which is the position of the next character to be read from that
file.
tellp():
tellp() function is used to determine the next position to write a character while
writing into a file. It also returns a long number

Question No: 21       ( Marks: 3 )
What is difference between variable and pointer?
Answer:
Variable:
Variables are used for easiness of program we put variable name and give some value
and in later
variable names are used instead of value
Pointers:
But in pointers instead of passing variables(value) we pass their addresses and & is
used to get the address.

Question No: 22     ( Marks: 5 )
What happened when we try to copy the array ‘arr1’ into the array ‘arr2’ in the
following code segment, justify your answer?
 main()
 {
 int arr1[3]={2,3,5};
 int arr2[3];
 arr2=arr1;
                              virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
 }
Answer:
 We can not copy array directly in this way (arr2=arr1;)
Each member of arr1 to be copied by each member of arr2.
We can use for loop to copy array 1 to array2
Question No: 23         ( Marks: 5 )
Differentiate between random access and sequential access file?
Answer:
Random access file:
Random access files are not in sequence mean its not necessary put that’s thing first
that written first
we put any thing from file any where
So tellg() and tellp() are the two very useful functions while reading from or
writing into the files at some certain position.
Sequential access file:
Sequential access files are simple character files. while working with the
sequential access files we write in a sequence not in a random manner




                            virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU   




                         http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming

Question No: 1      ( Marks: 1 ) - Please choose one
In C/C++ the #include is called,
   ►Header file
   ►Preprocessor Directive
   ►Statement
   ►Function
Question No: 2      ( Marks: 1 ) - Please choose one
When the logical operator AND (&&) combine two expressions exp1
and exp2 then the result will be true only,
   ►When both exp1 and exp2 are true
   ►When both exp1 and exp2 are false
   ►When exp1 is true and exp2 is false
   ►When exp1 is false and exp2 is true
Question No: 3      ( Marks: 1 ) - Please choose one
Header file: fstream.h includes the definition of the stream classes.

    ►ifstream, fstream, cout
      ►ifstream, fstream, ofstream
      ►fstream, cin, cout
      ►None of the above

Question No: 4        ( Marks: 1 ) - Please choose one
How many parameter(s) function getline() takes?
    ►0
    ►1
    ►2
    ►3
istream& istream::getline( char* buffer, streamsize num, char delim );
Question No: 5        ( Marks: 1 ) - Please choose one
Disks is divided into ____________ with power of__________.
Chunks, 2
Chunks, 2n
Blocks, n2
Blocks, 2n

Question No: 6      ( Marks: 1 ) - Please choose one
Function seekg() takes ____________ parameter(s).
0
1
2
3
istream& seekg ( streamoff off, ios_base::seekdir dir );
Question No: 7      ( Marks: 1 ) - Please choose one
Keyword ‘array’ must be used to declare an array.
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU          




                            http://vusolutions.blogspot.com/ 
 
    ► True
    ► False
Question No: 8       ( Marks: 1 ) - Please choose one
What will be the value of x after executing following
switch(x)
 { case 1:
       x += 1 ;
       break ;
case 2:
       x += 2
; case 3:
       x +=3 ;
       break ; }
    ►2
    ►4
    ►5
    ►7
    it wil be 7 as every case will add value to x
Question No: 9       ( Marks: 1 ) - Please choose one
When a function finishes its execution then,
    ► The control return to its Prototype
    ► The control returns to its definition
    ► Control returns to statement following function call
    ► The compiler stop execution of whole program
Question No: 10       ( Marks: 1 ) - Please choose one
What will be the output of following code segment?
main(){
int x = 5 ;
{
int x = 4 ;
cout << x << “,” ;
}
cout << x ;
}



   ► 4, 4
   ► 4, 5
   ► 5, 4
   First call of x read local value which is 4 and next call is to x has value of 5
Question No: 11          ( Marks: 1 ) - Please choose one
When an array element is passed to a function then this array
element is pass function,
By reference
By data type
By value
By data
                                virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 

A single array element is like a variable, so when an array element is passed to a
function, then by default it is passed by val



Question No: 12       ( Marks: 1 ) - Please choose one
Which of the following operator is used to access the value of variable pointed to by
a pointer?
    ►* operator
    ►-> operator
    ►&& operator
    ►& operator
Question No: 13       ( Marks: 1 ) - Please choose one
The      also belong to the System Software category.
    ►True
    ►False
Question No: 14       ( Marks: 1 ) - Please choose one
The argument of the isdigit() function is
    ►a character,
    ►a C-string,
    ►a C++ string class variable
    ►None of the given options.
Question No: 15       ( Marks: 1 ) - Please choose one
Declaring structures does not mean that memory is allocated.
    ►True
    ►False
Question No: 16       ( Marks: 1 ) - Please choose one
A union is a user-defined data type that contains only__________ from its list of
members at
a time.
    ► One object
    ► Two objects
    ► ► Three objects
    ► None of the given options
    Question No: 17       ( Marks: 1 )
What does 7 ^ 5 evaluate to in decimal and binary?
Question No: 18       ( Marks: 1 )
How can we evaluate a program?
Then the program should be evaluated by testing and checking
Question No: 19       ( Marks: 2 )
Which variable will be used in inner code block if we have the same names of variable
at
outer code block and inner code block?
It will use inner block variable
Question No: 20       ( Marks: 3 )
What will happen if we omit braces within loop?

                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Loop will execute only single immediate line and complete the iteration. You can not
run group of lines without use of curly braces.
Question No: 21          ( Marks: 5 )
Read the program below and write the output.
#include
main()
{
ofstream outfile;
char outfilename[] = “abc.txt”;
char outputtext[50] = “Welcome to VU”
outfile.open(outfilename, ios::out);
if(!outfile)
 {
  cout<<”Error Occured”;
  exit(1);
 }
outfile<<"Hello
Buddies..."<outfile.close(); }
Program should not run as ofstream funcations are used, which are
define in header file so program did not load that header file.
If we assume all libraries are loaded and referenced properly.
Then this program
Will create file name abc.txt
If its already exit it will overwrite it and
Write the “Hello Buddies...Welcome to VU” in that file and close it.
Question No: 22          ( Marks: 10 )
Differentiate between C and c++
C++ was based on C and retains a great deal of the functionality. C++
does not retain complete source-level compatability with C.
There are a few gotchas for C++ programmers trying to write C code, and
C programmers trying to compile with a C++ compiler.
Actually c is a procedural programming language which
cann't face the real world problem. It has some drawback
like a global data is shared by all function and if in a
large program it is find out difficult that which function
uses which data.

On the other hand c++ is an object oriented programming
language which eliminate some pitfall of conventional or
procedural programming language. It is a concept or
approach for designing a new software. It is nothing to do
with any programming language although a programming
language which support the oops concept to make it easier
to implement.

This is the main different between c and c++.
http://www.allinterview.com/showanswers/33052.html

                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming

Question No: 1     ( Marks: 1 ) - Please choose one
In C/C++ the #include is called,
   ►Header file
   ►Preprocessor Directive
   ►Statement
   ►Function
Question No: 2     ( Marks: 1 ) - Please choose one

To access the element of two dimensional array we use,

    ►Single referencing
    ►Single dereferencing
    ►Double dereferencing
    ►Double referencing

Question No: 3        ( Marks: 1 ) - Please choose one
Data Size of the file is always___________ the actual size of the file.
   ►Greater than
   ►Equal to
   ►Less than or equal to
   ►None of the above

Question No: 4       ( Marks: 1 ) - Please choose one
When an identifier is declared with keyword const then,
  ►Its value can be changed during execution.
  ►Its value can not be changed
  ►Its value can be changed with arithmetic operator
  ►Its value can be overwritten

Question No: 5       ( Marks: 1 ) - Please choose one
In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then
the last element of this array will be stored at,
   ►Arr[0]
   ►Arr[8]
   ►Arr[7]
   ►Arr[-1]

Question No: 6         ( Marks: 1 ) - Please choose one
If it is required to copy an array to another array then,
     ►Both arrays must be of the same size and data type
     ►Both arrays may be of different size
     ►Both arrays may be of different data type
     ►Both arrays may be of different size and type

                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU   




                        http://vusolutions.blogspot.com/ 
 
Question No: 7     ( Marks: 1 ) - Please choose one
In C/C++ all character strings are terminated with,
   ► Null character
   ► String
   ► Zero
   ► Full stop

Question No: 8      ( Marks: 1 ) - Please choose one
Let suppose
struct intorDouble {
int        ival; Double
     charvar;
};
main(){
intorDouble VAZ;
int size ;
size              =
sizeof(VAZ);
}
What will be the value of variable size, if int occupies 4 bytes and
double occupies 8 bytes?
   ►2
   ►4
   ►8
   ► 12

Question No: 9      ( Marks: 1 ) - Please choose one
When a pointer is incremented, it actually jumps the number of memoryaddresses
  ►According to data type
  ►1 byte exactly
  ►1 bit exactly
  ►A pointer variable can not be incremented

Question No: 10      ( Marks: 1 ) - Please choose one
Do-while loop executes at least,

    ►Zero Time
    ►One Time
    ►Two Times
    ►N Times

Question No: 11       ( Marks: 1 ) - Please choose one
+= , *= , /= , etc are called,
  ►Assignment operators
  ►Logical operator
  ►Compound assignment operator
  ►Unary operator

                           virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Question No: 12     ( Marks: 1 ) - Please choose one
Computer can understand only machine language code.
  ►True
  ►False

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

Which of the following is the correct syntax to print multiple values or
variables in a single command using cout?
   ►cout << "Hello" + x + "\n";
   ►cout << "H" << x << "\n";
   ►cout << "H", x, "\n";
   ►cout << ("H" & x & "\n");

Question No: 14      ( Marks: 1 ) - Please choose one
The compilers and interpreters also belong to the System Software category.
   ►True
   ►False

Question No: 15        ( Marks: 1 ) - Please choose one
Editors are used to compile the code.
    ►True
    ►False
Question No: 16        ( Marks: 1 ) - Please choose one
The variables having a name, type and size are just like empty boxes.
    ►True
    ►False
Question No: 17       ( Marks: 1 )
What will be the result of the statement
rand ( ) % 50
Answer: When 50 divides any number, the remainder will always be less than 50.
Question No: 18        ( Marks: 1 )
What is the ASCII code of null character
Answer: The ASCII code of null character is all zeros.
Question No: 19        ( Marks: 2 )
What is a truth Table?
These are still a tool available for analyzing logical expressions. We will read logic
design in future, which is actually to do with chips and gates. How we put these
things together. In logic design, there are certain techniques that are known as
minimization techniques. These are used to make a big circuit with the use of
minimum chips. These minimization techniques deal with Boolean algebra i.e. logic.
These techniques are also used in programming. So we should keep breadth in our
vision while maintaining a horizontal integration. We should always think outside the
box. There is a way of thinking for us as programmers. We always look at problems,
slice and dice them and come up with solutions. Programming as a skill is infact
important. It helps us think, from a logical perspective. How can we do it is
something else. We can get it from the reference books of the language or from
online help in the compiler. This part that how can we do is always changing. New
                            virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
languages will be evolved for our help. On the other hand, what is to be done
depends on our logical skills and fundamental knowledge. We have to develop this
thing.
Question No: 20     ( Marks: 3 )



How learning to design programs is like play soccer?


“Learning to design programs is like learning to play soccer. A player must learn to
trap a ball, to dribble with a ball, to pass, and to shoot a ball. Once the player knows
those basic skills, the next goals are to learn to play a position, to play certain
strategies, to choose among feasible strategies, and, on occasion, to create variations
of a strategy because none fits. “
Question No: 21         ( Marks: 5 )
What is the purpose of the default statement
The default statement is optional. If there is no case which matches the value of
the switch statement, then the statements of defaultare executed.
Question No: 22         ( Marks: 10 )


Write a program which contains a user defined f takes 3 integer arguments hours, minutes
the number of seconds.


ConvertInSeconds that


Input variables hours , minutes and seconds in main program
and call the fun ConvertInSeconds and display the number of
seconds returned by function.
Hint:
1 hour =60 minutes
1 minute =60 seconds


# include <iostream.h>
int ConvertInSeconds(int hours, int mins, int secs);
main()
{
int stopit;
int hours, mins, secs = 0 ;
cout << "Please Entere the Hours : " ;
cin>> hours ;
cout << "Please Entere the Minutes : " ;
cin>> mins ;
cout << "Please Entere the seconds : " ;
                             virtual.uni.help@gmail.com 
        CS201 Solved Past Papers GURU 
                                      




                     http://vusolutions.blogspot.com/ 
 
cin>> secs ;
cout << "\n Total Seconds = " << ConvertInSeconds(hours, mins,
secs);
cin>> stopit; //pause screen to show output
}
int ConvertInSeconds(int hours, int mins, int secs)
{
return ( (hours*60*60)+(mins*60)+(secs));
}




                        virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU   




                          http://vusolutions.blogspot.com/ 
 
    MIDTERM EXAMINATION
    Spring 2009 CS201- Introduction to Programming

    Question No: 1       ( Marks: 1 ) - Please choose one_______
    There are mainly------------------- types of software
    ►Two
    ►Three
    ►Four
    ►Five
    Software is categorized into two main categories
    o System Software
    o Application Software
    Question No: 2       ( Marks: 1 ) - Please choose one____
    In C/C++ the #include is called,

    ►Header file
    ►Preprocessor Directive
    ►Statement
    ►Function

    Question No: 3        ( Marks: 1 ) - Please choose one___________
    && is------------------ operator.
    ►An arithmetic
    ►Logical
    ►Relational
    ►Unary
    we use logical operators ( && and || ) for AND and OR respectively with
    relational operators.
    Question No: 4        ( Marks: 1 ) - Please choose one_______
    In flow chart, the symbol used for decision making is,
    ►Rectangle
    ►Circle
    ►Arrow
    ►Diamond
    http://www.ehow.com/about_5081911_symbols-used-flowchart.html
    Question No: 5        ( Marks: 1 ) - Please choose one______
    The correct syntax of do-while loop is,
    ►(condition ) while; do { statements; };
    ►{ statements; } do-while ();
    ►while(condition); do { statements; };
    ►do { statements; } while (condition);
    Question No: 6        ( Marks: 1 ) - Please choose one___________
    C++ views each file as a sequential stream of________________ .
    ►Bytes
    ►Bits
    ►0’s or 1’s
    ►Words

                            virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU      




                           http://vusolutions.blogspot.com/ 
 
    Question        No:   7       (     Marks:     1   )   -   Please     choose
    one__________________
    If the elements of an array are already sorted then the useful search
    algorithm is,
    ►Linear search
    ►Binary search
    ►Quick search
    ►Random search
    In binary search algorithm, the ‘divide and conquer’ strategy is applied.
    This plies only to sorted arrays in ascending or descending order.
    Question No: 8        ( Marks: 1 ) - Please choose one___________
    The address operator (&) can be used with,
    ►Statement
    ►Expression
    ►Variable
    ►Constant
    Question        No:   9       (     Marks:     1   )   -   Please     choose
    one_______________
    When a pointer is incremented, it actually jumps the number of
    memory addresses
    ►According to data type
    ►1 byte exactly
    ►1 bit exactly
    ►A pointer variable can not be incremented
    Question        No:   10       (    Marks:     1   )   -   Please     choose
    one______________
    Each pass through a loop is called a/an
    ►enumeration
    ►iteration
    ►culmination
    ►pass through
    Question No: 11        ( Marks: 1 ) - Please choose one_____________
    Call by reference mechanism should be used in a program when there is
    i. large amount of data to be passed
    ii. small amount of data to be passed
    iii. need to change the passed data
    iv. no need to change the passed data
    Choose the appropriate option for the above case.
    ► (i) and (ii) only
    ►(i) and (iii) only
    ►(ii) and (iii) only
    ►(ii) and (iv) only
    Question No: 12        ( Marks: 1 ) - Please choose one________

    Which of the following is the starting index of an array in C++?
    ►0
    ►1
    ►-1
                              virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU    




                          http://vusolutions.blogspot.com/ 
 
    ►any number
    Question No: 13        ( Marks: 1 ) - Please choose one________
    The return type of a function that do not return any value must be
    __________
    ►int
    ►void
    ►double
    ►float
    Question No: 14        ( Marks: 1 ) - Please choose one_________
    Which of the following is an extension of header file?
    ►.exe
    ►.txt
    ►.h
    ►.c
    Question No: 15        ( Marks: 1 ) - Please choose one__________
    We want to access array in random order which approach is better?
    ►Pointers
    ►Array index
    ►Both pointers and array index are better
    ►None of the given options.
    Remember, if the array is to be accessed in random order, then the pointer
    approach may not be better than array indexing. (from handouts
    courtesy Omer Chaudhry )
    Question No: 16        ( Marks: 1 ) - Please choose one____________
    When we declare a multidimensional array the compiler store the elements
    of multidimensional array in the form of,
    ►Columns
    ►Rows
    ►Contiguous memory location
    ►Matrix
    Question No: 17        ( Marks: 1 )__________
    What is the output of the following program?
    #include iostream.h
    main ( ) {
    int RollNo;
    int rollno;
    RollNo = 5;
    rollno = 8;
    cout << “Roll No is ” << rollno; }
    Program should not compile due to missing from following statement
    #include iostream.h
    if we ignore this then output should be
    Roll No is 8
    Question No: 18        ( Marks: 1 )_____________________
    Why we include iostream.h in our programs?
    Because standard stream handling function are stored in this file. Before
    using these function in our program it is necessary to tell compiler about
    the location of these functions.
                             virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU       




                            http://vusolutions.blogspot.com/ 
 
    Question No: 19          ( Marks: 2 )
    Find out error in the code given below:
    if ( num % 2 = 0 )
    cout << "The number is even" << endl;
    if ( num % 2 = 0 ) There should be extra = sign following is right statement
    if ( num % 2 = =0 )
    Question No: 20          ( Marks: 3 )
    How learning to design programs is like learning to play soccer?
    “Learning to design programs is like learning to play soccer. A player must
    learn to trap a ball, to dribble with a ball, to pass, and to shoot a ball. Once
    the player knows those basic skills, the next goals are to learn to play a
    position, to play certain strategies, to choose among feasible strategies,
    and, on occasion, to create variations of a strategy because none fits. “
    Question No: 21          ( Marks: 5 )
    Write the procedure of data insertion in middle of the files by Merge
    Method practiced in older systems?
           · Opened the data file and a new empty file.
           · Started reading the data file from beginning of it.
           · Kept on copying the read data into the new file until the location we
           want to insert data into is reached.
           · Inserted (appended) new data in the new file.
           · Skipped or jumped the data in the data file that is to be overwritten
           or replaced.
           · Copied (appended) the remaining part of the file at the end of the
           new file
    Question No: 22          ( Marks: 10 )
    Write a recursive function that takes three arguments (an integer array,
    starting subscript ‘s’ and
    ending subscript ‘e’ ).
    In first recursive call, the function should display the array from subscript ‘s’
    (s = 0) to ‘e’ (e =
    size of array). In each successive call, the function should print the array
    from index s+1 to e. T
    function should stop processing and return when starting subscript becomes
    equal to ending
    subscript.
    For example, if user enters values for array 2, 3, 4, 5, 6 then the recursive
    function must display the following output.
    23456
    3456
    456
    56
    6
    answer
    #include ;
    void PrintArray(int arrayInput[], int &s, int &e);
    main ( )
    {
                                virtual.uni.help@gmail.com 
           CS201 Solved Past Papers GURU       




                            http://vusolutions.blogspot.com/ 
 
    int pause;
    int TestArray [6] = {1,2,3,4,5,6};
    int StartPoint = 0;
    int EndPoint = 5;
    PrintArray(TestArray , StartPoint, EndPoint);
    cout<<"\n";
    PrintArray(TestArray , StartPoint, EndPoint);
    cout<<"\n";
    PrintArray(TestArray , StartPoint, EndPoint);
    cout<<"\n";
    PrintArray(TestArray , StartPoint, EndPoint);
    cout<<"\n";
    PrintArray(TestArray , StartPoint, EndPoint);
    cout<<"\n";
    PrintArray(TestArray , StartPoint, EndPoint);
    cin >> pause;
    }
    void PrintArray(int arrayInput[], int& s, int& e)
    {
    for (int i = s; i<= e; i++)
    {
    cout<< arrayInput[i];
    }
    s=s+1;
    }




                               virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming

Question No: 1      ( Marks: 1 ) - Please choose one
A precise sequence of steps to solve a problem is called
► Statement
► Program
► Utility
► Routine



Question No: 2      ( Marks: 1 ) - Please choose one
The Compiler of C language is written in
► Java Language
► UNIX
► FORTRON Language
► C Language



The C language is so powerful that the compiler of C and other various operating
systems are written in C.
Question No: 3         ( Marks: 1 ) - Please choose one
Initialization of variable at the time of definition is,
► Must
► Necessary
► Good Programming
► None of the given options



Question No: 4        ( Marks: 1 ) - Please choose one
In if structure the block of statements is executed only,
► When the condition is false
► When it contain arithmetic operators
► When it contain logical operators
► When the condition is true



Question No: 5       ( Marks: 1 ) - Please choose one
Which of the following function(s) is/are included in stdlib.h header file?
► double atof(const char *nptr)
► int atoi(const char *nptr)
► char *strcpy ( char *s1, const char *s2)
► 1 and 2 only
                             virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 




Question No: 6      ( Marks: 1 ) - Please choose one
Dealing with structures and functions passing by reference is the most economical
method
► True
► False

Question No: 7        ( Marks: 1 ) - Please choose one
Pointer is a variable which store,
► Data
► Memory Address
► Data Type
► Values


Question No: 8     ( Marks: 1 ) - Please choose one
Preprocessor program perform its function before ______ phase takes place.
► Editing
► Linking
► Compiling
► Loading

The C preprocessor modifies a source code file before handing it over to the compiler.
You're most likely used to using the preprocessor to include files directly into other
files,
Question No: 9       ( Marks: 1 ) - Please choose one
Which of the following can not be a variable name?
► area
► _area
► 10area
► area2


Question No: 10       ( Marks: 1 ) - Please choose one
Which looping process is best, when the number of iterations is known?
► for
► while
► do-while
► all looping processes require that the iterations be known

Question No: 11       ( Marks: 1 ) - Please choose one
Which character is inserted at the end of string to indicate the end of string?
► new line
► tab
► null
► carriage return
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU         




                            http://vusolutions.blogspot.com/ 
 
null character   inserted    at   the   end       of   the   string   by   C   automatically


Question No: 12        ( Marks: 1 ) - Please choose one
How many bytes are occupied by declaring following array of characters?
char str[] = “programming”;
► 10
► 11
► 12
► 13
11 plus one for null char (11+1= 12)

Question No: 13       ( Marks: 1 ) - Please choose one
Which of the following header file defines the rand() function?
► iostream.h
► conio.h
► stdlib.h
► stdio.h

The function is rand() and is in the standard library. To access this function, we need
to include <stdlib.h> library in our program. This function will return a random
number. The number can be between 0 and 32767.
Question No: 14         ( Marks: 1 ) - Please choose one
Commenting the code _____________________
► Makes a program easy to understand for others.
► Make programs heavy, i.e. more space is needed for executable.
► Makes it difficult to compile
► All of the given options.

Question No: 15       ( Marks: 1 ) - Please choose one
What's wrong with this for loop?
for (int k = 2, k <=12, k++)
► the increment should always be ++k
► the variable must always be the letter i when using a for loop
► there should be a semicolon at the end of the statement
► the commas should be semicolons

Question No: 16       ( Marks: 1 ) - Please choose one
For which array, the size of the array should be one more than the number of
elements in an array?
► int
► double
► float
► char


Question No: 17      ( Marks: 1 )
To Which category of the software “Compiler and Interpreter” belongs?
                              virtual.uni.help@gmail.com 
          CS201 Solved Past Papers GURU      




                          http://vusolutions.blogspot.com/ 
 
They belong to system software.
There are two type of system software
   1. Operating system
   2. Language translators.
These are part of language translators
Question No: 18        ( Marks: 1 )
What is the result of the expression x = 2 + 3 * 4 – 4 / 2
12
first multiplies 3*4 = 12 then Division 4/2 = 2
2+12-2 = 12
Question No: 19        ( Marks: 2 )
Write a declaration statement for an array of 10 elements of type float. Include an
initialization statement of the first four elements to 1.0, 2.0, 3.0 and 4.0.
float tmp [10] = {1.0,2.0,3.0,4.0};
Question No: 20        ( Marks: 3 )
Write down the output of the following code?
int array[7], sum = 0;
for(int i=0;i<7;i++)
{
array[i] = i;
sum+= array[i];
}
cout<< “ Sum = “ <<sum;
answer: 21
Loop will run times starts from zero and add values from 1 to 6 which is equal to 21

What will be the output of the following segment of C++ code?
int A[5] = {1 , 2, 3, 4};
int i;
for (i=0; i<5; i++)
{
A[i] = 2*A[i];
cout << A[i] << " ";
}
24680
Loops will run 5 times as its starting from zero. It will multiply the value of each item
in array as last time is not initialized so it will multiply it with zero to give zero as
output
Question No: 22        ( Marks: 10 )

Write a C++ program that will determine if a departmental store customer has
exceeded the credit limit on a charge account.
Program should input the following facts in five variables
   1. Account number
   2. Balance at the beginning of month (Beginning balance)
   3. total of all items charged by customer this month (charges)
   4. total of all credits (credits)
   5. allowed credit limit
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU    




                         http://vusolutions.blogspot.com/ 
 
Calculate the new balance
New balance = Beginning balance + charges – credits
Determine if new balance exceeds the allowed credit limit. For those customers
whose credit limit is exceeded. The program should display the message “Credit Limit
exceeded.”




                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
MIDTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming

Question No: 1 ( Marks: 1 ) - Please choose one
The function of cin is
► To display message
► To read data from keyboard
► To display output on the screen
► To send data to printer
Question No: 2 ( Marks: 1 ) - Please choose one
In C/C++ language the header file which is used to perform useful task and
manipulation of character data is
► cplext.h
► ctype.h
► stdio.h
► delay.h
The functions toupper and islower are part of the character handling library
<ctype.h>
Question No: 3 ( Marks: 1 ) - Please choose one
How many parameter(s) function getline() takes?
►0
►1
►2
►3

inFile.getLine(name, maxChar, stopChar); The first argument is a character array, the
array should be large enough to hold the complete line. The second argument is the
maximum number of characters to be read. The third one is the character if we want
to stop somewhere.
Question No: 4 ( Marks: 1 ) - Please choose one
Word processor is
► Operating system
► Application software
► Device driver
► Utility software
Question No: 5 ( Marks: 1 ) - Please choose one
For which values of the integer _value will the following code becomes an
infinite loop?
int number=1;
while (true) {
cout << number;
if (number == 3) break;
number += integer_value; }
► any number other than 1 or 2
► only 0
► only 1
► only 2
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU     




                         http://vusolutions.blogspot.com/ 
 
Rational:
number += integer_value
above line decide the fate of loop so any thing other then zero leads to value of 3
which will quite the loop. Only zero is the value which keeps the loop infinite.

Question No: 6 ( Marks: 1 ) - Please choose one
Each pass through a loop is called a/an
► enumeration
► Iteration
► culmination
► pass through
Question No: 7 ( Marks: 1 ) - Please choose one
A continue statement causes execution to skip to
► the return 0; statement
► the first statement after the loop
► the statements following the continue statement
► the next iteration of the loop
continue statement is used, when at a certain stage, you don’t want to execute the
remaining statements inside your loop and want to go to the start of the loop.
Question No: 8 ( Marks: 1 ) - Please choose one
What is the correct syntax to declare an array of size 10 of int data type?
► int [10] name ;
► name[10] int ;
► int name[10] ;
► int name[] ;
Question No: 9 ( Marks: 1 ) - Please choose one
Consider the following code segment. What will the following code segment display?
int main(){
int age[10] = {0};
cout << age ;
}
► Values of all elements of array
► Value of first element of array
► Starting address of array
► Address of last array element
Question No: 10 ( Marks: 1 ) - Please choose one
What will be the correct syntax to initialize all elements of two-dimensional array to
value 0?
► int arr[2][3] = {0,0} ;
► int arr[2][3] = {{0},{0}} ;
► int arr[2][3] = {0},{0} ;
► int arr[2][3] = {0} ;
Question No: 11 ( Marks: 1 ) - Please choose one
How many bytes will the pointer intPtr of type int move in the following statement?
intPtr += 3 ;
► 3 bytes
► 6 bytes
► 12 bytes
                            virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
► 24 bytes
one int is 4 bytes so 4*3 = 12 bytes movement.
Question No: 12 ( Marks: 1 ) - Please choose one
If there are 2(n+1) elements in an array then what would be the number of iterations
required to search a number using binary search algorithm?
► n elements
► (n+1) elements
► 2(n+1) elements
► 2(n+1) elements
Question No: 13 ( Marks: 1 ) - Please choose one
Which of the following operator is used to access the value of variable pointed to by a
pointer?
► * operator
► -> operator
► && operator
► & operator
Question No: 14 ( Marks: 1 ) - Please choose one
The ________ statement interrupts the flow of control.

► switch
► continue
► goto
► break
Question No: 15 ( Marks: 1 ) - Please choose one
Analysis is the -------------- step in designing a program
► Last
► Middle
► Post Design
► First
analysis will be always followed by design and then code.
Question No: 16 ( Marks: 1 ) - Please choose one
Paying attention to detail in designing a program is _________
► Time consuming
► Redundant
► Necessary
► Somewhat Good
In programming, the details matter. This is a very important skill. A good
programmer always analyzes the problem statement very carefully and in detail. You
should pay attention to all the aspects of the problem.
Question No: 17 ( Marks: 1 )
Which programming tool is helpful in tracing the logical errors?
Debugger is used to debug the program i.e. to correct the
Question No: 18 ( Marks: 1 )
Give the syntax of opening file ‘myFile.txt’ with ‘app’ mode using ofstream variable
‘out’.
out.open(“myfile.txt” , ios::app);
Question No: 19 ( Marks: 2 )
What is the difference between switch statement and if statement.
                             virtual.uni.help@gmail.com 
         CS201 Solved Past Papers GURU      




                         http://vusolutions.blogspot.com/ 
 
The if statement is used to select among two alternatives. It uses a boolean
expression to decide which alternative should be executed. The switch statement is
used to select among multiple alternatives. It uses an int expression to determine
which alternative should be executed.
Question No: 20 ( Marks: 3 )
Identify the errors in the following code segment and give the reason of
errors.
main(){
int x = 10
const int *ptr = &x ;
*ptr = 5 ;
}
Answer
*ptr = 5;
declaring a pointer to a constant Integer. You cannot use this pointer to change the
value being pointed to:
Question No: 21 ( Marks: 5 )
If int array[10]; is an integer array then write the statements which will store values
at Fifth and Ninth location of this array,
arrary[4] = 200;
arrary[8] = 300;
Question No: 22 ( Marks: 10 )
Write a function BatsmanAvg which calculate the average of a player (Batsman), Call
this function in main program (Function). Take the input of Total Runs made and
Total number of matches played from the user in main function
#include <iostream.h> // allows program to output data to the screen
// function main begins program execution
int BatsmanAvg(int TotalRuns, int TotalMatches) ;
main()
{
int stopit;
int TotalRuns, TotalMatchesPlayed =0;
cout << "Please Entere the total Runs made : " ;
cin>> TotalRuns ;
cout << "Please Entere the total match played : " ;
cin>> TotalMatchesPlayed ;
cout << "\n Avg Runs = " << BatsmanAvg(TotalRuns,TotalMatchesPlayed);
cin>> stopit; //pause screen to show output
}
int BatsmanAvg(int TotalRuns, int TotalMatches)
{
return TotalRuns/TotalMatches;
}




                             virtual.uni.help@gmail.com 
            CS201 Solved Past Papers GURU               




                                 http://vusolutions.blogspot.com/ 
 
Our Other Blogs/websites 
  
 VU study/Help related:‐ 
VUsolutions (Every VU related solution)                     http://VUsolutions.blogspot.com/  
Online VU Lectures (Videos)                                 http://onlineVUlectures.blogspot.com/  
VU SOLVED past Papers/Quizzes/Assignments/Final Projects    http://vusolutionsPapers.blogspot.com/  
VUsolutions GURU                                            http://vusolutionsGuru.blogspot.com/  
  
Interesting Site:‐ 
 


Islamic & History Movies (Prophets & Heroes):  http://www.islamic-prophet-movies.blogspot.com/
Naat & Songs of Hina Nasrullah:                  http://hinaNasrullah-naat-songs-tv-videos.blogspot.com/ 
Diamond Engagement Rings, Jewelry Designs:   http://diamonds-jewelry-engagement-rings.blogspot.com/
Birthday Cakes, Dresses, Wishes & Party Ideas   http://BirthdaysWishes.blogspot.com/ 
Mehndi Designs & Wedding related stuff:          http://MehndiWorld.blogspot.com/ 
Natural Home Remedies, Health Tips, Health Care  http://natural-home-remedies-healthy-foods.blogspot.com/  
Learn/Watch Famous Food Recipes:                 http://online‐food‐recipes.blogspot.com/ 
Political Talk Sows:                             http://awaztv.blogspot.com/  
Paksitani WikiLeaks:                             http://paki‐wiki‐leaks.blogspot.com/  
Fashion Central, Current Fashions:               http://only4shefashion.blogspot.com/  
Good Morning Shows:                              http://masala‐morningshow.blogspot.com/  
All Famous TV Dramas:                            http://pak‐topdramas.blogspot.com/  
Watch & Learn Magic Tricks:                      http://biggest‐magic‐tricks.blogspot.com/  
Latest Innovation & latest NEWS of the world:   http://its‐latest.blogspot.com/  
Text SMS funny friendship sad love Joke etc    http://sms‐world.blogspot.com/  
  
Funny Videos:‐ 
Santa Banta (Funny Sardar Jokes Videos)      http://santabanta‐videos.blogspot.com/  
Bankay Mian Ki Qawali (All Videos)           http://bankay‐mian‐ki‐qawali.blogspot.com/  
Funny Punjabi Tootay                         http://funny‐punjabi‐totay.blogspot.com/  
Geo KhabarNak Funny show with Aftab Iqbal    http://khabarnakwithaftabiqbal.blogspot.com/  
Dar & Darling Funny Show                     http://daranddarling.blogspot.com/  
Hum Sab Umeed Say Hain (Geo TV show) http://hum‐sab‐umeed‐say‐hain‐geotv.blogspot.com/  
Aaj ka Cartoon Funny:                        http://aajcartoon.blogspot.com/  
Alif Noon Dunya TV (Funny Videos)            http://alif‐noon‐dunya‐tv.blogspot.com/  
Bulbulay (Funny Drama) ARY TV                http://bulbulay‐ary‐tv.blogspot.com/  
Geo Cartoon (Funny Geo TV)                   http://geo‐cartoon.blogspot.com/  
“Naram Garam” Popular Funny Game show   http://naramgaram‐samaa‐tv.blogspot.com/  


                                    virtual.uni.help@gmail.com 

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:22
posted:9/7/2012
language:English
pages:144