PROMOTE MY BLOG: JUST CLICK BELOW BUTTON

Search Any Paper On This Blog

Saturday, December 4, 2010

CS304- Object Oriented Programming Complete Solved Past Paper Fall 2009

MIDTERM  EXAMINATION
Fall 2009
CS304- Object Oriented Programming (Session - 5)
    
Question No: 1    ( Marks: 1 )    - Please choose one
Which one of the following terms best represents the statement given below,
” Hiding details of an object from the other parts of a program”
       Obfustication.       Data Mining.       Compilation.       Encapsulation
  
 
Question No: 2    ( Marks: 1 )    - Please choose one
The process of hiding unwanted details from users is called __________.
       ► Protection        Encapsulation       ► Argumentation       ► Abstraction
   
Question No: 3    ( Marks: 1 )    - Please choose one
An employee working in an organization has

1. Name           2. Past experience        3. Age  4. Relatives       5. Hobbies in spare times
Keeping in view the principle of abstraction, which of the above information the company needs to save as employee’s record?
       ► 2, 4       ► 1, 3, 5       ► 1, 2, 3       ► 1, 2, 3, 4
   
Question No: 4    ( Marks: 1 )    - Please choose one
What a derived class can add?
       ► New data members       ► New member functions and New friend functions
       ► New constructors and destructor       ► All of given
    Question No: 5    ( Marks: 1 )    - Please choose one
The concept of derived classes is involved in,
       ► inheritance        encapsulation       structure         array
   
Question No: 6    ( Marks: 1 )    - Please choose one
Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC. The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?

       ► Give the goahead for further design using the current scheme
       ► Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
       ► Ask for the option of WindowsPC to be removed as it will soon be obsolete
       ► Change the hierarchy to remove the need for the superfluous Computer Class.

Question No: 7    ( Marks: 1 )    - Please choose one
Consider the code below,
class Fred {
public:
Fred();
...
};
int main()
{
Fred a[10];
Fred* p = new Fred[10];
...
}
Select the best option,
       Fred a[10]; calls the default constructor 09 times
Fred* p = new Fred[10];  calls the default constructor 10 times

       ► Produce an error

       ► Fred a[10]; calls the default constructor 11 times
Fred* p = new Fred[10];  calls the default constructor 11 times

       ► Fred a[10]; calls the default constructor 10 times
Fred* p = new Fred[10];  calls the default constructor 10 times
   
Question No: 8    ( Marks: 1 )    - Please choose one
   Which construct is the source for the creation of an object?
       ► Destructor of the class       ► New operator
       ► Delete operator       ► Constructor of the class
  
 
Question No: 9    ( Marks: 1 )    - Please choose one
this pointers are not accessible for static member functions.
       True       False
   
Question No: 10    ( Marks: 1 )    - Please choose one
When a variable is define as static in a class then all object of this class,
       ► Have different copies of this variable       ► Have same copy of this variable
       ► Can not access this variable       ► None of given
   
Question No: 11    ( Marks: 1 )    - Please choose one
_______ remain in memory even when all objects of a class have been destroyed.
       Static variables       ► Instance variable
       ► Primitive variables       ► None of given

Question No: 12    ( Marks: 1 )    - Please choose one
Given the following class
class Base{
        int Age=33;
}
How you can improve above class with respect to accessing the field Age?
       ► Define the variable Age as private
       ► Define the variable Age as protected
       ► Define the variable Age as private and create a get method that returns it and a set method that updates it       Define the variable Age as protected and create a set method that returns it and a get method that updates it

Question No: 13    ( Marks: 1 )    - Please choose one
The life of sub object is not dependant on the life of master class in ___________.
       ► Composition        Aggregation        ► Separation         ► None of the given
   
Question No: 14    ( Marks: 1 )    - Please choose one
Which one is not keyword in C++?
       ► operator       ► B_op       ► const       ► None of given
   

Question No: 15    ( Marks: 1 )    - Please choose one
The >= operator can be overloaded.
       ► True       ► False
   
Question No: 16    ( Marks: 1 )    - Please choose one
Identify which of the following overloaded operator function’s declaration is appropriate for the given call?
Rational_number_1 + 2.325
Where Rational_number_1 is an object of user defined class Rational_number.
       ► Rational_number operator+( Rational_number & obj);
       ► Rational_number operator+(double& obj);
       Rational_number operator+(Rational_number &obj, double& num);…mjh sy ye solve ni howa I think theak he ha.
       ► operator+(double& obj);
  
 
Question No: 17    ( Marks: 1 )
 Give one line definition of "Ternary Association".
Association between three classes
Diamond
May have association class connected at one corner of the diamond
Example: Association between Insurance Contract, Person, Insurance Policy 

Question No: 18    ( Marks: 1 )
Give one line definition of "Object Orientation".
A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.
  
Question No: 19    ( Marks: 2 )
Fill in the blanks below with public, protected or private keyword.

Public members of base class are _____ public _____ members of derived class
Protected members of base class are __ protected or private ________members of derived class.
Question No: 20    ( Marks: 3 )
What do you mean by the term Abstraction? Why we use it.
Abstraction is way to cope with complexity and it is used to simplify things.
Principle of abstraction:
Capture only those details about an object that are relevant to current perspective
Abstraction
 Example:
Suppose we want implement abstraction for the following statement, "Ali is a PhD student and teaches BS Students"
Here object Ali has two perspectives one is his student perspective and second is his teacher perspective

Abstraction Advantages,
Abstraction has following major advantages,

1. It helps us understanding and solving a problem using object oriented approach as it hides extra irrelevant details of objects.
2. Focusing on single perspective of an object provides us freedom to change implementation for other aspects of for an object later.
Similar to Encapsulation Abstraction is also used for achieving information hiding as we show only relevant details to related objects, and hide other details.
Question No: 21    ( Marks: 5 )
 Derived class can inherit base class features? Explain it with example.
Inheritance is a process by which an object inherits parent
Object quality. inheritance gives reusability, The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class. The relationship between a parent and child class under private inheritance¤ is not "is a", but "is implemented as a"

Example: father and child relation. father properties power
Get the child.
    Consider a class Man derived class of Monkey an object of
Man inherits some of monkeys qualities and overrides some
Qualities like walking straight with two legs and have
Additional functions like speech etc..
The simple example in C++ is having a class that inherits a data member from its parentclass.
class A
{ public: integer d;
};

class B : public A
{ public:
};

The class B in inherits the data member d from class A. When one class inherits from another, it acquires all of its methods and data. We can then instantiate an object of class B and call into that data member.
void func() { B b; b.d = 10; };
Question No: 22    ( Marks: 10 )
Suppose we have a furniture store with the following types of furniture, Chairs, Tables, Computer Tables, Dining Tables and Beds.
You have to model this store using inheritance by describing base class, derived classes.
You also have to describe the IS–A relationship between these classes.

Part B.
What is IS-A relationship, show how it is implemented using c++ code (you do not have to give the detailed code simply show in a single line or two how it will be implemented).

In knowledge representation and object-oriented programming and design, is-a is a relationship where one class D is a subclass of another class B (and so B is a superclass of D). In object-oriented programming the is-a relationship arises in the context of inheritance concept. One can say that "apple" may inherit all the properties common to all fruits, such as being a fleshy container for the seed of a plant.
The is-a relationship is contrasted with the has-a relationship, which constitutes the hierarchy. It may also be contrasted with the instance-of relation: see type-token distinction.
When designing a model (e.g., a computer program) of the real-world relationship between an object and its subordinate, a common error is confusing the relations has-a and is-a.

Code:
Class newclsaa:public perent class{
}
 Part A.

CS304- Object Oriented Programming Solved Midterm Paper Spring 2010

MIDTERM  EXAMINATION
Spring 2010
CS304- Object Oriented Programming (Session - 2)    
Question No: 1    ( Marks: 1 )    - Please choose one
Which part of an object exhibits its state?
       ► Data       ► Operations       Any public part       ► Any private part

