OOP Prem
OOP Prem
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 01
#include <iostream>
using namespace std;
class Complex
{
double real;
double img;
public:
Complex();
friend istream &operator>>(istream &, Complex &);
friend ostream &operator<<(ostream &, const Complex &);
Complex operator+(Complex);
Complex operator*(Complex);
};
Complex::Complex()
{
real = 0;
img = 0;
}
int main()
{
Complex C1, C2, C3, C4;
int flag = 1;
char b;
while (flag == 1)
{
cout << "Enter Real and Imaginary part of the Complex Number 1 : \n";
cin >> C1;
cout << "Enter Real and Imaginary part of the Complex Number 2 : \n";
cin >> C2;
int f = 1;
while (f == 1)
{
cout << "Complex Number 1 : " << C1 << endl;
cout << "Complex Number 2 : " << C2 << endl;
cout << "********* MENU ********** " << endl;
cout << "1. Addition of Complex Numbers" << endl;
cout << "2. Multiplication of Complex Numbers" << endl;
cout << "3. Exit\n";
int a;
cout << "Enter your choice from above MENU (1 to 3) : ";
cin >> a;
if (a == 1)
{
C3 = C1 + C2;
cout << "Addition : " << C3 << endl;
cout << "Do you wan to perform another operation (y/n) : \n";
cin >> b;
if (b == 'y' || b == 'Y')
{
f = 1;
}
else
{
cout << "Thanks for using this program! ! \n";
flag = 0;
f = 0;
}
}
else if (a == 2)
{
C4 = C1 * C2;
cout << "Multiplication : " << C4 << endl;
cout << "Do you wan to perform another operation (y/n) : \n";
cin >> b;
if (b == 'y' || b == 'Y')
{
Complex operator+(Complex);
f = 1;
}
else
cout << "Thanks for using this program! ! \n";
flag = 0;
f = 0;
}
else
{
cout << "Thanks for using this program! ! \n";
flag = 0;
f = 0;
}
}
}
return 0;
}
*****************************OUTPUT****************************
Complex Number 2 : 1 + 2i
Complex Number 2 : 1 + 2i
Complex Number 2 : 1 + 2i
***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 02
#include <iostream>
#include <string.h>
class studData;
class student
string name;
int roll_no;
string cls;
char *division;
string dob;
char *bloodgroup;
public:
student()
name = "";
roll_no = 0;
cls = "";
dob = "dd/mm/yyyy";
~student()
delete division;
delete[] bloodgroup;
return count;
};
class studData
string address;
public:
studData()
address = "";
~studData()
delete telno;
delete dlno;
void getstudData()
getline(cin, address);
cin>>*telno;
cin>>*dlno;
void dispstudData()
};
getline(cin,name);
cin>>roll_no;
cin.get();
getline(cin,cls);
cin>>division;
cin.get();
getline(cin,dob);
cin>>bloodgroup;
st->getstudData();
count++;
cout<<"Class : "<<cls<<endl;
cout<<"Division : "<<division<<endl;
st1->dispstudData();
int student::count;
int main()
student* stud1[100];
studData* stud2[100];
int n=0;
char ch;
stud1[n]=new student;
stud2[n]=new studData;
stud1[n]->getData(stud2[n]);
n++;
cin>>ch;
cin.get();
}
while (ch=='Y' || ch=='y');
for(int i=0;i<n;i++)
cout<<"-------------------------------------------------------";
stud1[i]->dispData(stud2[1]);
cout<<"-----------------------------------------------------------";
cout<<endl<<"-----------------------------------------------------";
for(int i=0;i<n;i++)
delete stud1[i];
delete stud2[i];
return 0;
}
*****************************OUTPUT****************************
Enter Class : SE
Enter Division : A
Roll Number : 21
Class : SE
Division : A
Blood Group : B+
***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 03
#include <iostream>
#include <string>
using namespace std;
class Publication {
private:
string title;
float price;
public:
void add() {
cout << "\nEnter the Publication information:\n";
cout << "Enter Title of the Publication: ";
cin.ignore();
getline(cin, title);
cout << "Enter Price of Publication: ";
cin >> price;
}
void display() {
cout << "\nTitle Of Publication: " << title;
cout << "\nPublication Price: " << price;
}
};
public:
void add_book() {
try {
add();
cout << "Enter Page Count of Book: ";
cin >> page_count;
if (page_count <= 0) {
throw page_count;
}
} catch (...) {
cout << "\nInvalid Page Count! Setting Page Count to 0.\n";
page_count = 0;
}
}
void display_book() {
display();
cout << "\nPage Count: " << page_count << "\n";
}
};
public:
void add_tape() {
try {
add();
cout << "Enter Play Duration of the Tape (in minutes): ";
cin >> play_time;
if (play_time <= 0) {
throw play_time;
}
} catch (...) {
cout << "\nInvalid Play Time! Setting Play Time to 0.\n";
play_time = 0;
}
}
void display_tape() {
display();
cout << "\nPlay Time: " << play_time << " min" << "\n";
}
};
int main() {
Book books[19];
Tape tapes[10];
int ch, b_count = 0, t_count = 0;
do {
cout << "\n* * * PUBLICATION DATABASE SYSTEM * * *";
cout << "\n1. Add Information to Books";
cout << "\n2. Add Information to Tapes";
cout << "\n3. Display Books Information";
cout << "\n4. Display Tapes Information";
cout << "\n5. Exit";
cout << "\n\nEnter your choice: ";
cin >> ch;
switch (ch) {
case 1:
if (b_count < 19) {
books[b_count].add_book();
b_count++;
} else {
cout << "\nBook array is full!\n";
}
break;
case 2:
if (t_count < 10) {
tapes[t_count].add_tape();
t_count++;
} else {
cout << "\nTape array is full!\n";
}
break;
case 3:
cout << "\n* * * BOOK PUBLICATION DATABASE SYSTEM * * *\n";
for (int j = 0; j < b_count; j++) {
books[j].display_book();
}
break;
case 4:
cout << "\n* * * TAPE PUBLICATION DATABASE SYSTEM * * *\n";
for (int j = 0; j < t_count; j++) {
tapes[j].display_tape();
}
break;
case 5:
cout << "Exiting the system.\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
} while (ch != 5);
return 0;
}
*****************************OUTPUT****************************
*** PUBLICATION DATABASE SYSTEM * * *
1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit
***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 04
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Employee {
string Name;
int ID;
double salary;
public:
void accept() {
cout << "Enter Name: ";
cin.ignore();
getline(cin, Name);
cout << "Enter ID: ";
cin >> ID;
cout << "Enter Salary: ";
cin >> salary;
}
void display() {
cout << "\nName: " << Name;
cout << "\nID: " << ID;
cout << "\nSalary: " << salary << endl;
}
};
int main() {
Employee o[100];
int n;
cout << "Enter the number of employees you want to store: ";
cin >> n;
ofstream f;
f.open("demo.txt", ios::out);
***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 06
#include <iostream>
using namespace std;
template<class T>
void selectionSort(T A[], int n) {
int i, j, min;
T temp;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++) {
if (A[j] < A[min]) {
min = j;
}
}
temp = A[min];
A[min] = A[i];
A[i] = temp;
}
cout << "\nSorted array: ";
for (i = 0; i < n; i++) {
cout << A[i] << " ";
}
cout << endl;
}
int main() {
int A[SIZE];
float B[SIZE];
int i, n, ch;
do {
cout << "\n----- MENU -----\n";
cout << "1. Integer Values\n";
cout << "2. Float Values\n";
cout << "3. Exit\n";
cout << "Enter your choice: ";
cin >> ch;
switch (ch) {
case 1:
cout << "\nEnter total number of integer elements: ";
cin >> n;
cout << "\nEnter integer elements: ";
for (i = 0; i < n; i++) {
cin >> A[i];
}
selectionSort(A, n);
break;
case 2:
cout << "\nEnter total number of float elements: ";
cin >> n;
cout << "\nEnter float elements: ";
for (i = 0; i < n; i++) {
cin >> B[i];
}
selectionSort(B, n);
break;
case 3:
exit(0);
break;
default:
cout << "\nInvalid choice! Please try again.\n";
}
} while (ch != 3);
return 0;}
*****************************OUTPUT****************************
----- MENU -----
1. Integer Values
2. Float Values
3. Exit
Enter your choice: 1
Enter total number of integer elements: 5
Enter integer elements: 34 12 25 9 58
Sorted array: 9 12 25 34 58
----- MENU -----
1. Integer Values
2. Float Values
3. Exit
Enter your choice: 2
Enter total number of float elements: 4
Enter float elements: 2.5 5.6 1.3 4.8
Sorted array: 1.3 2.5 4.8 5.6
----- MENU -----
1. Integer Values
2. Float Values
3. Exit
Enter your choice: 3
***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 07
#include <iostream>
#include <map>
#include <string>
int main()
mapType populationMap;
populationMap.insert(make_pair("Maharashtra", 125));
populationMap.insert(make_pair("Bihar", 120));
populationMap.insert(make_pair("Odisha", 47));
populationMap.insert(make_pair("Kerala", 38));
populationMap.insert(make_pair("Chhattisgarh", 30));
populationMap.insert(make_pair("Haryana", 29));
populationMap.insert(make_pair("Uttarakhand", 12));
populationMap.insert(make_pair("Meghalaya", 4));
populationMap.insert(make_pair("Lakshadweep", 0.06));
cout << iter->first << ": " << iter->second << " million\n";
char c;
do
string state;
cout << "\nEnter the name of the state you want to know the population of: ";
getline(cin, state);
if (iter != populationMap.end())
cout << state << "'s population is " << iter->second << " million\n";
else
cin >> c;
populationMap.clear();
return 0;
}
*****************************OUTPUT****************************
Total states and UTs of India: 17
Chhattisgarh: 30 million
Haryana: 29 million
Kerala: 38 million
Meghalaya: 4 million
Odisha: 47 million
UT Delhi: 19 million
Uttarakhand: 12 million
Enter the name of the state you want to know the population of: Maharashtra
Enter the name of the state you want to know the population of: Uttarakhand
Enter the name of the state you want to know the population of: Chhattisgarh
***