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 two classes `Alpha` and `Beta`, each with private data. Use a friend function to calculate and display the sum of their private data.
Create two classes `Alpha` and `Beta`, each with private data. Use a friend function to calculate and display the sum of their private data. SOLUTION…. C++ Friend Function Example #include <iostream> using namespace std; class Beta; // Forward declaration // Class Alpha class Alpha { private: int a; public: void input() { cout << “Enter […]
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 a base class `Shape`, and derive classes `Rectangle` and `Triangle`. Use functions to input dimensions and calculate area of each shape.
Create a base class `Shape`, and derive classes `Rectangle` and `Triangle`. Use functions to input dimensions and calculate area of each shape. SOLUTION…. Pure Virtual Function Example in C++ #include <iostream> using namespace std; // Base class class Shape { public: virtual void input() = 0; // Pure virtual function virtual void area() = 0; […]
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 […]
What is operator overloading? Write different rules to overload operators. Also, explain Operator overloading with an example.
ASSIGNMENT ASSIGNMENT ASSIGNMENT Q.1 Explain Codd’s Rules. Answer :- Codd’s rules, proposed by Dr. Edgar F. Codd in 1985, serve as a benchmark for evaluating whether a database management system (DBMS) is truly relational. Codd originally defined 12 rules, including a rule 0, which collectively outline the characteristics a system must exhibit to qualify as […]