Question No: 2    ( Marks: 1 )    - Please choose one
Inheritance is a way to
       ► organize data.        pass arguments to objects of classes.
       add features to existing classes without rewriting them.
       improve data-hiding and encapsulation.
   
Question No: 3    ( Marks: 1 )    - Please choose one
Suppose you have been given the following design,

"A person has a name, age, address and sex. You are designing a class to represent a type of person called a patient. This kind of person may be given a diagnosis, have a spouse and may be alive".
Given that the person class has already been created, what of the following would be appropriate to include when you design the patient class?
       ► registration date and diagnosis       ► age and sex
       ► sex and diagnosis       ► diagnosis and age
   
Question No: 4    ( Marks: 1 )    - Please choose one
What problem(s) may occur when we copy objects without using deep copy constructor?
       ► Dangling pointer       ► Memory Leakage       All of the given       ► System crash
   
Question No: 5    ( Marks: 1 )    - Please choose one
this pointers are not accessible for static member functions.
       True       ► False
   
Question No: 6    ( Marks: 1 )    - Please choose one
A static member function cannot be declared.
      ► Static       Implicit       ► Explicit       ► Virtual

Question No: 7    ( Marks: 1 )    - Please choose one
 _______ remain in memory even when all objects of a class have been destroyed.
       ► Static variables       ► Instance variable       ► Primitive variables       ► None of given
   
Question No: 8    ( Marks: 1 )    - Please choose one
Friend functions are _____________ functions of a class.
       ► None of given       ► object member       ► non-member       ► data member
   
Question No: 9    ( Marks: 1 )    - Please choose one
___________, which means if A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.
       Friendship is one way only                           ► Friendship is two way only
       ► NO Friendship between classes                 ► Any kind of friendship

Question No: 10    ( Marks: 1 )    - Please choose one
The statement objA=objB; will cause a compiler error if the objects are of different classes.

       ► True       ► False
   
Question No: 11    ( Marks: 1 )    - Please choose one
Identify which of the following overloaded operator function’s declaration is appropriate for the given call?
Rational_number_1 + 2.325
Where Rational_number_1 is an object of user defined class Rational_number.


       ► Rational_number operator+( Rational_number & obj);
       ► Rational_number operator+(double& obj);
       Rational_number operator+(Rational_number &obj, double& num);
       ► operator+(double& obj);
   
Question No: 12    ( Marks: 1 )    - Please choose one
Which operator can not be overloaded?
       ► The relation operator ( >= )       ► Assignment operator ( = )
       ► Script operator ( [] )                      ► Conditional operator (? : )

Question No: 13    ( Marks: 1 )    - Please choose one
To convert from a user-defined class to a basic type, you would most likely use
       ► a built-in conversion operator.        ► a one-argument constructor.
       ► an overloaded = operator.                 ► a conversion operator that’s a member of the class.
   
Question No: 14    ( Marks: 1 )    - Please choose one
 The technique in which we visualize our programming problems according to real life’s problems is called
----------------
       ► structured programming       ► object oriented Programming   
       ► procedural programming       ► non of the given
   
Question No: 15    ( Marks: 1 )    - Please choose one
In object orientated programming, a class of objects cans _____________ properties from another class of objects

       ► Utilize       ► Borrow       ► Inherit       ► Adopt
   
Question No: 16    ( Marks: 1 )    - Please choose one
A C++ class is similar to --------------------

       ► Structure       ► Header File       ► Library File       ► None of the given
   
Question No: 17    ( Marks: 2 )
Can we create an array of objects for a class having user defined constructor? Justify your answer.

   
Question No: 18    ( Marks: 2 )
 Friend functions increase ‘Programming bugs’. What is your opinion?

   
Question No: 19    ( Marks: 2 )
 Explain two benefits of setter functions.

   
Question No: 20    ( Marks: 3 )
 What are binary operators? Give an example of binary operators overloading using any class.
   
Question No: 21    ( Marks: 3 )
 Give c++ code to overload assignment operator for string class.

MIDTERM EXAMINATION Solved Paper Of CS304- Object Oriented Programming

Question No: 1    ( Marks: 1 )    - Please choose one
No instances can be created from an abstract class.
       ► True       ► False
   
Question No: 2    ( Marks: 1 )    - Please choose one
Aggregation is implemented using pointer.
       ► True       ► False
   
Question No: 3    ( Marks: 1 )    - Please choose one
Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC. The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?
       ► Give the goahead for further design using the current scheme
       ► Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
       ► Ask for the option of WindowsPC to be removed as it will soon be obsolete
       ► Change the hierarchy to remove the need for the superfluous Computer Class.
   
Question No: 4    ( Marks: 1 )    - Please choose one
The ______ keyword tells the compiler to substitute the code within the function definition for every instance of a function call.
       virtual       ► inline       instance       None of given.
   
Question No: 5    ( Marks: 1 )    - Please choose one
   Which construct is the source for the creation of an object?
       ► Destructor of the class       ► New operator       ► Delete operator       ► Constructor of the class
   
Question No: 6    ( Marks: 1 )    - Please choose one
Which will be the good example of a method that is shared by all instances of a class?
       ► Constructor       ► Attribute       ► Constructor and Attribute       ► None of given options
   
Question No: 7    ( Marks: 1 )    - Please choose one
__________ provide the facility to access the data member.
       ► accesser function        ► private function       ► inline function        ► None of the given
Question No: 8    ( Marks: 1 )    - Please choose one
A static member function cannot be declared.
       ► Static       ► Implicit       ► Explicit       ► Virtual
   
Question No: 9    ( Marks: 1 )    - Please choose one
A non-static member function can be called only after _______ the class as an object.
       Instantiating       Declaring       Defining       Opening
   
Question No: 10    ( Marks: 1 )    - Please choose one
Static variable is created even when there is no object of a class is created.
       ► True       ► False
   
Question No: 11    ( Marks: 1 )    - Please choose one
In _______________ a pointer or reference to an object is created inside a class.
       ► Aggregation        ► Composition       ► Separation       ► None of the given
   
Question No: 12    ( Marks: 1 )    - Please choose one
Friend class and friend function can be used as an alternate to each other
       ► True       ► False
   
Question No: 13    ( Marks: 1 )    - Please choose one
Constructor/s with a different signature than default constructor is/are called?
       ► Overloaded Constructor/s         ► Default Constructor/s
       ► Simple Constructor/s                            ► Multiple Constructor/s
Question No: 14    ( Marks: 1 )    - Please choose one
Operator overloading is
       ► making C++ operators work with objects.        ► giving C++ operators more than they can handle.
       ► giving new meanings to existing Class members.        ► making new C++ operators.
   
Question No: 15    ( Marks: 1 )    - Please choose one
The statement objA=objB; will cause a compiler error if the objects are of different classes.

       ► True       ► False
   
Question No: 16    ( Marks: 1 )    - Please choose one
Which operator can not be overloaded?
       ► The relation operator ( >= )                   ► Assignment operator ( = )
       ► Script operator ( [] )                              ► Conditional operator (? : )
Question No: 17    ( Marks: 1 )
Give two examples of binary operators.

Question No: 18    ( Marks: 1 )
Give one line definition of "Model".

A model is an abstraction of something real or conceptual.

Question No: 19    ( Marks: 2 )
Write a statement that a member function can use to return the entire object of which it is a member, without creating any temporary objects.

Following staement can return the entire object of which it is a member.Member function is a function which is declared in the public part of class.

Question No: 20    ( Marks: 3 )
Give example c++ code to overload unary ‘ ++ ‘ operator for complex numbers class.

Code:


Question No: 21    ( Marks: 5 )
 Describe base and derived class’s relationship with at least two examples.
Any parent class is called the base class. And the class that is derived from it is its child class and called as Derived class. Examples are given: