OOP Pract. 17

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

0 •e@OINDEX O@e• 0

Name. Joshi Shweta Kiran

Roll no. 21420

Enrollment no. 2012280095

Subject. OOP

..
·•- - -
·•--- -------
---·-
--•-·---•·
..
·•---
·-----
·•-
·•-
· -- -- ... --··
-- ----
---·
·-
·• -
·-
·• -
·- -·---·--
-----
·-
·•·-
-
·•-- -- ---
·•
·• --
·- - ---·---- -· - -
,, _ . 1

I -'- .
-'-

• . ::lb eore+,

; - - - - - - - t - - - - - - -'_ _ _ _ _ _ _ _ __ _ _ _ J

A\g or-i +bm /,step -s

§ e J_ vQ I l , e c ) +,,
f ?.!Ge

o-12

, -

j
Coding C++ MENU
Auto saved at 01 :40:02
<iostream>
std;

Complex {
fHl vate :
float real;
fluc1l imag;

public :

Complex() : real(0),
0), imag(0) {}

vo1cl input() {
cout <<
cin >> real;
cin >> imag;

Complex operator+ ( cor,st Complex& obj) {


Complex temp;
temp.real= real+ obj.real;
temp.imag = imag + obj.imag;
temp;

void output( ) {
(imag < 0)
cout << << real << imag <<

cout << << real << << i

rnt main() {
Complex complex1, complex2, result;

cout <<
complex1 . input();

cout <<
complex2.input();

result= complex1 + complex2;


result.output();
Compile Result

Enter first complex number:


Enter real and imaginary parts respectively:
9 5
Enter second complex number:
Enter real and imaginary parts respectively:
7 6
Output Complex number: 16+11i
[Process completed - press Enter]

••
••

•~
1111111 a
111111

Coding C++ MENU
Auto saved at 01 :40:18
<iostream>
std;

Complex {
p1-1vate :
float real;
float imag;

public :

Complex() : real(O), imag(O) {}

VOlcl input() {
cout <<
cin >> real;
cin >> imag;

Complex operator+ ( canst Complex& obj) {


Complex temp;
temp.real= real+ obj.real;
temp.imag = imag + obj.imag;
temp;

vo1cl output() {
(imag < 0)
cout << << real << imag <<

cout << << real << << i

irH main() {
Complex complex1, complex2, result;

cout <<
complex1 . input();
cout <<
complex2.input();

result= complex1 + complex2;


result.output();
Compile Result

Enter first complex number:


Enter real and imaginary parts respectively:
3 8
Enter second complex number:
Enter real and imaginary parts respectively:
6 2
Output Complex number: 9+10i
[Process completed - press Enter]

••
••

II Tliai ,___ II .
1111111 ■ II .
111111 •
-
•m·
Compile Result

Enter Two Complex Numbers 4 9


Enter Two Complex Numbers 5 1
Entered Values
4+9i
5+1i

Addition of Real and Imaginary Numbers


9+10i

[Process completed - press Enter]

••
••

II ,._ _ _ ., II .
1111111 ■ •
111111

•m
Coding C++ MENU
Auto saved at 01 :45:16
<iostream>
std;

Complex

111t num1, num2;


public :
vo1cl accept()

cout<<
cin>>num1 >>num2;

Complex operator+(Complex c1, Complex c2);

vo1cl display()

cout<<num1 << <<num2<< <<

Complex c;
c.num1=c1.num1+c2.num1;
c.num2=c1.num2+c2.num2;
(c);

int main()

Complex c1,c2, sum;

c1. accept();
c2.accept();

sum= c1+c2;

cout<<
cout<<
c1. di splay();
cout<<
c2.display();

cout<<
cout<<
sum. di splay();
Compile Result

Enter Two Complex Numbers 2 5

Enter Two Complex Numbers 7 7


Entered Values
2+Si
7+7i

Addition of Real and Imaginary Numbers


9+12i

[Process completed - press Enter]

lill ■■
111111

Coding C++ RUN MENU
Auto saved at 01 :49:06
<iostream>
std;
FLOAT
{
floclt a;

pul)] l c :
FLOAT ( f lo,lt a)
{
->a=a;
}

float operator+( FLOAT F)


{
(a+ F.a);
}

f 10,7 t operator-( FLOAT F)


{
(a- F.a);
}

float operator*( FLOAT F)


{
(a*F.a);
}

f 10,7 t: operator/( FLOAT F)


{
(a / F.a);
}

};

1111 main()
{
FLOAT f1(10 . 10),f2(20 . 20);

cout<< <<f1+f2;
cout<< <<f1-f2;
cout<< <<f1*f2;
cout << <<f1 / f2;

o·,
Compile Result

Operator+ 30.3

Operator -10.1

Operator* 204.02

Operator/ 0.5
[Process completed - press Enter]

••
••

II
••••
111111
-
•m · "' II :--'I

,. .,I
.

\
Coding C++ MENU
Auto saved at 01 :50:48
<iostream>
std;
FLOAT

flo,1t a;

public :
FLOAT (f l ocit a)
{
->a=a;

flocit operator+( FLOAT F)


{
(a+ F.a);

flocit operator-( FLOAT F)

(a - F.a);

float operator*( FLOAT F)


{
(a*F.a);

flocit operator / ( FLOAT F)

(a / F.a);

int main()

FLOAT f1(40.40),f2(70.70);
1(40.40),f2(70.70);

cout<< <<f1+f2;
cout<< <<f1 - f2 ;
c out<< <<f1*f 2 ;
cout<< <<f1 / f2;
Compile Result

Operator+ 111.1

Operator -30.3

Operator* 2856.28

Operator/ 0.571429
[Process completed - press Enter]

••
••

II ,__, II .
1111111 •
1111·
BIi .. - \:

-e
. __,~ '
,., -. - · - -
. -

@ ◄ EN·MR ► ,
Coding C++ MENU
Auto saved at 01 :54:39

<est ring>
<iostream>
<string .h>

std;

CompareString {

publ1c :

char- str [25];

CompareString( chai- str1[])


{

strcpy( ->str, str1);


}

1nt operator==(CompareString s2)

(strcmp(str, s2.str) == 0)
1;

mt operator<=(CompareString s3)

(strlen(str) <= strlen(s3 . str))


1;
Coding C++ MENU
Auto saved at 01 :54:39

11H operator>=(CompareString s3)

(strlen(str) >= strlen(s3.str))


1;

void compare(CompareString s1, CompareString s2)


{

(s1 == s2)
cout << s1.str <<
<< s2.str << endl;
{
cout << s1.str <<
<< s2.str << endl;
(s1 >= s2)
cout << s1 .str <<
<< s2.str << endl;

cout << s2.str <<


<< s1.str << end!;

vo1cl testcase1()
{

CflcllStr1 [] =
chc11 str2[] =

CompareString s1(str1);
CompareString s2(str2);

cout << <<s1.str<<


<< s2.str << << endl;

compare(s1, s2);
}

vo1cl testcase2()
{

chM str1 [] =
chc11 str2[] =
Compile Result

Comparing "friend" and "Brother"


friend is not equal to Brother
Brother is greater than friend

Comparing "Friend" and "Brother"


Friend is not equal to Brother
Brother is greater than Friend

[Process completed - press Enter]

••
••
....

.66- ,__,, II .
'
- - - ·. ,----

.
II Ea
.~.. y rn II .
.

••••
.

[ ]: ~

. --

111111 i

.
-
... .
'

II
..
'

.J
I

-· Xi C
...
.

.... '?'
i

~ -


.

\:

EN·MR
--
.
-
- :


• I

,
.
Coding C++ MENU
Auto saved at 02:00:13
<iostream>
<string.h>

std;

CompareString {

. pub l 1 c :

ch,:ff str[25];

Compa rest ring( c hc1, st r1 [] )


{

strcpy( ->str, str1);


}

int operator==(CompareString s2)

(strcmp(str, s2.str) == 0)
1;

rnt operator<=(CompareString s3)

(strlen(str) <= strlen(s3.str))


1;

int operator>=(CompareString s3)

(strlen(str) >= strlen(s3.str))


" ,,
Coding C++ MENU
Auto saved at 02:00:13

void compare(CornpareString s1, CompareString s2)


{

(s 1 == s2)
cout << s1 .str <<
<< s2.str << endl;
{
cout << s1 . str <<
<< s2.str << endl;
(s1 >= s2)
cout << s1.str <<
<< s2 . str << endl;

cout << s2 . str <<


<< s 1. str << endl;

void testcase1()
{

ch.:ff str1 [] =
char str2[ ] =

CornpareString s1(str1);
CornpareString s2(st r2 );

cout << << s1. st r <<


<< s2 . str << << endl;

compare(s1, s2);
}

vo1el testcase2()
{

char- str1 [] =
char- str2 [] =

CornpareString s1(s tr1 );


CornpareString s2(str2);

cout << << s1.str <<


<< s2.str << << endl:
II 11
Compile Result

Comparing "sadness" and "happyness"


sadness is not equal to happyness
happyness is greater than sadness

Comparing "family" and "people"


family is not equal to people
family is greater than people
[Process completed - press Enter]

••
••

ll_r-._ '"- - - - -" II .


1111111 ■, ~
t .

111111 .
-· ~

'9,
~.
1 I
·C
~
- _,,,
'?'
-
V,
·•
--\ :--: -
◄ EN·MR
-.
.

► ,

You might also like