Exp Oop
Exp Oop
5(A)
#include <iostream>
class Number {
private:
public:
num Number() {
void displaySquare() {
cout << "Square of " << num << " is: " << (num * num) << endl;
void displayCube() {
cout << "Cube of " << num << " is: " << (num * num * num) << endl;
};
int main() {
Number n;
n.displaySquare();
n.displayCube();
return 0;
Output:
EXP NO 5(B)
#include <iostream>
class Student {
private:
int rollNo;
string name;
long PRN;
float totalMarks;
float percentage;
public:
rollNo = r;
name = n;
PRN = p;
totalMarks = marks;
// Function to calculate
percentage void
calculatePercentage() {
cout << "Total Marks: " << totalMarks << "/500" << endl;
cout << "Percentage: " << percentage << "%" << endl;
};
int main() {
percentage s.displayDetails();
return 0;
Output:
EXP NO 5( C )
#include <iostream>
class Book {
private:
string bookName;
string authorName;
float price;
long ISBN;
public:
isbn) {
bookName = bName;
authorName = aName;
price = p;
ISBN = isbn;
bookName = b.bookName;
authorName = b.authorName;
price = b.price;
ISBN = b.ISBN;
};
int main() {
endl; book1.displayDetails();
cout << "\nDetails of Book 2 (Copied from Book 1):" << endl;
book2.displayDetails();
return 0;
Output:
EXP NO : 6 ( A )
#include <iostream>
class Employee {
private:
int emp_id;
string name;
string designation;
float salary;
public:
// Default
constructor
Employee() {
emp_id = 0;
name = "Unknown";
designation = "Not
cout << "Default Constructor called for Employee ID: " << emp_id << endl;
// Parameterized constructor
{ emp_id = id;
name = emp_name;
designation = desig;
salary = sal;
cout << "Parameterized Constructor called for Employee ID: " << emp_id << endl;
cout << "Destructor called for Employee ID: " << emp_id << endl;
};
int main() {
emp1.displayDetails();
emp2.displayDetails();
// Destructor will be called automatically when program ends or objects go out of scope
return 0;
}
Output:
EXP NO 6 ( B)
#include <iostream>
class Number {
private:
int value;
public:
// Constructor
Number(int v = 0) : value(v) {}
return Number(-value);
// Function to display
};
int main() {
n3.display();
Number n4 = n1 + n2;
n4.display();
return 0;
Output:
EXP NO : 7 (A)
#include <iostream>
// Base class
class Person {
protected:
string name;
int age;
public:
};
// Derived class
{ private:
int roll_no;
public:
};
int main() {
Student s1;
details s1.readStudentDetails();
n"; s1.displayStudentDetails();
return 0;
}
Output:
EXP NO: 7( B)
#include <iostream>
// Base class 1
class Person {
protected:
string name;
int age;
public:
};
// Base class 2
class Company {
protected:
string company_name;
public:
};
// Derived class
{ private:
int emp_id;
public:
};
int main() {
Employee emp;
details emp.readEmployeeDetails();
n"; emp.displayEmployeeDetails();
return 0;
Output:
EXP NO: 7(C)
#include <iostream>
// Base class
class Person
{ protected:
string name;
int age;
public:
void readPersonDetails()
void displayPersonDetails() {
};
protected:
int emp_id;
public:
void readEmployeeDetails()
{ readPersonDetails();
cin.ignore();
void displayEmployeeDetails() {
displayPersonDetails();
};
protected:
int student_id;
public:
void readStudentDetails()
{ readPersonDetails();
cin.ignore();
void displayStudentDetails()
{ displayPersonDetails();
};
// Derived class 3 (Hybrid Inheritance)
private:
int work_hours;
public:
void readPartTimeEmployeeDetails() {
readEmployeeDetails();
void displayPartTimeEmployeeDetails() {
displayEmployeeDetails();
};
int main() {
PartTimeEmployee pt_emp;
pt_emp.readPartTimeEmployeeDetails();
pt_emp.displayPartTimeEmployeeDetails();
return 0;
}
Output: