Create a program using `enum` to represent days of the week. Accept a number from the user and display the corresponding day using a `switch` statement.

Create a program using `enum` to represent days of the week. Accept a number from the user and display the corresponding day using a `switch` statement. SOLUTION…. C++ Enum Days Example #include <iostream> using namespace std; int main() { // Enum declaration enum Days { Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; […]

Accept two strings using character arrays. Use string functions `strcpy()`, `strcat()`, `strcmp()`, and `strlen()` to perform various operations.

Accept two strings using character arrays. Use string functions `strcpy()`, `strcat()`, `strcmp()`, and `strlen()` to perform various operations. SOLUTION…. C++ String Functions Example #include <iostream> #include <cstring> // for string functions using namespace std; int main() { char str1[100], str2[100], str3[100]; // Input two strings cout << “Enter first string: “; cin.getline(str1, 100); cout << […]

Create a base class `Animal` with function `speak()`. Derive classes `Dog` and `Cat`, override `speak()` function to display “Bark” and “Meow” respectively.

Create a base class `Animal` with function `speak()`. Derive classes `Dog` and `Cat`, override `speak()` function to display “Bark” and “Meow” respectively. SOLUTION…. C++ Virtual Function Example #include <iostream> using namespace std; // Base class class Animal { public: virtual void speak() { // Virtual function cout << “Animal sound” << endl; } }; // […]

Create an abstract class `Employee` with a pure virtual function `calculateSalary()`. Derive classes `FullTime` and `PartTime` and implement salary calculations.

Create an abstract class `Employee` with a pure virtual function `calculateSalary()`. Derive classes `FullTime` and `PartTime` and implement salary calculations. SOLUTION…. C++ Abstract Class Example #include <iostream> using namespace std; // Abstract class class Employee { protected: string name; int empID; public: Employee(string n, int id) : name(n), empID(id) {} virtual void calculateSalary() = 0; […]

Create a base class `Shape` with virtual function `area()`. Derive `Rectangle` and `Triangle` to override `area()` and use a base class pointer to call functions.

Create a base class `Shape` with virtual function `area()`. Derive `Rectangle` and `Triangle` to override `area()` and use a base class pointer to call functions. SOLUTION…. C++ Virtual Function Example #include <iostream> using namespace std; // Base class class Shape { public: virtual void area() { // Virtual function cout << “Base Shape area (not […]

Create classes `Student`, `Test`, `Sports`, and `Result` to demonstrate hybrid inheritance. Accept data and display total marks.

Create classes `Student`, `Test`, `Sports`, and `Result` to demonstrate hybrid inheritance. Accept data and display total marks. SOLUTION…. C++ Hybrid Inheritance Example #include <iostream> using namespace std; // Base Class: Student class Student { protected: int roll; string name; public: void inputStudent() { cout << “Enter Roll No: “; cin >> roll; cout << “Enter […]

Create class `Student` and `Sports` to accept marks and sports score respectively. Derive a class `Result` from both and display total score.Demonstrate multiple Inheritance.

Create class `Student` and `Sports` to accept marks and sports score respectively. Derive a class `Result` from both and display total score.Demonstrate multiple Inheritance. SOLUTION…. Multiple Inheritance in C++ C++ Program: Multiple Inheritance Example #include <iostream> using namespace std; // Base class 1 class Student { protected: int marks; public: void getMarks(int m) { marks […]