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 << "Balance= $" << account.balance << endl;
};
int main()
{
BankAccount account(341289.0);
BankManager manager;
manager.printBalance(account);
manager.setBalance(account, 670912.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: