0% found this document useful (0 votes)
7 views

OOP Prem

oop

Uploaded by

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

OOP Prem

oop

Uploaded by

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

Name : Borawake Prem Girish

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;
}

istream &operator>>(istream &, Complex &i)


{
cin >> i.real >> i.img;
return cin;
};

ostream &operator<<(ostream &, const Complex &d)


{
cout << d.real << " + " << d.img << "i" << endl;
return cout;
};

Complex Complex ::operator+(Complex c1)


{
Complex temp;
temp.real = real + c1.real;
temp.img = img + c1.img;
return temp;
};
Complex Complex ::operator*(Complex c2)
{
Complex tmp;
tmp.real = ((real * c2.real) - (img * c2.img));
tmp.img = ((real * c2.img) + (img * c2.real));
return tmp;
};

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****************************

Enter Real and Imaginary part of the Complex Number 1 :


32
Enter Real and Imaginary part of the Complex Number 2 :
12
Complex Number 1 : 3 + 2i

Complex Number 2 : 1 + 2i

********* MENU **********


1. Addition of Complex Numbers
2. Multiplication of Complex Numbers
3. Exit
Enter your choice from above MENU (1 to 3) : 1
Addition : 4 + 4i

Do you wan to perform another operation (y/n) :


Y
Complex Number 1 : 3 + 2i

Complex Number 2 : 1 + 2i

********* MENU **********


1. Addition of Complex Numbers
2. Multiplication of Complex Numbers
3. Exit
Enter your choice from above MENU (1 to 3) : 2
Multiplication : -1 + 8i

Do you wan to perform another operation (y/n) :


Y
Complex Number 1 : 3 + 2i

Complex Number 2 : 1 + 2i

********* MENU **********


1. Addition of Complex Numbers
2. Multiplication of Complex Numbers
3. Exit
Enter your choice from above MENU (1 to 3) : 3

***
Name : Borawake Prem Girish
Class : SE Div : A
Roll No : 21 Subject : OOP
****************************************************************
Practicle : 02

#include <iostream>

#include <string.h>

using namespace std;

class studData;

class student

string name;

int roll_no;

string cls;

char *division;

string dob;

char *bloodgroup;

static int count;

public:

student()

name = "";

roll_no = 0;

cls = "";

division = new char;

dob = "dd/mm/yyyy";

bloodgroup = new char[4];

~student()

delete division;
delete[] bloodgroup;

static int getCount()

return count;

void getData(studData *);

void dispData(studData *);

};

class studData

string address;

long int* telno;

long int* dlno;

friend class student;

public:

studData()

address = "";

telno = new long;

dlno = new long;

~studData()

delete telno;

delete dlno;

void getstudData()

cout<< "Enter Contact Address : ";


cin.get();

getline(cin, address);

cout << "Enter Telephone Number : ";

cin>>*telno;

cout<<"Enter Driving License Number : ";

cin>>*dlno;

void dispstudData()

cout<<"Contact Address : "<<address<<endl;

cout<<"Telephone Number : "<<*telno<<endl;

cout<<"Driving License Number : "<<*dlno<<endl;

};

inline void student::getData(studData* st)

cout<<" Enter Student Name : ";

getline(cin,name);

cout<<"Enter Roll Number : ";

cin>>roll_no;

cout<<"Enter Class :";

cin.get();

getline(cin,cls);

cout<<"Enter Division :";

cin>>division;

cout<<"Enter Date of Birth :";

cin.get();

getline(cin,dob);

cout<<"Enter Blood Group :";

cin>>bloodgroup;
st->getstudData();

count++;

inline void student::dispData(studData* st1)

cout<<"Student Name : "<<name<<endl;

cout<<"Roll Number : "<<roll_no<<endl;

cout<<"Class : "<<cls<<endl;

cout<<"Division : "<<division<<endl;

cout<<"Date of Birth : "<<dob<<endl;

cout<<"Blood Group : "<<bloodgroup<<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++;

cout<<"Do you want to add another student (y/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<<"Total students : "<<student::getCount();

cout<<endl<<"-----------------------------------------------------";

for(int i=0;i<n;i++)

delete stud1[i];

delete stud2[i];

return 0;

}
*****************************OUTPUT****************************

Enter Student Name : Prem Borawake

Enter Roll Number : 21

Enter Class : SE

Enter Division : A

Enter Date of Birth : 15/06/2005

Enter Blood Group : B+

Enter Contact Address : 8261905243

Enter Telephone Number : 1234567890

Enter Driving License Number : Prem143

Do you want to add another student (y/n) : -------------------------------------------------------Student Name :


Prem Borawake

Roll Number : 21

Class : SE

Division : A

Date of Birth : 15/06/2005

Blood Group : B+

PS C:\Users\Prem\OneDrive\Desktop\C++ Code\OOP pratical>

***
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;
}
};

class Book : public Publication {


private:
int page_count;

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";
}
};

