Skip to content
VUBuddy

CS304 Midterm Solved Subjective with References by Moaaz and Irfan

Object Oriented Programming PDF 297 KBUpdated 23 Oct 2026
Midterm past paper CS304 Midterm Solved Subjective with References by Moaaz and Irfan PDF 297 KB
vubuddy.com
Type
Midterm past paper
Course
CS304 Object Oriented Programming
Size
PDF 297 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 297 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 2, 3, 4 of 14. Download the file for all 14 pages.

Q1. can constant object access the none constant member function of each class.

Answer: (Page 106) " Const objects can access only const member functions so chances of change of state of const objects once they are created are eliminated."

Q2. Give at least two problems that we should check when we overloading assignments operator ("=") in string class (unsolved)

Q3. Give c++ code to overloaded unary "--" oprators to comples member class.

Answer: (Page 165)

Complex operator -- (int); · // friend Complex operator --(const Complex &, int); · Complex Complex::operator -- (int){ · complex t = *this; · real - = 1; · return t; · Complex operator -- (const · Complex & h, int){ · complex t = h; · h.real - = 1; · return t;

Q4. What is simple association? Explain it with the help of example.

Answer: (Page 49) The two interacting objects have no intrinsic relationship with other object. It is the weakest link between objects. It is a reference by which one object can interact with some other object.

  • Customer gets cash from cashier
  • Employee works for a company

Q5. explain the deference between the static variable of a class with none static variable with the help of example

The difference between static and non static members is only that a non static member is tied to an instance of a class although a static member is tied to the class, and not to a particular instance. That is, a static member is shared by all instances of a class although a non static member exists for each instance of class.

write c++ code for operator() ......5 marks

Answer: (Page 161)

Function Operator

public: char & operator()(int);

char & String::operator() (int pos){ assert(pos>0 && pos<=size); return bufferPtr[pos-1];

int main(){ String s1(“Ping”); char g = s1(2); // g = „i‟ s1(2) = „o‟; cout << g << “\n”; cout << str. GetString(); return 0;

Write c++ code for operator [] using string class.......5 marks.....

Answer: (Page 160) Subscript operator must be overloaded as member function of the class with one parameter of integer type,

public: char & operator[](int);

char & String::operator[]( int pos){ assert(pos>0 && pos<=size); return stringPtr[pos-1];

int main() { String s1(“Ping”); cout <<str. GetString()<< endl; s1[2] = „o‟; cout << str. GetString(); return 0;

static data members.......2.mark

Answer: (Page 108) “A variable that is part of a class, yet is not part of any object of that class, is called static data member”

What is interface give two real life examples?

Answer: (Page 18) Interface is a set of functions of an object that he wants to expose to other objects.

Interface of a Car is set of these functions

  • Accelerate • Change Gear • Apply Brakes• Turn Lights On/Off

Interface of a Phone is set of these functions

  • Input Number• Place Call • Disconnect Call • Add number to address book • Remove number • Update number

What is aggregation give example?

Answer: (Page 53) An object may contain a collection (aggregate) of other objects, the relationship between the container and the contained object is called aggregation, For Example: A room and its components like table, chair and bed etc are example of aggregation.

What is an abstract class?

Answer: (Page 21) Taking part of the objects and their functions that is related to the problem and ignore all other irrelative characteristic called abstraction

Q17. Can we create an array of objects for a class having user defined constructor? Justify your answer. (2 marks)

Answer: (Page 114) There must always be a default constructor if we want to create array of objects

Q18. Friend functions increase „Programming bugs‟. What is your opinion? (2 marks)

Answer: Yes friend functions can increase programming bugs some time.

All CS304 files →
CS304 Object Oriented Programming All CS304 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.