#include <iostream>
using namespace std;
class Employee {
private:
int emp_id;
string name;
string address;
public:
// Function to accept employee details
void accept() {
cout << "Enter Employee ID: ";
cin >> emp_id;
[Link](); // Ignore newline character
cout << "Enter Employee Name: ";
getline(cin, name);
cout << "Enter Employee Address: ";
getline(cin, address);
}
// Function to display employee details
void display() {
cout << "\nEmployee ID: " << emp_id;
cout << "\nName: " << name;
cout << "\nAddress: " << address << "\n";
}
};
int main() {
Employee emp[3]; // Array of 3 Employee objects
// Accept data for 3 employees
for (int i = 0; i < 3; i++) {
cout << "\nEnter details for Employee " << i + 1 << ":\n";
emp[i].accept();
}
// Display data for 3 employees
cout << "\nDisplaying Employee Details:\n";
for (int i = 0; i < 3; i++) {
emp[i].display();
}
return 0;
}
#include <iostream>
using namespace std;
class Rectangle {
private:
float length, breadth;
public:
// Default constructor initializing length and breadth
Rectangle() {
length = 5.0; // Default length
breadth = 3.0; // Default breadth
}
// Function to calculate area
float calculateArea() {
return length * breadth;
}
// Function to display the area
void display() {
cout << "Length: " << length << ", Breadth: " << breadth << endl;
cout << "Area of Rectangle: " << calculateArea() << endl;
}
};
int main() {
Rectangle rect; // Object created using default constructor
[Link](); // Display area
return 0;
}
#include <iostream>
using namespace std;
class Circle {
private:
float radius;
public:
// Parameterized constructor
Circle(float r) {
radius = r;
}
// Function to calculate circumference
float calculateCircumference() {
return 2 * 3.1416 * radius;
}
// Function to display the circumference
void display() {
cout << "Radius: " << radius << endl;
cout << "Circumference of Circle: " << calculateCircumference() << endl;
}
};
int main() {
float r;
cout << "Enter radius of the circle: ";
cin >> r;
Circle c(r); // Object created with user-specified radius
[Link](); // Display circumference
return 0;
}
#include <iostream>
using namespace std;
class Student {
private:
int stud_id;
string name;
float marks;
public:
// Function to accept student details
void accept() {
cout << "Enter Student ID: ";
cin >> stud_id;
[Link](); // Ignore newline character
cout << "Enter Student Name: ";
getline(cin, name);
cout << "Enter Marks: ";
cin >> marks;
}
// Function to display student details
void display() {
cout << "\nStudent ID: " << stud_id;
cout << "\nName: " << name;
cout << "\nMarks: " << marks << "\n";
}
};
int main() {
Student stud[2]; // Array of 2 Student objects
// Accept data for 2 students
for (int i = 0; i < 2; i++) {
cout << "\nEnter details for Student " << i + 1 << ":\n";
stud[i].accept();
}
// Display data for 2 students
cout << "\nDisplaying Student Details:\n";
for (int i = 0; i < 2; i++) {
stud[i].display();
}
return 0;
}