FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming (Session - 1)
Time: 120 min
Marks: 75
Student Info | |
StudentID: | |
Center: | |
ExamDate: |
Question No: 1 ( Marks: 1 ) - Please choose one
► dot operator (.)
► * operator
► à operator
► None of given.
Question No: 2 ( Marks: 1 ) - Please choose one
► 1
► 2
► 3
► 4
Question No: 3 ( Marks: 1 ) - Please choose one
► No error
► Syntax error
► Logical error
► Run time error
Question No: 4 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 5 ( Marks: 1 ) - Please choose one
►Zero
►One
►Two
►N arguments
Question No: 6 ( Marks: 1 ) - Please choose one
►Class-Name operator + (Class-Name rhs)
►operator Class-Name + ( )
►operator Class-Name + ( rhs)
►Class-Name operator + ( )
Question No: 7 ( Marks: 1 ) - Please choose one
►Member function
►Non-member function
►Private function
►Public function
Question No: 8 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 9 ( Marks: 1 ) - Please choose one
►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
►True
►False
Question No: 11 ( Marks: 1 ) - Please choose one
► float, int
► float, double
► int
► char
Question No: 12 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 13 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 14 ( Marks: 1 ) - Please choose one
►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
►True
►False
Question No: 16 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 17 ( Marks: 1 ) - Please choose one
►return
►break
►continue
►goto
Question No: 18 ( Marks: 1 ) - Please choose one
►private, public
►public, private
►private, protected
►public, protected
Question No: 19 ( Marks: 1 ) - Please choose one
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
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
►One, zero
►Zero, one
►One, two
►Two, one
Question No: 22 ( Marks: 1 ) - Please choose one
► Structures, function
► Objects, member functions
► Functions, objects
► None of the given options
Question No: 23 ( Marks: 1 ) - Please choose one
► True
► False
Question No: 24 ( Marks: 1 ) - Please choose one
► Constructor
► Destructor
► Both a constructor and a destructor
► None of the given options
Question No: 25 ( Marks: 1 ) - Please choose one
► Built-in- Function
► Operators
► Memory Allocation Function
► None of the given options
Question No: 26 ( Marks: 1 ) - Please choose one
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
►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
Question No: 29 ( Marks: 1 ) - Please choose one
►True
►False
Question No: 30 ( Marks: 1 ) - Please choose one
►deep copy
►shallow copy
►constructor copy
►none of the options
Question No: 31 ( Marks: 1 )
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 )
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 )
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 )
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 )
1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
Output will be:
1
1
1
1
1
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Output will be:
1
2
3
2
3
Question No: 36 ( Marks: 3 )
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 than void, 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 )
Question No: 38 ( Marks: 5 )
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 )
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 )
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.
Question No: 41 ( Marks: 10 )
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
#include <stdio.h> #include <iostream> #include <cstring> using namespace std; class Date { public: 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; } 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(); } }; void main() { Person object; object.setDate(); object.Display(); system("pause"); } |
No comments:
Post a Comment
PLEASE COMMENT ABOUT YOUR VISIT AND MY SITE
Note: Only a member of this blog may post a comment.