0% found this document useful (0 votes)
18 views3 pages

OOPClass Activity

Uploaded by

atiq.rehman1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

OOPClass Activity

Uploaded by

atiq.rehman1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP Lab Class Activity

Name: Atiq ur rehman


ID: F2023266530
Section: V8

Task-1:
Code:
#include <iostream>
using namespace std;

class BankManager;
class BankAccount
{
double balance;
friend class BankManager;

public:
BankAccount(double initialBalance) : balance(initialBalance) {}

double getBalance() const


{
return balance;
}
};

class BankManager
{
public:
void setBalance(BankAccount& account, double newBalance)
{
account.balance = newBalance;
}

void printBalance(const BankAccount& account)


{
cout << "The balance= $" << account.balance << endl;
}
};

int main()
{
BankAccount account(22988.0);
BankManager manager;

manager.printBalance(account);

manager.setBalance(account, 568900.0);

manager.printBalance(account);

return 0;
}
Output:

Task-2:
Code:
#include <iostream>
using namespace std;

class Rectangle;
class Point
{
private:
int x, y;

friend bool PointInside(const Point& p, const Rectangle& r);

public:
Point(int x, int y) : x(x), y(y) {}
};

class Rectangle
{
private:
int length, width;

public:
Rectangle(int length, int width) : length(length), width(width) {}

friend bool PointInside(const Point& p, const Rectangle& r);


};

bool PointInside(const Point& p, const Rectangle& r)


{
return (p.x >= 0 && p.x <= r.length) && (p.y >= 0 && p.y <= r.width);
}

int main()
{
Point p(1, 1);
Rectangle r(5, 5);

if (PointInside(p, r))
{
cout << "The point is inside." << endl;
}
else
{
cout << "The point is outside." << endl;
}

return 0;
}

Output:

You might also like