CS304 – Object Oriented Programming: Midterm Important Subjective (58 Solved Q&As)

Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.

All 664 Midterm Packs · CS304 Course Page · CS304 MCQ Pack (399 MCQs)

  1. What is interface? Give two real life examples.
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    Interface is a set of functions of an object that it wants to expose to other objects. Interface of a Car is the set of these functions: Accelerate, Change Gear, Apply Brakes, Turn Lights On/Off. Interface of a Phone is the set of these functions: Input Number, Place Call, Disconnect Call, Add number to address book, Remove number, Update number.

  2. What is an abstract class?
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    Taking part of the objects and their functions that is related to the problem and ignoring all other irrelevant characteristics is called abstraction. (The source answer defines abstraction, on which the concept of an abstract class is based.)

  3. What are Accessor Functions? Explain with an example. (Marks: 5)
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    Accessor functions are used to access private data of the object. We provide accessor functions to get and set private data members of the class. class Student { ... int rollNo; public: void setRollNo(int aRollNo) { rollNo = aRollNo; } }; Avoiding error — the setter can validate the value before assigning it: void Student::setRollNo(int aRollNo) { if (aRollNo < 0) { rollNo = 0; } else { rollNo = aRollNo; } }

  4. Explain two benefits of setter functions. (Marks: 2)
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    Setter (and getter) functions are provided by the class to access its members. Their benefits are: 1. They help to define the variable in an interface, and can be used to make a variable read-only, and to notify other methods/classes when the value is changed. 2. They minimize the chances of moving the object into an inconsistent state, because we can write checks in our setter functions — for example, we can check whether the user has entered a correct age value and has not entered a negative value for age.

  5. Explain the scope of 'private' member of a class with one example. (Marks: 2)
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    The scope of a private data member of a class is that access is allowed only within the class. Only member functions of the class can access and modify the value of the data member. A derived class or a class instance/object cannot access it directly. The data member is created for each separate object in memory and is eliminated when the object is destroyed; an object is destroyed by calling its destructor. class Arithmetic { private: int a, b; public: void Add() { // a + b; direct access by member function — correct access } }; int main() { Arithmetic c1; c1.a = 4; // illegal access to private data member — compiler error }

  6. If, within a class, da is a member variable, will the statement this.da = 25; assign 25 to da? (Marks: 2)
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    No — the statement is false/incorrect. 'this' is a pointer, so when using a pointer to an object we use the -> operator to access the object's member functions and data members. The correct statement is: this->da = 25;

  7. Can a constant object access the non-constant member function of a class?
    Topic: OOP Fundamentals — Classes, Objects & Encapsulation

    No. Const objects can access only const member functions, so chances of change of state of const objects once they are created are eliminated.

  8. Write three important properties of constructors. Also tell the reason why we cannot overload the following four operators in C++: . , .* , :: , ?: — and, considering the Complex number class, can we subtract two complex numbers by overloading the plus '+' operator? Justify your answer.
    Topic: Constructors, Object Arrays & Initialization Order

    Properties of constructors: 1. Constructor is a special function having the same name as the class name. 2. Constructor does not have a return type. 3. Constructors are commonly public members. The operators . , .* , :: and ?: cannot be overloaded because they are strictly compile-time operators: they are defined for all types, operate on names rather than values, and have results which can be used in constant expressions (evaluated at compile time). Subtracting through operator+: No. An overloaded operator must keep its natural, intuitive meaning; writing subtraction code inside operator+ would be misleading and against the purpose of operator overloading. Subtraction of two complex numbers must be implemented by overloading the '-' operator. (Note: the answer to the last part — subtracting through operator+ — is written from course knowledge; the source answer covers only the constructor properties and the non-overloadable operators.)

  9. Can we create an array of objects for a class having user defined constructor? Justify your answer. (Marks: 2)
    Topic: Constructors, Object Arrays & Initialization Order

    No — not with a user defined (parameterized) constructor alone. When an array of objects is created, every element has to be constructed without arguments, so there must always be a default constructor if we want to create an array of objects. If the class provides only a user defined constructor, an array of objects cannot be created unless a default constructor is also defined.

  10. Can we create an array of objects for a class having default constructor? Justify your answer. (Marks: 2)
    Topic: Constructors, Object Arrays & Initialization Order

    Yes. When an array of objects is created, the constructor is called for each element of the array. Since no arguments can be supplied while creating an array, the default constructor (the constructor with no parameters) is invoked for every element. Therefore, if a class has a default constructor, an array of its objects can be created, and each element is initialized by that default constructor.

  11. Consider the class given below. Explain the order in which variables e, f and g will be initialized after creating an object of this class.
    Topic: Constructors, Object Arrays & Initialization Order

    class XYZ { int e; int f; int g; public: XYZ(); }; XYZ::XYZ() : g(30), e(10), f(20) { ... } Member variables are initialized in the order in which they are declared in the class, not in the order in which they appear in the member initializer list. The declaration order here is e, f, g, so they are initialized in the order e first, then f, then g — giving the values e = 10, f = 20 and g = 30. (Note: the source file prints the values as 'f = 30 and g = 20', which appears to be a printing error in the source — the initializer list assigns f(20) and g(30).)

  12. Consider the class given below. What will be the values in variables x, y and z after creating an object of this class? (Marks: 3)
    Topic: Constructors, Object Arrays & Initialization Order

    class ABC { int x; int y; int z; public: ABC(); }; ABC::ABC() : x(10), z(x), y(x) { ... } Variables are initialized in the order of their declaration in the class (x, y, z), regardless of the order in the initializer list. So x is initialized first with 10; then y is initialized with the value of x, i.e. 10; then z is initialized with the value of x, i.e. 10. x = 10, y = 10 and z = 10.

  13. What are static data members? (Marks: 2)
    Topic: Static Members

    A variable that is part of a class, yet is not part of any object of that class, is called a static data member.

  14. Explain the difference between the static variable of a class and the non-static variable, with the help of an example.
    Topic: Static Members

    The difference between static and non-static members is only that a non-static member is tied to an instance of a class, whereas 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 separately for each instance of the class. Example: in a Student class, rollNo is a non-static member — every student object has its own rollNo. A static member such as a counter of students is shared by all objects, so increasing it through any one object is visible to all objects of the class.

  15. Friend functions increase 'Programming bugs'. What is your opinion? (Marks: 2)
    Topic: Friend Functions

    Yes, friend functions can increase programming bugs. A friend function can access the private data of a class, which minimizes encapsulation. This can result in data vulnerability, programming bugs and tough debugging.

  16. Friend functions minimize 'Encapsulation'. What is your opinion?
    Topic: Friend Functions

    Yes, friend functions minimize encapsulation, as we can access the private data of any class using friend functions. This can result in: • Data vulnerability • Programming bugs • Tough debugging

  17. Friend functions increase 'Data vulnerability'. What is your opinion? (Marks: 2)
    Topic: Friend Functions

    Yes. Friend functions minimize encapsulation, as we can access the private data of any class using friend functions. This can result in: • Data vulnerability • Programming bugs • Tough debugging

  18. What is simple association? Explain it with the help of an example.
    Topic: Object Relationships — Association, Aggregation & Composition

    The two interacting objects have no intrinsic relationship with the other object. It is the weakest link between objects. It is a reference by which one object can interact with some other object. Examples: • Customer gets cash from cashier. • Employee works for a company.

  19. What is the difference between simple association and composition?
    Topic: Object Relationships — Association, Aggregation & Composition

    In Association, the interacting objects have no intrinsic relationship with the other object. It is the weakest link between objects. While in Composition, an object may be composed of other smaller objects; the relationship is between the 'part' objects and the 'whole' object, and the part objects are dependent on the whole object for their existence.

  20. What is aggregation? Give an example.
    Topic: Object Relationships — Association, Aggregation & Composition

    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 an example of aggregation.

  21. What is composition? Explain it with the help of an example. (Marks: 5)
    Topic: Object Relationships — Association, Aggregation & Composition

    An object may be composed of other smaller objects; the relationship between the 'part' objects and the 'whole' object is known as Composition. Composition is represented by a line with a filled-diamond head towards the composer object. For example, a man and his body parts have the relation of 'part' objects and the 'whole' object — this is known as the composition of man.

  22. What are binary operators? Give an example of binary operator overloading using any class. (Marks: 3)
    Topic: Operator Overloading — Concepts & Arithmetic Operators

    Binary operators act on two quantities. Examples of binary operators are +, -, * and /. Overloading of the + operator for a Complex class: class Complex { private: double real, img; public: ... Complex operator +(const Complex & rhs); }; Complex Complex::operator +(const Complex & rhs) { Complex t; t.real = real + rhs.real; t.img = img + rhs.img; return t; } The binary operator is always called with reference to the left hand argument.

  23. Give C++ code to overload the unary '--' operator for the Complex class. (Marks: 3)
    Topic: Operator Overloading — Concepts & Arithmetic Operators

    class Complex { ... Complex operator --(int); // postfix, as member function // friend Complex operator --(const Complex &, int); }; Complex Complex::operator --(int) { Complex t = *this; real -= 1; return t; } // As a friend (non-member) function: Complex operator --(const Complex & h, int) { Complex t = h; t.real -= 1; return t; }

  24. Write C++ code for overloading the '^' operator in the Complex numbers class. If we have two objects of the Complex number class, Complex obj1, obj2; and we write the statement Complex obj3 = obj1 ^ obj2; then obj3.real = (obj1.real)^(obj2.real) and obj3.img = (obj1.img)^(obj2.img). (Hint: You can use the C++ built-in function pow(x, y) that returns the result of x raised to the power y.) (Marks: 5)
    Topic: Operator Overloading — Concepts & Arithmetic Operators

    class Complex { double real, img; public: Complex operator ^(const Complex & c) { Complex t; t.real = pow(real, c.real); t.img = pow(img, c.img); return t; } }; When the statement Complex obj3 = obj1 ^ obj2; is executed, the overloaded ^ operator is called on obj1 with obj2 as argument, so obj3.real gets (obj1.real) raised to the power (obj2.real) and obj3.img gets (obj1.img) raised to the power (obj2.img), computed with the built-in pow(x, y) function.

  25. Write C++ code for overloading the '-' operator in the Complex numbers class which can work in the given situations: Complex obj1; Complex obj3 = 47.4 - obj2; Complex obj4 = obj2 - 47.4; (Marks: 5)
    Topic: Operator Overloading — Concepts & Arithmetic Operators

    We make one version a friend function so that it can be written as a non-member function: when the left operand is a double value (47.4 - obj2), the operator is not called with respect to a Complex object; instead both arguments (the double value and the Complex object) are passed to the friend function, and the compiler invokes the function according to the arguments passed. The case obj2 - 47.4 is handled by the member function. class Complex { private: double real, img; public: friend Complex operator -(double c1, Complex obj); Complex operator -(double c1) { Complex temp; temp.real = real - c1; temp.img = img - c1; return temp; } }; // Friend function definition — handles 47.4 - obj2 Complex operator -(double c1, Complex obj) { Complex temp; temp.real = c1 - obj.real; temp.img = c1 - obj.img; return temp; }

  26. Assuming that class X does not use any overloaded operators and has a member function to subtract two objects of X, placing the result in the third object using which it has been called, write a statement that we will use to subtract two objects of class X, placing the result in the third object. You can take any names for the three objects of X. (Marks: 3)
    Topic: Operator Overloading — Concepts & Arithmetic Operators

    obj3.subtract(obj1, obj2); Here the member function subtract is called using the third object obj3, and the two objects to be subtracted (obj1 and obj2) are passed to it as arguments. The function subtracts them and places (stores) the result in the calling object obj3 itself.

  27. Give C++ code to overload the assignment operator for the String class. (Marks: 3)
    Topic: Assignment Operator, Copying & Special Operators

    class String { int size; char * bufferPtr; public: String(); // default constructor String(char *); // overloaded constructor String(const String &); // copy constructor ... }; String::String() { bufferPtr = NULL; size = 0; } String::String(char * ptr) { if (ptr != NULL) { size = strlen(ptr); bufferPtr = new char[size + 1]; strcpy(bufferPtr, ptr); } else { bufferPtr = NULL; size = 0; } } String::String(const String & rhs) { size = rhs.size; if (rhs.size != 0) { bufferPtr = new char[size + 1]; strcpy(bufferPtr, rhs.bufferPtr); } else { bufferPtr = NULL; } } int main() { String str1("Hello"); String str2("World"); str1 = str2; return 0; }

  28. Give at least two problems that we should check when we are overloading the assignment operator ("=") in the String class.
    Topic: Assignment Operator, Copying & Special Operators

    1. Self-assignment (self-referencing): an object may be assigned to itself, e.g. str = str; The overloaded assignment operator must check for this case, otherwise it would first delete its own buffer and then try to copy data from the already-freed memory, corrupting the object. 2. Chained (cascaded) assignment: assignments in a single line such as stringObject1 = stringObject2 = stringObject3 = stringObject4 must work. For this, the assignment operator must return a reference to the assigned object (String &) so that the result of one assignment can be used as the operand of the next. (Related: the old memory of the destination object must also be released properly, otherwise memory leakage and dangling pointers occur.)

  29. How do we resolve the following problems in overloading of the assignment operator in the String class? Explain with the help of C++ code. (i) Self referencing. (ii) Assigning a string value to more than one string in a single line, like stringObject1 = stringObject2 = stringObject3 = stringObject4.
    Topic: Assignment Operator, Copying & Special Operators

    Both problems are resolved by defining the assignment operator to return a reference to the object itself (String &) and by guarding against self-assignment before releasing the old buffer: class String { ... public: ... String & operator = (const String &); }; String & String::operator = (const String & rhs) { if (this != &rhs) { // protects against self-assignment size = rhs.size; delete [] bufferPtr; if (rhs.size != 0) { bufferPtr = new char[rhs.size + 1]; strcpy(bufferPtr, rhs.bufferPtr); } else { bufferPtr = NULL; } } return *this; // enables chained assignment } Returning *this by reference makes chained assignment work, because the result of stringObject2 = stringObject3 is stringObject2 itself, which is then assigned to stringObject1, and so on.

  30. Explain what type of copy the default assignment operator "=" does when applied to objects (shallow copy or deep copy). (Marks: 3)
    Topic: Assignment Operator, Copying & Special Operators

    The default assignment operator performs a shallow copy. If our class has any data member using dynamic memory, then we have to write our own code for the default constructor, copy constructor and similarly the assignment operator, because the compiler-generated versions of these functions perform shallow copy, which creates dangling pointer and memory leakage issues in case of dynamic memory allocation.

  31. Write C++ code to overload the subscript [] operator for the String class. (Marks: 5)
    Topic: Assignment Operator, Copying & Special Operators

    The subscript operator must be overloaded as a member function of the class with one parameter of integer type: class String { ... public: char & operator[](int); ... }; char & String::operator[](int pos) { assert(pos > 0 && pos <= size); return stringPtr[pos - 1]; } int main() { String s1("Ping"); cout << s1.GetString() << endl; s1[2] = 'o'; cout << s1.GetString(); return 0; }

  32. Write C++ code for the operator() (function operator). (Marks: 5)
    Topic: Assignment Operator, Copying & Special Operators

    class String { ... 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 << s1.GetString(); return 0; }

  33. How can we overload the Stream Extraction and Insertion Operators in C++? Give example code for the Complex Number Class. (Marks: 5)
    Topic: Assignment Operator, Copying & Special Operators

    The stream insertion (<<) and extraction (>>) operators are overloaded as friend functions of the class, because their left operand is a stream object, not an object of our class. class Complex { ... friend ostream & operator << (ostream & os, const Complex & c); friend istream & operator >> (istream & in, Complex & c); }; // Stream insertion operator — we want the output as: (real, img) ostream & operator << (ostream & os, const Complex & c) { os << '(' << c.real << ',' << c.img << ')'; return os; } // Stream extraction operator istream & operator >> (istream & in, Complex & c) { in >> c.real >> c.img; return in; } (Note: the source gives the insertion operator in full but the file ends after the declaration of the extraction operator; the extraction operator's definition above is completed from course knowledge — not in sources.)

  34. Detect and correct the compile time error(s) in the following code. (Marks: 5)
    Topic: Finding & Correcting Errors in Code

    Code given in the paper: class Exam { char *ExamName; int No_of_paper; public: Exam() { ExamName = "Final Term"; No_of_paper = 5; } void setname(char* name) const { ExamName = name; } void setpaper(int paper) const { No_of_paper = paper; } char* getname() { return ExamName; } int getpaper() { return No_of_paper; } }; int main() { const Exam exam1; cout << " Exam = " << exam1.getname() << endl; cout << " Number of paper = " << exam1.getpaper(); getch(); return 0; } Errors: (1) setname and setpaper are declared const, but a const member function cannot modify the data members of the class — assigning ExamName and No_of_paper inside them is a compile time error. (2) exam1 is declared as a const object in main, and a const object can call only const member functions, whereas getname and getpaper are non-const member functions — calling them on exam1 is also a compile time error. Corrected code: class Exam { char *ExamName; int No_of_paper; public: Exam() { ExamName = "Final Term"; No_of_paper = 5; } void setname(char* name) { ExamName = name; } void setpaper(int paper) { No_of_paper = paper; } char* getname() { return ExamName; } int getpaper() { return No_of_paper; } }; int main() { Exam exam1; cout << " Exam = " << exam1.getname() << endl; cout << " Number of paper = " << exam1.getpaper(); getch(); return 0; }

  35. What is Abstraction?
    Topic: Important Definitions — OOP Concepts

    The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.

  36. What is a Class Diagram?
    Topic: Important Definitions — OOP Concepts

    A class diagrams are widely used to describe the types of objects in a system and their relationships. Class diagrams model class structure and contents using design elements such as classes, packages and objects.

  37. What is Method Overriding?
    Topic: Important Definitions — OOP Concepts

    Method overriding is a language feature that allows a subclass to override a specific implementation of a method that is already provided by one of its super-classes. A subclass can give its own definition of methods but need to have the same signature as the method in its super-class. This means that when overriding a method the subclass's method has to have the same name and parameter list as the super-class's overridden method.

  38. What is Operator Overloading?
    Topic: Important Definitions — OOP Concepts

    The operator overloading is a specific case of polymorphisms in which some or all of operators like +, - or == are treated as polymorphic (multi) functions and as such have different behaviors depending on the types of its arguments.

  39. What is Method Overloading?
    Topic: Important Definitions — OOP Concepts

    The method overloading is the ability to define several methods (in same class) all with the same name but different on the basis of i) number of parameters ii) types of parameters.

  40. What is Polymorphism?
    Topic: Important Definitions — OOP Concepts

    Polymorphism is a generic term that means 'many shapes'. More precisely Polymorphism means the ability to request that the same operations be performed by a wide range of different types of things.

  41. What is Inheritance?
    Topic: Important Definitions — OOP Concepts

    Ability of a new class to be created, from an existing class by extending it, is called inheritance.

  42. What is a base class?
    Topic: Important Definitions — OOP Concepts

    When inheritance is used to create a new class from another, the new class is called the subclass or derived class, and the class from which it was derived is called the base class.

  43. What is a concrete class?
    Topic: Important Definitions — OOP Concepts

    A concrete class is one that can be used to directly create, or instantiate objects, unlike an abstract base class which can only be used as a base class for other classes which eventually lead to concrete classes

  44. What is a constructor?
    Topic: Important Definitions — OOP Concepts

    Objects are complete, miniature programs and, like any good programs, have well defined initialization and termination phases. They have special routines (i.e. member functions ) to look after this. The initialization routine is called the constructor, and C++ ensures that every object is properly initialized by calling its constructor. The designer of the object can have more than one constructor, a situation called overloading and then the compiler will select between them depending on exactly what arguments are passed to the constructor function. However there must always be a default constructor, to be used when no information is supplied.

  45. What is a destructor?
    Topic: Important Definitions — OOP Concepts

    The termination routine is called the destructor, and C++ will provide a default if none is supplied. If, during the lifetime of the object, it uses heap memory then the designer of the object must provide a destructor function to release such memory to avoid a memory leak.

  46. What is meant by protected?
    Topic: Important Definitions — OOP Concepts

    The protected keyword in the class statement means that the following members of the class are not available to users of the objects of the class, but can be used by any subclass that inherits from it, and consequently forms part of its implementation.

  47. What is OOP?
    Topic: Important Definitions — OOP Concepts

    The object oriented programming is commonly known as OOP. Most of the languages are developed using OOP concept. Object-oriented programming (OOP) is a programming concept that uses "objects" to develop a system. An object hides the implementation details and exposes only the functionalities and parameters it requires to its client. Here also an object shares the same concept as that of a bike. While driving a motor bike, we are unaware of its implementation details such as how it is developed, internal working of gears etc.? We know only the functions or actions it can perform.

  48. What are the various elements of OOP?
    Topic: Important Definitions — OOP Concepts

    Various elements of OOP are: Object, Class, Methods, Encapsulation, Information Hiding, Inheritance and Polymorphism.

  49. What is an Object?
    Topic: Important Definitions — OOP Concepts

    An object has state, behavior and identity; the structure and behavior of similar objects are defined in their common class. The terms instance and object are interchangeable. An object is a tangible entity that exhibits some well-defined behavior.

  50. What is Encapsulation?
    Topic: Important Definitions — OOP Concepts

    Encapsulation is the process of hiding all of the details of an object that do not contribute to its essential characteristics. It is the principle that each component of a program should encapsulate (hide) its implementation details, exposing only a well-defined interface to the rest of the system — this is also called information hiding.

  51. What is the proper syntax to free the memory allocated to an array "a" of five objects?
    Topic: Code & Short Questions from Past Papers

    delete [] a; — The delete[] operator deallocates the memory of the whole array and calls the destructor for each of the five objects.

  52. Write a class Coordinate that performs the mathematical operations (Addition and Multiplication) on its coordinates with the help of operator overloading. The class has two private data members: xCord and yCord.
    Topic: Code & Short Questions from Past Papers

    class Coordinate { private: int xCord; int yCord; public: Coordinate(int x = 0, int y = 0) { xCord = x; yCord = y; } Coordinate operator + (const Coordinate &c) { return Coordinate(xCord + c.xCord, yCord + c.yCord); } Coordinate operator * (const Coordinate &c) { return Coordinate(xCord * c.xCord, yCord * c.yCord); } };

  53. Write any two advantages of declaring a member function as const.
    Topic: Code & Short Questions from Past Papers

    1) A const member function can be called on constant objects, so constant objects can still use the read-only (getter) functions of the class. 2) It guarantees that the function will not modify the data members of the object, which makes the program safer and lets the compiler catch accidental changes to the state of the object.

  54. Write the code for a deep copy constructor for the given class: class MidTerm { private: char* papername; int Totalmarks; };
    Topic: Code & Short Questions from Past Papers

    MidTerm(const MidTerm &obj) { Totalmarks = obj.Totalmarks; papername = new char[strlen(obj.papername) + 1]; strcpy(papername, obj.papername); } In a deep copy, separate memory is allocated for the pointer data member and the contents are copied, so both objects own independent copies of the data.

  55. Write the exact type of the this pointer in a member function of a class XYZ.
    Topic: Code & Short Questions from Past Papers

    In a non-const member function, the this pointer is of type XYZ* (it is a constant pointer that holds the address of the object itself). In a const member function, its type is const XYZ*, so the object cannot be modified through it.

  56. Write three distinct situations in which the copy constructor of a class is called.
    Topic: Code & Short Questions from Past Papers

    1) When an object is initialized with another object of the same class, e.g. Student s2 = s1; 2) When an object is passed by value as an argument to a function. 3) When an object is returned by value from a function.

  57. Consider the code: class Complex { private: double x, y; static int z; public: Complex(double = 0.0); friend ostream& operator<<(ostream&, const Complex&); static int doSomething() { z = 2 * y; return z; } }; What is wrong in the definition of member function doSomething()?
    Topic: Code & Short Questions from Past Papers

    doSomething() is a static member function. Static member functions have no this pointer and can access only the static data members of the class; here it tries to use y, which is a non-static data member, so the code is wrong and will not compile.

  58. What will be the effect of writing the friend function operator<< in the private part of the above class?
    Topic: Code & Short Questions from Past Papers

    There will be no effect. Access specifiers (public, private, protected) do not apply to friend declarations: a friend function or friend class has full access to the private and protected members of the class no matter in which section of the class it is declared.

MIHORA VU – Virtual University Assignment Solutions 2026, Solved Past Papers & All 455+ Courses

Official MIHORA TECH academic repository offering 28,328+ verified study documents for all 455+ Virtual University of Pakistan courses. Access VU Assignment Solution 2026 (Latest Session), Moaaz & Waqar Siddhu solved midterm & final papers, lecture handouts, and quizzes with 100% direct high-speed links.

SPRING 2026 / FALL 2026 ACTIVE SESSION

VU Assignment Solution 2026 (Latest Solved Assignments, GDBs & Quizzes)

Get high-scoring solutions for Assignment 1, Assignment 2, and Graded Discussion Boards across Computer Science, Mathematics, Management, English, and Economics. Compliant with Turnitin similarity limits (< 19%) and official 24-hour grace periods.

Open VU Assignment Solution 2026 Hub →

Popular Virtual University Courses (2026 Solved Papers & Solutions):

CS101 – Introduction to Computing CS201 – Introduction to Programming CS301 – Data Structures CS302 – Digital Logic Design CS401 – Computer Architecture & Assembly Language CS402 – Theory of Automata CS403 – Database Management Systems CS501 – Advance Computer Architecture CS502 – Fundamentals of Algorithms CS504 – Software Engineering - I CS506 – Enterprise Application Development CS601 – Data Communication CS602 – Computer Graphics CS604 – Operating Systems CS605 – Software Engineering - II CS607 – Artificial Intelligence CS610 – Computer Networks CS619 – Final Year Project MTH101 – Calculus & Analytical Geometry MTH202 – Discrete Mathematics MTH301 – Calculus II (Multivariable Calculus) MTH302 – Business Mathematics & Statistics MTH501 – Linear Algebra ENG101 – English Comprehension ENG201 – Business and Technical English Writing MGT101 – Financial Accounting MGT211 – Introduction to Business MGT301 – Principles of Marketing MGT501 – Human Resource Management ACC311 – Fundamentals of Auditing ACC501 – Business Finance STA301 – Statistics and Probability ECO401 – Economics (Micro & Macro) ISL202 – Islamic Studies / Ethics PAK301 – Pakistan Studies PHY101 – Physics - Mechanics & Waves

Complete Directory of All 455 Virtual University Courses & Codes

Browse the complete curriculum of all 455 accredited courses across 27 faculties of Virtual University of Pakistan. Every course includes verified lecture handouts, Moaaz & Waqar Siddhu solved papers, and 2026 assignment solution templates.

Accounting & Finance (16 Courses)

ACC301 – Financial Accounting ACC311 – Fundamentals of Auditing ACC501 – Business Finance BNK601 – Banking Laws & Practices BNK603 – Consumer Banking BNK604 – Commercial Banking BNK610 – Credit & Risk Management in Banking EFIN623 – Economics of Financial Markets FIN611 – Advanced Financial Accounting FIN621 – Financial Statement Analysis FIN622 – Corporate Finance FIN623 – Taxation Management FIN624 – Islamic Banking & Finance FIN625 – Credit & Risk Management FIN630 – Investment Analysis & Portfolio Management FIN722 – Advanced Corporate Finance

Bioinformatics (7 Courses)

BIF101 – Basic Bioinformatics BIF401 – Introduction to Bioinformatics BIF402 – Computational Biology Methods BIF501 – Genomics & Proteomics BIF601 – Bioinformatics Algorithms BIF602 – Structural Bioinformatics BIF604 – Systems Biology

Biological Sciences (16 Courses)

BIO101 – Basic Biology BIO102 – Introductory Biology & Diversity BIO201 – Cell Biology BIO202 – Biochemistry BIO203 – General Genetics BIO204 – Biochemical Techniques BIO301 – Molecular Biology BIO302 – Animal Physiology BIO303 – Developmental Biology BIO401 – Ecology & Evolutionary Biology BIO502 – Immunology & Pathology BIO503 – Pharmacology & Toxicology BIO504 – Applied Microbiology BIO505 – Environmental Biotechnology BIO506 – Forensic Biology BIO731 – Advanced Molecular Genetics

Virtual University of Pakistan (43 Courses)

BNK611 – Economic Ideology in Islam BT613T – Agricultural Biotechnology CS306 – Introduction to Python CS441 – Big Data Concepts CS442 – Introduction to Data Science CS620 – Modeling & Simulation CS701 – Theory of Computation CS703 – Operating Systems CS704 – Advanced Computer Architecture ECO302 – Microeconomics EDU407 – EDU407 ENG401 – Introduction to Literature: Short Story and Poetry GSC201 – Teaching of General Science MCM516 – TV News Reporting and Production MGMT611 – Human Relations MGMT629 – Crisis Management MGT201 – Financial Management MGT401 – Financial Accounting II MGT404 – MGT404 MGT504 – Organization Theory & Design MGT520 – International Business MGT522 – MGT522 MGT601 – SME Management MGT603 – Strategic Management MGT613 – Production and Operations Management MGT703 – Strategic Management MGT705 – Advanced Cost and Management Accounting MGT713 – Production / Operations Management MTH102 – Basic Algebra and Trigonometry MTH201 – Multivariable Calculus MTH304 – Mechanics MTH403 – MTH403 MTH404 – MTH404 MTH405 – MTH405 MTH621 – Real Analysis I MTH633 – Group Theory MTH642 – Fluid Mechanics MTH643 – MTH643 PAK303 – PAK303 PSC401 – Public International Law PSY409 – Positive Psychology SE601 – Software Construction & Development SE602 – Software Re—engineering

