Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

assignment2_Advanced Python_UHasselt

The assignment requires students to implement two classes in Python: Stack and InfixExpression, with specific methods and functionalities outlined for each. It emphasizes the importance of individual work, warns against plagiarism, and specifies submission guidelines including file naming and content requirements. The assignment will be graded based on functionality and code quality, with a strict deadline of March 16, 2025.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

assignment2_Advanced Python_UHasselt

The assignment requires students to implement two classes in Python: Stack and InfixExpression, with specific methods and functionalities outlined for each. It emphasizes the importance of individual work, warns against plagiarism, and specifies submission guidelines including file naming and content requirements. The assignment will be graded based on functionality and code quality, with a strict deadline of March 16, 2025.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Advanced Programming in Python

Assignment 2: OOP

Due date is 16/03/2025 at 23:59

The assignment is strictly individual. Plagiarism and cooperation will be


thoroughly checked by hand, and by specialised software. Not only copying
other peoples code, but also giving your source code to other students will
be considered as fraud. Using solutions from the internet, even very small
portions are considered as plagiarism.
When we detect fraud, conform with the exam regulations (OER), we
will inform the exam comity, which will start a fraud process (see the OER).
Unfortunately, every academic year students get caught; we hope that this
will not be the case this year.

Questions
Implement the following programs in python:

1. Implement Stack class that is used to create and instantiate stack objects. Stack is a data
structure that contains data but restricts accessing the saved data in a LIFO (last in first
out) manner. In other words, the last element added to the stack is the first one to be
removed. You are required to add at least the following instance methods to your class:

ˆ push(x): adds an element x to the top of the stack;


ˆ pop(): removes and returns the element on the top of the stack; and
ˆ empty(): is a boolean method that checks whether the stack is empty or not.

If you tried to pop an empty stack, then you should return a KeyError exception with the
custom message "You can not pop an empty stack.".
To know more about stacks and a possible implementation of it, check this link [1].

2. Implement InfixExpression class that is used to create and instantiate expressions in


infix notations as objects. This class has one string attribute expression which holds the
value of the expression. For example, "A+B" is a possible value of such expression. Make
sure to define that attribute as a private attribute and add setter and getter for it using
decorators. You are also required to add the following instance methods to your class:

ˆ update_expression(self, operator, expression) where operator is a character


and expression is a string which represents another expression. The method should
not return anything, rather it should update the expression of the InfixExpression
object. Precisely, it should set the expression of the InfixExpression object to

1
be (le)op(re) where le is the expression of the object, op is operator, and re is
expression.
Example
Let e be an InfixExpression whose expression has the value "A+B*C". Then
– e.update_expression("-", "D") updates the expression of the infix expression
e to be "(A+B*C)-(D)"; and
– e.update_expression("^", "D/(E-F)") updates the expression of the infix ex-
pression e to be "(A+B*C)^(D/(E-F))".
ˆ convert_to_postfix(self) that uses the class Stack to return a string which is the
expression in postfix notation. You have to consider only the following five arithmetic
operators: ^, * , / , + , and - .
Example
Let e1, e2, and e3 be three InfixExpression objects whose expressions have the
values "A+B*C", "A*B+C", and "A*(B+C)"; respectively. Then
– e1.convert_to_postfix()= "ABC*+";
– e2.convert_to_postfix()= "AB*C+"; and
– e3.convert_to_postfix()= "ABC+*".

Submission and Grading Criteria


First of all, do not solve the assignment in multiple files. We expect from you one file
that contains all the solutions of the assignment’s questions. In case you are not solving all
the questions, then make sure that you also include the functions of the unsolved questions
in your submission with pass in the body. Moreover, your solution file must have the name
assignment2.py; otherwise, the tests will not run. Also, make sure that file begins with
"""
author : [ firstname lastname ]
studentnumber : [ your studentnumber ]
"""
Before the deadline make sure to submit the solution file through Blackboard.

Helper Functions You can define as many additional functions as you want. Help functions
should start with an underscore. But all solutions should not exceed 500 lines. In fact, 500 lines
is extremely generous bound. You need much less than that.

Grading The assignments are graded by both hand and unit tests. That means the results
of the functions should be precisely as expected by the given unit tests. Check the test file
test assignment2.py on Blackboard. Do not edit that file except for the imports if needed.
In grading we do not only look at functionality, but we also take code quality (including comments
in the code) into account.

References
[1] Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers. How to Think Like
a Computer Scientist. http://openbookproject.net/thinkcs/python/english3e/index.
html, 2012. [Online; accessed 14-July-2019].

You might also like