class Tape : public Publication {


private:
float play_time;

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

Enter your choice: 1

Enter the Publication information:


Enter Title of the Publication: Techneo
Enter Price of Publication: 399
Enter Page Count of Book: 459

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 1

Enter the Publication information:


Enter Title of the Publication: Disha
Enter Price of Publication: 399
Enter Page Count of Book: 789

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 2

Enter the Publication information:


Enter Title of the Publication: OLD Songs
Enter Price of Publication: 399
Enter Play Duration of the Tape (in minutes): 20.14

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 2

Enter the Publication information:


Enter Title of the Publication: RedTape
Enter Price of Publication: 399
Enter Play Duration of the Tape (in minutes): 31.36

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 3

* * * BOOK PUBLICATION DATABASE SYSTEM * * *

Title Of Publication: Techneo


Publication Price: 399
Page Count: 459

Title Of Publication: Disha


Publication Price: 399
Page Count: 789

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 4

* * * TAPE PUBLICATION DATABASE SYSTEM * * *

Title Of Publication: OLD Songs


Publication Price: 399
Play Time: 20.14 min

Title Of Publication: RedTape


Publication Price: 399
Play Time: 31.36 min

* * * PUBLICATION DATABASE SYSTEM * * *


1. Add Information to Books
2. Add Information to Tapes
3. Display Books Information
4. Display Tapes Information
5. Exit

Enter your choice: 5


Exiting the system.
PS C:\Users\rushi\OneDrive\Desktop\OOP Practicle>

***
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);

for (int i = 0; i < n; i++) {


cout << "Enter information for Employee " << (i + 1) << ": ";
o[i].accept();
f.write((char*)&o[i], sizeof(o[i]));
}
f.close();
ifstream f_in;
f_in.open("demo.txt", ios::in);
cout << "\nEmployee data from file:\n";
for (int i = 0; i < n; i++) {
o[i].display();
}
f_in.close();
return 0;
}
*****************************OUTPUT****************************

Enter the number of employees you want to store: 3


Enter information for Employee 1: Enter Name: Kunal Bhalerao
Enter ID: 123
Enter Salary: 120000
Enter information for Employee 2: Enter Name: Prem Borawake
Enter ID: 234
Enter Salary: 100000
Enter information for Employee 3: Enter Name: Tejas Sonawane
Enter ID: 456
Enter Salary: 90000

Employee data from file:

Name: Kunal Bhalerao


ID: 123
Salary: 120000

Name: Prem Borawake


ID: 234
Salary: 100000

Name: Tejas Sonawane


ID: 456
Salary: 90000
PS C:\Users\rushi\OneDrive\Desktop\OOP Practicle>

***
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>

using namespace std;

int main()

typedef map<string, float> mapType;

mapType populationMap;

populationMap.insert(make_pair("Maharashtra", 125));

populationMap.insert(make_pair("Uttar Pradesh", 225));

populationMap.insert(make_pair("Bihar", 120));

populationMap.insert(make_pair("West Bengal", 100));

populationMap.insert(make_pair("Madhya Pradesh", 90));

populationMap.insert(make_pair("Tamil Nadu", 80));

populationMap.insert(make_pair("Andhra Pradesh", 53));

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("UT Delhi", 19));

populationMap.insert(make_pair("UT Jammu and Kashmir", 14));

populationMap.insert(make_pair("Uttarakhand", 12));

populationMap.insert(make_pair("Meghalaya", 4));

populationMap.insert(make_pair("Lakshadweep", 0.06));

populationMap.insert(make_pair("UT Ladakh", 0.0006));


cout << "Total states and UTs of India: " << populationMap.size() << endl;

for (auto iter = populationMap.begin(); iter != populationMap.end(); ++iter)

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: ";

cin >> ws;

getline(cin, state);

auto iter = populationMap.find(state);

if (iter != populationMap.end())

cout << state << "'s population is " << iter->second << " million\n";

else

cout << "State is not in population map.\n";

cout << "Do you wish to continue? (y/n): ";

cin >> c;

} while (c == 'y' || c == 'Y');

populationMap.clear();

return 0;

}
*****************************OUTPUT****************************
Total states and UTs of India: 17

Andhra Pradesh: 53 million

Bihar: 120 million

Chhattisgarh: 30 million

Haryana: 29 million

Kerala: 38 million

Lakshadweep: 0.06 million

Madhya Pradesh: 90 million

Maharashtra: 125 million

Meghalaya: 4 million

Odisha: 47 million

Tamil Nadu: 80 million

UT Delhi: 19 million

UT Jammu and Kashmir: 14 million

UT Ladakh: 0.0006 million

Uttar Pradesh: 225 million

Uttarakhand: 12 million

West Bengal: 100 million

Enter the name of the state you want to know the population of: Maharashtra

Maharashtra's population is 125 million

Do you wish to continue? (y/n): y

Enter the name of the state you want to know the population of: Uttarakhand

Uttarakhand's population is 12 million

Do you wish to continue? (y/n): y


Enter the name of the state you want to know the population of: Kerala

Kerala's population is 38 million

Do you wish to continue? (y/n): y

Enter the name of the state you want to know the population of: Chhattisgarh

Chhattisgarh's population is 30 million

Do you wish to continue? (y/n): n

***

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy