OOPS Lab Session
OOPS Lab Session
1. Bank Account Management Create a BankAccount class that simulates a bank account. The
class should have methods to deposit, withdraw, and check the account balance. Implement
the necessary constructors and accessors. Write a program to demonstrate the functionality of
the BankAccount class.
Test cases:
CODE:
#include <iostream>
class student
{private:
int deposit;
int withdraw;
public:
void getset()
cin>>deposit;
cin>>withdraw;
balance+=deposit-withdraw;
void showme()
{cout<<"deposit :"<<deposit<<endl;
cout<<"withdraw :"<<withdraw<<endl;
if (balance>=0)
{ cout<<"balance :"<<balance<<endl;}
else
};
int student::balance = 0;
int main()
{class student a;
class student b;
a.getset();
a.showme();
b.getset();
b.showme();
2. Question: Create a class called Stack that represents a stack data structure. It should have
methods push(), pop(), and isEmpty() to add elements, remove elements, and check if the
stack is empty, respectively. Implement the stack using an array. Write a program that
demonstrates the functionality of the Stack class by performing push and pop operations.
Test cases:
Stack Operations:
1. Push
2. Pop
3. Exit
Pushed element: 10
Stack Operations:
1. Push
2. Pop
3. Exit
Pushed element: 20
Stack Operations:
1. Push
2. Pop
3. Exit
Popped element: 20
Stack Operations:
1. Push
2. Pop
3. Exit
Popped element: 10
Stack Operations:
1. Push
2. Pop
3. Exit
#include <iostream>
class Stack {
private:
int stk[100];
int index;
public:
Stack() {
index = 0; // initialize index to 0
~Stack() {
void push() {
int n;
cin >> n;
stk[index++] = n;
void pop() {
if (index > 0) {
index = index - 1;
cout << "Popped element is: " << stk[index] << endl;
} else {
};
int main() {
int x = 0;
Stack s1;
while (x != 3) {
cout << "Stack Operations:\n1. Push\n2. Pop\n3. Exit\nEnter your choice: ";
cin >> x;
if (x == 1) {
s1.push();
} else if (x == 2) {
s1.pop();
return 0;