Bio-Technology (34 Courses)

BT101 – Ecology, Biodiversity & Evolution BT102 – Microbiology BT201 – Biotechnology Fundamentals BT301 – Recombinant DNA Technology BT302 – Cell and Tissue Culture BT401 – Genetic Engineering BT402 – Fermentation Technology BT403 – Agricultural Biotechnology BT404 – Medical Biotechnology BT405 – Industrial Biotechnology BT406 – Nanobiotechnology BT501 – Biochemical Engineering BT502 – Biosafety & Bioethics BT503 – Molecular Diagnostics BT504 – Stem Cell Technology BT505 – Food Biotechnology BT511 – Vaccine Technology BT512 – Drug Design & Development BT513 – Genomics & Functional Proteomics BT514 – Enzyme Technology BT601 – Advanced Genetic Engineering BT602 – Bioinformatics in Biotechnology BT603 – Bioprocess Engineering BT604 – Aquatic Biotechnology BT605 – Environmental Bioremediation BT611 – Synthetic Biology BT612 – Metabolic Engineering BT613 – Biofuels and Bioenergy BT614 – Clinical Research in Biotechnology BT693 – Research Project in Biotechnology BT732 – Advanced Molecular Biology Seminar BT734 – Advanced Cellular Biotechnology BT735 – Current Topics in Biotechnology NTBT301 – Nanotechnology in Biotechnology

Chemistry (2 Courses)

CHE201 – General Chemistry CHE301 – Organic Chemistry

Computer Science (55 Courses)

CS000 – Introduction to Computer Fundamentals CS001 – Computer Proficiency License CS101 – Introduction to Computing CS201 – Introduction to Programming CS202 – Web Design & Development CS204 – Cyber Law & Intellectual Property CS205 – Information Security Management CS206 – Ethical Hacking & Defense CS301 – Data Structures CS302 – Digital Logic Design CS304 – Object Oriented Programming CS310 – Introduction to Programming (Python) CS311 – Introduction to Web Services Development CS312 – Mobile Application Development CS314 – Embedded Systems & IoT CS315 – Web Engineering CS401 – Computer Architecture & Assembly Language CS402 – Theory of Automata CS403 – Database Management Systems CS405 – Mobile Computing CS407 – Cloud Computing Fundamentals CS408 – Human Computer Interaction CS409 – Ethical & Legal Issues in Computing CS410 – Design & Analysis of Algorithms CS411 – Visual Programming CS420 – Game Design and Development CS432 – Network Security CS435 – Cloud Computing Infrastructure CS501 – Advance Computer Architecture CS502 – Fundamentals of Algorithms CS505 – Agile Software Development CS506 – Enterprise Application Development CS507 – Information Systems CS508 – Modern Programming Languages CS510 – Compiler Construction CS511 – Distributed Systems CS521 – Data Science Principles CS601 – Data Communication CS602 – Computer Graphics CS603 – Software Architecture CS604 – Operating Systems CS606 – Compiler Design & Construction CS607 – Artificial Intelligence CS608 – Digital Signal Processing CS609 – System Programming CS610 – Computer Networks CS614 – Data Warehousing CS619 – Final Year Project CS621 – Information Retrieval Techniques CS625 – Formal Methods in Software Engineering CS627 – Computer Vision & Pattern Recognition CS636 – Big Data Analytics CS708 – Advanced Computer Graphics CS713 – Advanced Software Architecture CS718 – Advanced Artificial Intelligence

Software Engineering (4 Courses)

CS504 – Software Engineering - I CS605 – Software Engineering - II CS611 – Software Quality Assurance CS615 – Software Project Management

Statistics (18 Courses)

DSTA630 – Data Science Research Methods STA000 – Basic Statistics Fundamentals STA100 – Foundations of Statistics STA301 – Statistics and Probability STA304 – Statistical Inference STA404 – Experimental Design STA406 – Sampling Techniques STA408 – Biostatistics and Epidemiology STA630 – Research Methods in Social Sciences STA631 – Advanced Statistical Methods STA632 – Multivariate Analysis STA641 – Non-Parametric Methods STA642 – Econometric Models STA730 – Advanced Research Methodology in Statistics STAT100 – Statistics Fundamentals STAT404 – Applied Statistical Modeling STAT408 – Statistical Computing STAT730 – Advanced Biostatistics

Education (44 Courses)

ECE101 – Introduction to Early Childhood Care & Education EDU101 – Foundations of Education EDU201 – Learning Theories & Applications EDU205 – Classroom Management EDU301 – General Methods of Teaching EDU302 – Human Development & Learning EDU303 – School, Community and Teacher EDU304 – Educational Assessment & Evaluation EDU305 – Curriculum Development & Instruction EDU306 – Contemporary Trends in Education EDU401 – Critical Thinking and Reflective Practices EDU402 – Educational Leadership & Management EDU403 – Art, Craft & Calligraphy in Education EDU404 – Teaching of English EDU405 – Teaching of Mathematics EDU406 – Teaching of General Science EDU410 – ICT in Education EDU411 – Teaching of Social Studies EDU430 – Information & Communication Technology in Teaching EDU431 – Test Development & Measurement EDU433 – Educational Statistics EDU501 – Educational Psychology EDU505 – Guidance and Counseling in Schools EDU510 – Qualitative Research in Education EDU512 – Comparative Education EDU514 – Special Education Principles EDU515 – Early Childhood Education Curriculum EDU516 – Educational Technology & Media EDU601 – Philosophy of Education EDU602 – Educational Planning and Policy EDU604 – Educational Administration & Supervision EDU630 – Research Methods in Education EDU654 – Teacher Education in Pakistan EDU702 – Advanced Seminar in Educational Leadership EDU705 – Advanced Educational Policy Analysis EDUA305 – Applied Curriculum Development EDUA403 – Elementary Arts Education EDUA405 – Pedagogy of Mathematics EDUA516 – Educational Media Design EDUA630 – Action Research in Educational Settings MEDU402 – Master Level Educational Leadership MEDU406 – Science Teaching Pedagogies MEDU430 – Advanced ICT in Education MEDU601 – Advanced Philosophy of Education

Economics (11 Courses)

ECO401 – Economics (Micro & Macro) ECO402 – Microeconomics Analysis ECO403 – Macroeconomics Analysis ECO404 – Managerial Economics ECO406 – Development Economics ECO501 – Monetary Economics ECO601 – International Economics ECO603 – Public Sector Economics ECO606 – Agricultural Economics ECO607 – Environmental & Resource Economics ECO610 – Econometrics Principles

Management Sciences (26 Courses)

EMG525 – Engineering Project Management MGMT614 – Leadership & Team Building MGMT615 – Project Management Practices MGMT617 – Project Management Methodologies MGMT622 – Operations Management MGMT623 – Supply Chain Management MGMT625 – Knowledge Management Systems MGMT627 – Global Business Strategy MGMT628 – Strategic Management MGMT630 – Business Strategy & Policy MGMT631 – Innovation Management MGT101 – Financial Accounting MGT111 – Introduction to Public Administration MGT211 – Introduction to Business MGT301 – Principles of Marketing MGT402 – Cost & Management Accounting MGT411 – Money & Banking MGT501 – Human Resource Management MGT502 – Organizational Behaviour MGT503 – Principles of Management MGT510 – Total Quality Management MGT602 – Entrepreneurship MGT604 – Management of Financial Institutions MGT610 – Business Ethics & Corporate Governance MGT611 – Business & Labor Law MGTE630 – Business Management Strategy

English (34 Courses)

ENG001 – Basic English Grammar & Composition ENG101 – English Comprehension ENG201 – Business and Technical English Writing ENG301 – Business Communication ENG501 – History of English Language ENG502 – Introduction to Linguistics ENG503 – English Morphology and Syntax ENG504 – Sociolinguistics ENG505 – Phonetics & Phonology ENG506 – World Englishes ENG507 – Psycholinguistics ENG508 – Semantics & Pragmatics ENG509 – English for Specific Purposes (ESP) ENG510 – Language Testing & Evaluation ENG511 – Syllabus Design & Materials Development ENG512 – Stylistics & Literary Analysis ENG513 – Second Language Acquisition (SLA) ENG514 – Classical Poetry ENG515 – Classical Drama ENG516 – Research Methodology in Linguistics ENG517 – Modern Poetry ENG518 – Modern Drama ENG519 – Classical Novel ENG520 – Modern Novel ENG521 – American Literature ENG522 – Postcolonial Literature ENG523 – Continental Literature & Criticism ENG524 – Literary Criticism & Theory ENG525 – Discourse Analysis ENG526 – Applied Linguistics in Education ENG527 – Creative Writing & Composition ENG528 – Corpus Linguistics ENG529 – Translation Studies & Theory FENG301 – Functional English for Professionals

Islamic Studies (4 Courses)

ETH100 – Ethics (For Non-Muslim Students) ETH201 – Ethics & Moral Philosophy (For Non-Muslims) ISL201 – Islamic Studies ISL202 – Islamic Studies / Ethics

General Guides (1 Courses)

GENERAL – General University Resources, Guides & Handbooks

General Sciences (1 Courses)

GSC101 – General Science

Human Resources (4 Courses)

HRM613 – Human Resource Development HRM617 – Compensation & Benefits Management HRM624 – Conflict & Negotiation Management HRM627 – Strategic Human Resource Management

Information Technology (4 Courses)

IT430 – E-Commerce & Digital Business IT601 – Network Administration IT602 – Database Administration ITU430 – E-Commerce Systems

Microbiology (4 Courses)

MB501 – General Microbiology & Microbial Diversity MB502 – Microbial Physiology & Metabolism MB504 – Medical Microbiology MIC501 – Applied Microbiology

Mass Communication (22 Courses)

MCD401 – Media Content Development MCD403 – Media Ethics & Professional Standards MCM000 – Introduction to Communication Fundamentals MCM101 – Introduction to Mass Communication MCM301 – Communication Skills MCM304 – Mass Media in Pakistan MCM310 – Radio Broadcasting & Audio Media MCM311 – Radio & Television Production MCM401 – Fundamentals of Public Relations MCM404 – Electronic Media Content Creation MCM411 – News Writing and Reporting MCM431 – Digital Media & Online Journalism MCM501 – Development Support Communication MCM511 – Media Ethics, Cyber Laws & Regulation MCM514 – Feature, Column & Editorial Writing MCM517 – Advertising Strategy & Campaigns MCM520 – Print Media Design & Layout MCM531 – International & Cross-Cultural Communication MCM601 – Theories of Mass Communication MCM604 – Communication Research Methodology MCM610 – Cyber Journalism & Web Publishing MCMP310 – Radio & Audio Production Practical

Marketing (5 Courses)

MKT501 – Marketing Management MKT530 – Consumer Behaviour MKT610 – Customer Relationship Management (CRM) MKT621 – Advertising & Brand Management MKT630 – International Marketing Strategy

Mathematics (20 Courses)

MTH001 – Elementary Mathematics MTH100 – General Mathematics MTH101 – Calculus & Analytical Geometry MTH104 – Sets & Logic MTH202 – Discrete Mathematics MTH301 – Calculus II (Multivariable Calculus) MTH302 – Business Mathematics & Statistics MTH401 – Differential Equations MTH501 – Linear Algebra MTH601 – Operations Research MTH603 – Numerical Analysis MTH622 – Vector & Tensor Analysis MTH631 – Real Analysis MTH632 – Complex Analysis MTH634 – Topology MTH641 – Functional Analysis MTH644 – Mathematical Methods MTH645 – Mechanics MTH646 – Differential Geometry MTH647 – Fluid Mechanics

Social Studies (3 Courses)

PAK301 – Pakistan Studies PAK302 – History of Pakistan PAK522 – Ideology & Constitution of Pakistan

Physics (3 Courses)

PHY000 – Foundational Physics PHY101 – Physics - Mechanics & Waves PHY301 – Circuit Theory

Psychology (23 Courses)

PSY101 – General Psychology PSY401 – Clinical Psychology Fundamentals PSY402 – Social Psychology PSY403 – Developmental Psychology PSY404 – Abnormal Psychology PSY405 – Personality Theories & Assessment PSY406 – Educational Psychology Applications PSY407 – Experimental Psychology & Lab Methods PSY408 – Health Psychology PSY502 – History and Systems of Psychology PSY504 – Cognitive Psychology PSY505 – Psychological Testing & Measurement PSY510 – Positive Psychology & Well-being PSY511 – Counseling Psychology Principles PSY512 – Organizational & Industrial Psychology PSY513 – Neuropsychology Fundamentals PSY515 – Forensic & Criminal Psychology PSY516 – Cross-Cultural Psychology PSY610 – Neurological Basis of Behavior PSY611 – Psychopathology & Diagnostics PSY631 – Psychological Assessment Practicum PSY632 – Research Methods in Psychology PSYP631 – Psychological Assessment Lab Practical

Sociology (14 Courses)

SOC101 – Introduction to Sociology SOC201 – Pakistani Society and Culture SOC301 – Social Psychology & Society SOC302 – Cultural Anthropology SOC401 – Social Research Methods SOC402 – Classical Sociological Theories SOC403 – Social Change & Modernization SOC404 – Urban Sociology SOC601 – Rural Sociology & Community Development SOC602 – Gender Studies & Society SOC605 – Criminology & Juvenile Delinquency SOC608 – Sociology of Development SOC609 – Sociology of Health & Medicine SOC610 – Demography & Population Dynamics

Urdu Literature (2 Courses)

URD101 – Functional Urdu (Urdu Zaban-o-Adab) URDU101 – Urdu Language & Literature

Zoology (35 Courses)

ZOO101 – Principles of Animal Life I ZOO102 – Principles of Animal Life II ZOO103 – Animal Diversity: Invertebrates ZOO111 – Fundamentals of Zoology ZOO201 – Animal Diversity: Chordates ZOO202 – Animal Form & Function I ZOO203 – Animal Form & Function II ZOO301 – Animal Physiology ZOO302 – Cell & Molecular Biology in Zoology ZOO307 – Principles of Ecology ZOO401 – Evolution & Principles of Systematics ZOO403 – Animal Behavior & Sociobiology ZOO404 – Biostatistics for Zoologists ZOO405 – General Developmental Biology ZOO501 – Developmental Biology ZOO502 – Environmental Biology ZOO503 – Biostatistics in Zoological Research ZOO504 – Zoogeography & Paleontology ZOO505 – Wildlife of Pakistan & Conservation ZOO506 – Endocrinology ZOO507 – Animal Diversity & Behavior ZOO509 – Fish Biology & Fisheries Science ZOO510 – General Microbiology & Immunology ZOO511 – Immunology & Serology ZOO512 – Parasitology & Vectors ZOO513 – Applied Entomology ZOO514 – Biochemistry of Animals ZOO515 – Genetics & Population Biology ZOO516 – Aquaculture & Fisheries Management ZOO517 – Toxicology & Environmental Health ZOO518 – Comparative Vertebrate Anatomy ZOO519 – Mammalogy ZOO520 – Ornithology (Bird Biology) ZOO603 – Applied Parasitology & Vector Biology ZOO630 – Research Methodology in Zoology

Core Student Calculators & Rules Handbooks

Frequently Asked Questions – MIHORA VU Study Library

Where can I download VU Assignment Solution 2026 for CS101, CS201, MTH101, and all subjects?

MIHORA VU (https://study.mihora.tech/vu-assignment-solution-2026) offers verified 2026 assignment solutions, GDB answers, quiz files, and Dev-C++ code templates for all 455 Virtual University courses with 100% free direct downloads.

What is the 24-hour assignment grace period in Virtual University?

Virtual University gives students an automatic 24-hour grace period after the official assignment deadline. Submissions during this grace window are awarded full credit with 0 marks deduction.

How to avoid zero marks in VU assignments due to Turnitin plagiarism?

Never copy-paste solutions directly from YouTube or public groups. Keep Turnitin similarity under 19% by renaming code variables, rearranging logical statements, and writing custom explanations.

Where can I get Moaaz and Waqar Siddhu solved midterm and final past papers?

MIHORA VU hosts over 28,328 verified documents including complete Moaaz and Waqar Siddhu past paper collections for all 455 VU subjects, available via direct download without registration.

What is the 20% Two-Half passing rule in Virtual University?

Students must score at least 20% in the First Half (Quizzes, Assignments, GDBs, and Midterms) AND independently at least 20% in the Final Term exam paper to pass any course.