OODP Week 3 Programs
OODP Week 3 Programs
Week – 3
-Pranshu Bharti
RA2311033010104
CINTEL AK – 1
PROGRAM 1:
#include <iostream>
#include <vector>
#include <sstream>
int main() {
vector<int> arr;
int option, i = 0, n, x;
string buffer;
istringstream ssin;
bool bub_swap;
while (true) {
cout << "(3) Sort the array using insertion sort method" << endl;
cout << "(4) Sort the array using selection sort method" << endl;
cout << "(5) Sort the array using bubble sort method\nSelect: ";
switch (option) {
case 1:
break;
case 2:
break;
case 3:
int j = i - 1;
arr[j + 1] = arr[j];
j--;
arr[j + 1] = key;
break;
case 4:
int min_idx = i;
min_idx = j;
}
}
arr[min_idx] = arr[i];
arr[i] = temp;
break;
case 5:
bub_swap = false;
bub_swap = true;
arr[j + 1] = temp;
break;
default: return 0;
return 0;
OUTPUT:
PROGRAM 2:
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
int main() {
int a, b;
cin >> a >> b;
cout << add(a,b) << endl;
return 0;
}
OUTPUT:
PROGRAM 3:
#include <iostream>
class BankAccount {
private:
std::string account_number;
double balance;
public:
if (amount > 0) {
balance += amount;
std::cout << "Deposited " << amount << ". New balance: " << balance << std::endl;
} else {
std::cout << "Invalid deposit amount. Amount must be greater than 0." << std::endl;
if (amount > 0) {
balance -= amount;
std::cout << "Withdrew " << amount << ". New balance:" << balance << std::endl;
} else {
} else {
std::cout << "Invalid withdrawal amount. Amount must be greater than 0." << std::endl;
}
void check_balance() {
};
int main() {
account.deposit(1500);
account.withdraw(300);
account.check_balance();
return 0;
OUTPUT:
PROGRAM 4:
#include <iostream>
#include <string>
#include <vector>
class Student {
private:
std::string name;
std::string id;
std::vector<int> grades;
public:
grades.push_back(grade);
double calculateAverageGrade() {
int sum = 0;
sum += grade;
void displayInfo() {
};
int main() {
student.addGrade(95);
student.addGrade(92);
student.displayInfo();
return 0;
OUTPUT:
PROGRAM 5:
#include <iostream>
#include <string>
class Employee {
private:
std::string name;
std::string id;
double hourlyWage;
double hoursWorked;
public:
double calculateWeeklySalary() {
void displayInfo() {
};
int main() {
employee.displayInfo();
return 0;
}
OUTPUT:
PROGRAM 6:
#include <iostream>
#include <string>
class Product {
private:
std::string name;
std::string brand;
double price;
int capacity;
public:
void displayDetails() {
std::cout << "Capacity: " << capacity << " ml" << std::endl;
}
};
int main() {
waterBottle.displayDetails();
return 0;
OUTPUT:
PROGRAM 7:
#include <iostream>
#include <vector>
using namespace std;
vector<int> merge_arrays(vector<int> a, vector<int> b) {
int m = a.size(), n = b.size(), i = 0, j = 0;
vector<int> c;
bool a_pushed, b_pushed;
for(int k = 0; k < m+n; k++) {
if ((a[i] <= b[n-1-j] && i < m) || j >= n) {
c.push_back(a[i]);
i++;
}
else {
c.push_back(b[n-1-j]);
j++;
}
}
return c;
}
int main() {
vector<int> A = { 3, 5, 8, 18, 33, 56 };
vector<int> B = { 99, 88, 77, 66, 55, 44, 33, 22, 11, 0 };
vector<int> C = merge_arrays(A, B);
for (int i : C) {
cout << i << " ";
}
cout << endl;
return 0;
}
OUTPUT:
PROGRAM 8:
#include <iostream>
int main() {
int n, a, b, c;
int ways = 0;
ways++;
return 0;
OUTPUT:
PROGRAM 9:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class library {
int roll_no;
string name;
int book_code;
public:
library(int r,string n,int code) {
roll_no = r;
name = n;
book_code = code;
}
void display() {
cout << "Roll No:" << roll_no << endl;
cout << "Name of the Student:" << name << endl;
cout << "Code of Book Accessed:" << book_code << endl;
}
};
int main() {
int t_roll, t_code;
string t_name;
cin >> t_roll >> t_name >> t_code;
library lib1(t_roll, t_name, t_code);
cin >> t_roll >> t_name >> t_code;
library lib2(t_roll, t_name, t_code);
lib1.display();
lib2.display();
return 0;
}
OUTPUT:
PROGRAM 10:
#include <iostream>
#include <vector>
using namespace std;
class room {
int l,b,h;
public:
room() {
l = 0;
b = 0;
h = 0;
}
room(int _l, int _b, int _h) {
l = _l;
b = _b;
h = _h;
}
int area() { return l * b; }
};
class house {
int hno, no_rooms;
vector<room> rooms;
string name, city, state;
public:
house(string _name, string _city, string _state, int _hno, int _n)
{
name = _name;
city = _city;
state = _state;
hno = _hno;
no_rooms = _n;
}
void add_room(int l, int b, int h) {
room temp(l, b, h);
rooms.push_back(temp);
}
int area() {
int a = 0;
for (room r : rooms) {
a += r.area();
}
return a;
}
};
int main() {
string name, city, state;
int hno, n, l, b, h;
cin >> name >> hno >> city >> state >> n;
house A(name, city, state, hno, n);
for (int i = 0; i < n; i++) {
cin >> l >> b >> h;
A.add_room(l, b, h);
}
cout << "House name: " << name << endl;
cout << "House address: " << hno << ", " << city << ", " <<
state << endl;
cout << "House no of rooms: " << n << endl;
cout << "House area: " << A.area() << endl;
return 0;
}
OUTPUT: