Posts

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345

  // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent,  and  GraduateStudent  classes  in  a  university  management  system. Can  you  explain  the  advantages  of  using  multilevel  inheritance  with  specific   details  about the functions and data members in these classes? How were the parameterized constructors (e.g.,  setting  student  name,  age,  and  ID)  used  to  ensure  that  each   class  in  the  hierarchy correctly initializes its properties. #include < iostream > using namespace std ; class Student { private :     string name , ID ;     int age ; public :     Student () { name = "" , ID = "" , age = 0 ; }     Student ( string n , string i , int a ) { name ...

220: Construct a class stack with member functions isEmpty, isFull, push, pop. Then make a class Human with data members name, father name and age. Then derive a class from it Student with data members rollNumber, department. Make a static count variable to check the total number of students anytime without calling object. Overload ++ operator that will increase the age of student by one. Your stack class should hold the record of every student.(array in stack class will be of student type)

  // Construct a class stack with member functions isEmpty, isFull, push, pop. Then make a class Human with data members name, father name // and age. Then derive a class from it Student with data members rollNumber, department. Make a static count variable to check the // total number of students anytime without calling object. Overload ++ operator that will increase the age of student by one. // Your stack class should hold the record of every student.(array in stack class will be of student type) #include < iostream > using namespace std ; const int stackSize = 10 ; class Human { private :     string name , fatherName ;     int age ; public :     Human ( string n = "" , string f = "" , int a = 0 ) { name = n , fatherName = f , age = a ; }     void setName ( string n ) { name = n ; }     void setFather ( string f ) { fatherName = f ; }     void setAge ( int a ) { age = ...

219: Create a C++ program that demonstrates function overriding and dynamic polymorphism in single inheritance. Define a base class "Shape" with a virtual function "displayInfo." Derive classes "Circle" and "Rectangle" from "Shape" and override the "displayInfo" function to provide specific information about each shape.

  // Create a C++ program that demonstrates function overriding and dynamic polymorphism in single inheritance. // Define a base class "Shape" with a virtual function "displayInfo." Derive classes "Circle" and "Rectangle" // from "Shape" and override the "displayInfo" function to provide specific information about each shape. #include < iostream > using namespace std ; class Shape { public :     virtual void displayInfo () { cout << " A closed geometrical figure is known as shape \n " ; } }; class Circle : protected Shape { public :     void displayInfo () override     {         cout << " A circle is a closed two-dimensional figure in which the set of all "               << " the points in the plane is equidistant from a given point called center. \n " ;     } }; class Rectangle : protected Shape { public :     void displayInfo ()...

218: Implement a C++ program to create a basic hierarchy for electronic devices. Create a base class "Device" with attributes like brand and power source. Derive a class "Phone" from "Device" to include features like operating system and screen size.

  // Implement a C++ program to create a basic hierarchy for electronic devices. // Create a base class "Device" with attributes like brand and power source. // Derive a class "Phone" from "Device" to include features like operating system and screen size. #include < iostream > using namespace std ; class Device { private :     string brand , powerSource ; public :     Device ( string b = "" , string p = "" ) { brand = b , powerSource = p ; }     virtual void display_Device (); }; void Device :: display_Device () { cout << " Brand: " << brand << " \n Power Source: " << powerSource << endl ; } class Phone : protected Device { private :     string operating_System , screen_size ; public :     Phone ( string b = "" , string p = "" , string o = "" , string s = "" ) : Device ( b , p )     {...

217: Write a C++ program to model a vehicle hierarchy. Create a base class "Vehicle" with attributes like make and model. Derive classes "Car" and "Motorcycle" from "Vehicle" and add specific attributes like the number of tyres and engine type.

  // Write a C++ program to model a vehicle hierarchy. Create a base class "Vehicle" // with attributes like make and model. Derive classes "Car" and "Motorcycle" from // "Vehicle" and add specific attributes like the number of tyres and engine type. #include < iostream > using namespace std ; class Vehicle { private :     string make , model ; public :     Vehicle ( string ma = "" , string mo = "" ) { make = ma , model = mo ; }     virtual void display_vehicle (); }; void Vehicle :: display_vehicle () { cout << " Make: " << make << " \n Model: " << model << endl ; } class Car : protected Vehicle { private :     int tyres ;     string engine ; public :     Car ( string , string , int , string );     void display_vehicle () override ; }; Car :: Car ( string ma = "" , string mo = "" , int t = 0 , s...

216: Develop a C++ program to manage a list of employees. Create a base class "Employee" with attributes like name and salary. Derive a class "Manager" from "Employee" to include additional attributes like department and team size.

  // Develop a C++ program to manage a list of employees. Create a base class // "Employee" with attributes like name and salary. Derive a class "Manager" // from "Employee" to include additional attributes like department and team size. #include < iostream > using namespace std ; class Employee { private :     string name ;     int salary ; public :     Employee ( string n = "" , int s = 0 ) { name = n , salary = s ; }     virtual void displayEmp () { cout << " Name: " << name << " \n Salary: " << salary << endl ; } }; class Manager : protected Employee { private :     string department ;     int team_size ; public :     Manager ( string n = "" , int s = 0 , string d = "" , int t = 0 ) : Employee ( n , s )     {         department = d , team_size = t ;     }     v...

215: Create a C++ program that uses single inheritance to model a simple shape hierarchy. Implement a base class "Shape" with a virtual function "printArea." Derive classes "Rectangle" and "Triangle" from "Shape" and override the "printArea" function to calculate and display their respective areas.

  // Create a C++ program that uses single inheritance to model a simple shape hierarchy. // Implement a base class "Shape" with a virtual function "printArea." Derive classes // "Rectangle" and "Triangle" from "Shape" and override the "printArea" function to // calculate and display their respective areas. #include < iostream > using namespace std ; class Shape { public :     virtual void printArea () { cout << " Make object of specific shape \n " ;} }; class Rectangle : protected Shape { private :     float length , width ; public :     Rectangle ( float l = 0 , float w = 0 ) { length = l , width = w ; }     void printArea () override { cout << " Area of Rectangle: " << length * width << endl ; } }; class Triangle : protected Shape { private :     float base , height ; public :     Triangle ( float b = 0 , float h = 0 ) ...