0% found this document useful (0 votes)
34 views4 pages

SDF2 Tutorial 7

The document is a tutorial and assignment sheet for a course titled SDF-II, containing seven questions related to object-oriented programming concepts, particularly inheritance in C++. It includes theoretical questions, programming exercises, and design tasks focused on class hierarchies and the use of inheritance in various software scenarios. The questions require explanations, code outputs, and design considerations for different applications, including an online learning platform and a Valentine's Day event planning service.

Uploaded by

Kush Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

SDF2 Tutorial 7

The document is a tutorial and assignment sheet for a course titled SDF-II, containing seven questions related to object-oriented programming concepts, particularly inheritance in C++. It includes theoretical questions, programming exercises, and design tasks focused on class hierarchies and the use of inheritance in various software scenarios. The questions require explanations, code outputs, and design considerations for different applications, including an online learning platform and a Valentine's Day event planning service.

Uploaded by

Kush Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorial and Assignment Sheet – EVEN 2025

15B11CI211 – SDF-II
Tutorial 7

Ques1. Can we pass parameters to base class constructor though derived class or derived
class constructor? Explain.

Ques2. What will be the output of following program? Explain with reasons.

#include<bits/stdc++.h>

using namespace std;

class Base1 {

public:

Base1()

{ cout << " Base1" << endl; }

};

class Base2 {

public:

Base2()

{ cout << "Base2" << endl; }

};

class Derived: public Base1, public Base2 {

public:

Derived()

{ cout << "Derived" << endl; }

};

int main()

Derived d;
return 0; }

Ques 3. In a software project for an online learning platform, how would you utilize
inheritance to model different types of courses, such as video-based courses, interactive
courses, and text-based courses? Explain how you would design the class hierarchy to ensure
flexibility, scalability, and maintainability while leveraging the benefits of inheritance.
Additionally, discuss potential pitfalls or trade-offs associated with using inheritance in this
scenario.

Ques 4. Design a software system for a university's academic department that manages
various types of employees, including professors, administrative staff, and teaching
assistants. Utilize multiple types of inheritance (single, multiple, and hierarchical) to model
the relationships between different employee roles, ensuring flexibility and scalability in the
system. Discuss the advantages and potential challenges associated with each type of
inheritance in this context.

Ques 5. What will be the output of following program?

#include<iostream>
using namespace std;

class Base
{
public :
int x, y;
public:
Base(int i, int j){ x = i; y = j; }
};

class Derived : public Base


{
public:
Derived(int i, int j):x(i), y(j) {}
void print() {cout << x <<" "<< y; }
};

int main(void)
{
Derived q(10, 10);
q.print();
return 0;
}
Ques 6.

Imagine you're developing a software application for a virtual Valentine's Day event planning
service. As part of the system, you're tasked with designing a class hierarchy to represent
different types of romantic gifts that users can send to their loved ones. Utilize inheritance to
model relationships between various gift types, each with unique attributes and behaviors
tailored to express love and affection.

Requirements:

1. Create a base class RomanticGift with common attributes such as sender name, recipient
name, and price.
2. Derive three types of gifts from the RomanticGift class: Flower, ChocolateBox, and
LoveLetter.
3. Each derived class should have additional attributes and methods specific to its type:
 Flower: Include attributes for flower type, color, and arrangement style.
 ChocolateBox: Include attributes for chocolate type, flavor, and quantity.
 LoveLetter: Include attributes for the message content and style.
4. Override the displayDetails() method in each derived class to provide specific information
about the gift type.
5. Additionally, implement a friend function printGiftDetails() to facilitate private data access
and display detailed information about any gift type.

Your Task:

Write C++ code to fulfill the requirements mentioned above. Ensure that your code
demonstrates inheritance, method overriding, and the usage of friend functions to achieve
encapsulation and facilitate data access between classes. Lastly, provide a main() function to
create instances of different gift types and display their details using the overridden
displayDetails() method and the printGiftDetails() friend function.

Ques 7. What is the output of the code below:

#include <iostream>

using namespace std;

class Base {};

class Derived: public Base {};

int main()

Base *p = new Derived;

Derived *q = new Base;}

You might also like