0% found this document useful (0 votes)
2 views2 pages

Mini Project Info

This document outlines two mini projects for an OOP course in Python. The first project involves creating a class to perform arithmetic operations on complex numbers, including addition, subtraction, multiplication, and comparisons. The second project focuses on converting a hexadecimal number to its binary equivalent using string manipulation and ASCII values.

Uploaded by

Nihal Ben
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)
2 views2 pages

Mini Project Info

This document outlines two mini projects for an OOP course in Python. The first project involves creating a class to perform arithmetic operations on complex numbers, including addition, subtraction, multiplication, and comparisons. The second project focuses on converting a hexadecimal number to its binary equivalent using string manipulation and ASCII values.

Uploaded by

Nihal Ben
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/ 2

TRAVAUX DIRIGES MINI PROJECT : OOP in python

Cours/Module : INF2031-OOP Enseignant : M. A. EL AISSAOUI


Système de Management Qualité – ISO 9001, version 2000 V00

I- MINI PROJECT Arithmetic Operations on Complex Numbers


This mini project will make use of various concepts of object-oriented programming such as
constructor,self-parameter, creating instance of class and overloading of inbuilt functions.
Explanation of Complex Numbers
Complex numbers can be written in the form a + bi where a and b are real numbers and i is the unit
imaginary number, i.e. -1 . The values of a and b can be zero. Complex numbers contain two parts,
viz. real and imaginary.
Valid examples of complex numbers are: 2 + 6i, 1 – i, 4 + 0i
Addition of Two Complex Numbers
(a + bi) + (c + di) = (a + c) + (b + d)i
(2 + 1i) + (5 + 6i) = (2 + 5) + (1 + 6) i = (7+7i)
Subtraction of Two Complex Numbers
(a + bi) - (c + di) = (a - c) + (b - d)i
(2 + 1i) - (5 + 6i) = (2 - 5) + (1 - 6) i = (-3 - 5i)
Multiplication of Two Complex Numbers
(a + bi) * (c + di) = (ac – bd) + (ad + bc)i
(2 + 1i) * (5 + 6i) = (2*5 - 1*6) + ((2*6)i +(1*5)i ) = 4 + 17i
PROBLEM STATEMENT
Write a program to perform the following operations on complex numbers.
(a) Addition
(b) Subtraction
(c) Multiplication
(d) Check if two complex numbers are equal or not
(e) Check if C1 >= C2
(f) Check if C1 <= C2
Note:
Make use of the following inbuilt methods to implement the above functions.
__add__ method to overload + Operator
__sub__ method to overload – Operator
__mul__ method to overload * operator
__le__ method to overload < operator
__ge__ method to overload > operator
Algorithm
• STEP 1: Create a class named Complex.
• STEP 2: Create the constructor of the class Complex using the init method. The constructor will
have two parameters, viz. one each to store the real and the imaginary part.
• STEP 3: Create such other methods for add, sub, mul to perform addition, subtraction and
multiplication, respectively. Define all the functionalities of these operations by making use of
inbuilt functions.
• STEP 4: Also define the inbuilt methods to check if two complex numbers are equal or if the first
complex number is greater than the second.
• STEP 5: Create two instances of Complex class C1 and C2 to declare two complex numbers.

ECOLE POLYTECHNIQUE PRIVEE D’AGADIR


- 1 -© Propriété Exclusive de l’Ecole Polytechnique Privée d’Agadir Universiapolis, Technopole d’Agadir, Bab Elmadina, Agadir
Tél : 05 28 23 34 34
TRAVAUX DIRIGES MINI PROJECT : OOP in python

Cours/Module : INF2031-OOP Enseignant : M. A. EL AISSAOUI


Système de Management Qualité – ISO 9001, version 2000 V00

• STEP 6: Use these two instances to perform all the operations.


Output
First Complex Number is as Follows: ( 2 , 1 )
Second Complex Number is as Follows: ( 5 , 6 )
Addition of two complex Number is as follows: ( 7 , 7 )
Subtraction of two Complex Number is as follows: ( -3 , -5 )
Multiplication of two Complex Number is as follows: ( 4 , 17 )
Compare Two Complex Numbers: False
Checking if C1 is Greater than C2: False
Checking if C1 is Less than C2: True

II- MINI PROJECT Conversion of Hexadecimal Number into its


Equivalent Binary Number
Program Statement
Write a program to convert a hexadecimal number entered as a string into its equivalent binary
format.
Note: Use ord() to obtain the ASCII value of a character.
Sample Input
Please Enter the Hexadecimal Number: 12FD
Output
Equivalent Binary Number is
0001 0010 1111 1101
Algorithm
• STEP 1: Read the hexadecimal number as a string from the user.
• STEP 2: Pass ‘h’, i.e. the number as a string to a function named ‘hex_to_bin(h)’
• STEP 3: Inside function hex_to_bin(h), traverse each character of string ‘h’. Check if the
character inside the string contains values in between ‘A’ and ‘F’. Then add 10 to the difference
between ASCII values, i.e. (ord(‘ch’) – ord(‘A’)) + 10 and pass the obtained sum ‘X’ as string
to function dec_bin(X).
• STEP 4: Calculate the equivalent binary number of x and print the same.

ECOLE POLYTECHNIQUE PRIVEE D’AGADIR


- 2 -© Propriété Exclusive de l’Ecole Polytechnique Privée d’Agadir Universiapolis, Technopole d’Agadir, Bab Elmadina, Agadir
Tél : 05 28 23 34 34

You might also like