Professional Documents
Culture Documents
Oop Lab 5
Oop Lab 5
TECHNOLOGY
JALANDHAR, PUNJAB
OBJECT ORIENTED PROGRAMMING
LAB
SESSION:2022-26
SUBMITTED BY:
NAME: BHUMIKA
BRANCH: CSE
a) Get its three sides from the user using getdata() function. (The function must be defined
outside
the class)
c)Display the area(The function must be defined outside the class, but made inline)
#include <iostream>
class Triangle {
private:
public:
void getData();
double calculateArea() {
};
void Triangle::getData() {
std::cout << "Enter the lengths of the three sides of the triangle: ";
std::cout << "The area of the triangle is: " << area << std::endl;
}
int main() {
triangle1.getData();
displayArea(area1);
triangle2.getData();
displayArea(area2);
triangle3.getData();
displayArea(area3);
return 0;
OUTPUT
Program 2: Make the student class with
-display_data()- To display all the details and total marks (Nest total()
function in this function)
#include <iostream>
#include <string>
class Student {
private:
int rollno;
std::string name;
int marks[3];
int totalMarks;
public:
rollno = r;
name = n;
marks[0] = m1;
marks[1] = m2;
marks[2] = m3;
int calculateTotal() {
return totalMarks;
void display_Data() {
};
int main() {
Student student1;
student1.display_Data();
return 0;
}
OUTPUT
Program 3: WAP that create class BankAccount to manage bank accounts. Each account has
an account number and a balance. Implement the following requirements using static data
members and static member functions:
1) The BankAccount class should have a static data member totalAccounts to keep track of
the total number of bank accounts created.
2)The BankAccount class should have a static member function getTotalAccounts() that
returns the total number of bank accounts created.
3)Each time a new account is created, the totalAccounts count should be updated.
#include<iostream>
class bankaccount{
private:
int account_no;
double balance;
public:
account_no=accountnumber;
balance=intibalance;
totalaccounts++;
}
return totalaccounts;
};
int bankaccount::totalaccounts=0;
int main(){
bankaccount account_no1(1001,5000.0);
bankaccount account_no2(1002,7890.5);
return 0;
OUTPUT