Professional Documents
Culture Documents
OOPS Practical
OOPS Practical
Q.1 Design an employee class for reading and displaying the employee
information, the getInfo() and displayInfo() methods will be used
respectively where getinfo() will be private method.
Code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Employee
{
private:
char name[50];
int age;
double salary;
void getInfo()
{
clrscr();
public:
void displayInfo()
{
getInfo();
clrscr();
cout << "\nEmployee information:\n";
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Salary: $" << salary << endl;
getch();
}
};
void main()
{
Employee emp;
emp.displayInfo();
getch();
}
void getInfo()
{
clrscr();
public:
void displayInfo()
{
getInfo();
clrscr();
cout << "\nEmployee information:\n";
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Grade: " << grade << endl;
getch();
}
};
void main()
{
Student student;
student.displayInfo();
getch();
}
Q.3 Design the class Demo which will contain the following methods:
readNo(), factorial() for calculating the factorial of a number,
reverseNo() will reverse the given number, isPalindrome() will check
the given number is palindrome, isArmstrong() which will calculate
the given number is armStrong or not.Where readNo() will be private
method.
class MyClass
{
private:
int privateVar;
public:
// Constructor
MyClass()
{
privateVar = 0;
}
// Member function declaration
void setPrivateVar(int value);
void displayPrivateVar();
};
void MyClass::displayPrivateVar()
{
cout << "Private Variable: " << privateVar << endl;
}
int main()
{
// Create an instance of the MyClass
MyClass myObject;
// Access class members using member functions
myObject.setPrivateVar(42);
myObject.displayPrivateVar();