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

Unit 5 Assignment Questions

The document outlines a series of programming assignments focused on object-oriented design, including the creation of various classes such as Rectangle, Lunch, BankAccount, and more. Each assignment specifies methods and functionalities that need to be implemented, ranging from basic operations to more complex interactions between classes. The tasks are categorized into easy, medium, and difficult questions, covering a wide range of programming concepts and skills.

Uploaded by

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

Unit 5 Assignment Questions

The document outlines a series of programming assignments focused on object-oriented design, including the creation of various classes such as Rectangle, Lunch, BankAccount, and more. Each assignment specifies methods and functionalities that need to be implemented, ranging from basic operations to more complex interactions between classes. The tasks are categorized into easy, medium, and difficult questions, covering a wide range of programming concepts and skills.

Uploaded by

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

2020

Unit V: Assessment: Assignments

Easy Questions

1.Define a class named Rectangle which can be constructed by a length and width.The Rectangle
class has a method which can compute the area.

2. Define a class called Lunch. It’s __init__() method should have two arguments: self and menu
where menu is a string. Add a method called menu_price. It will involve an if statement:

 if "menu 1" print "Your choice:", menu, "Price 12.00", if "menu 2" print "Your choice:",
menu, "Price 13.40", else print "Error in menu".
 To check if it works define: Paul=Lunch("menu 1") and call Paul.menu_price()

3.Create a class named triangle. The constructor for this class should take two numeric
arguments, which are the width and height. Add methods to compute the area and perimeter of
the triangle, as well as methods that simply return the height and width. Add a method isequi()
that returns a Boolean value if the triangle is equilateral.

Medium Questions

4.Develop a class BankAccount that supports these methods:

a)__init__():Initializes the bank account balance to the value of the input argument ,or to 0 if
no input argument is given

b) withdraw():Takes an amount as input and withdraws it from the balance

c) deposit():Takes an amount as input and adds it to the balance

d) balance():Returns the balance on an account

>>>x=BankAccount(500)

>>>x.balance()

500.00

1 Department of Computer Science & Engg, PESU


2020
Unit V: Assessment: Assignments

>>>x.withdraw(70)

>>>x.balance()

430.00

>>>x.deposit(10)

>>>x.balance()

440.00

5.Implement two subclasses of class Person that supports these methods:

a) __init__():A constructor that takes as input a person’s name (as a string) ,birth year(as an
integer)and person’s degree
b) age(): Returns the age of a person(use function localtime() from the Standard library
module time to compute the age)
c) name():Returns the name of the person
d) degree():Returns the degree of the instructor.

The class Student,also a subclass of class Person ,that supports:

__init__():Constructor that takes the person’s major in addition to name and birth year
major(): Returns the major of the student
Your implementation of the three classes should behave as shown in the text code:
>>>x=Instructor(‘Guido Von Rossum’,1973,’PhD’)
>>>x.age()
47
>>>y=Student(‘jones’,’1987,’’computer science’)
>>>y.age()
33
>>>y.major()

2 Department of Computer Science & Engg, PESU


2020
Unit V: Assessment: Assignments

‘Computer Science’
>>>x.degree()
‘PhD’

6.Write a program which has list of user data (tuples containing a username, email and age) and
adds each user to a directory if the user is at least 16 years old. You do not need to store the age.
Write a exception which defines a different exception for each of these error conditions:

 the username is not unique


 the age is not a positive integer
 the user is under 16
 the email address is not valid (a simple check for a username, the @ symbol and a domain
name is sufficient)
Raise these exceptions in your program where appropriate. Whenever an exception occurs, your
program should move onto the next set of data in the list. Print a different error message for each
different kind of exception.

7.Write a class named Circle with attributes center and radius ,where center is a Point object and
radius is a number.Instantiate a Circle object that represents a circle with its center at ( 150, 100 )
and radius 70.

a) Write a function point_inside that takes a Circle and a Point and returns True if the Point
lies in or on the boundary of the circle.
b) Write a function named rect_inside that takes a Circle and a Rectangle and returns True
ifthe Rectangle lies entirely in or on the boundary of the circle.
c) Write a function rect_overlaps_circle() that takes a Circle and a Rectangle and returns
True if any of the corners of the Rectangle fall inside the circle.

8.Create Hindimovies class ,Make methods to:

i)Dispaly-Display all movie names on day show basis

3 Department of Computer Science & Engg, PESU


2020
Unit V: Assessment: Assignments

ii)Addnewmovie-adding new movie name to the list of movies.

iii) Deletemovie-delete movie if it is running more than 100 days.

iv) ratingmovie-display the rating based on number of days running (suppose100 days:10 90
days:9 etc...)

9.Create a employee class,Make methods to:

i) display-Display all information of employee(like-name,id,salary,designation,


experiance,address).

ii) addincrement-add increment to salary based on experiance,ie,

a) 2years-500RS per month.

b) above 2years 1000 per month.

c) more than 5 years 5000 per month.

10. Create a deck of cards class.( Internally, the deck of cards should use another class, a card
class. Make methods to:

i)Deal()-method to deal a single card from the deck.

ii)removecard()-After a card is dealt, it is removed from the deck.

iii)shuffle()-method which makes sure the deck of cards has all 52 cards and then rearranges
them randomly.

Note:The Card class should have a suit (Hearts, Diamonds, Clubs, Spades) and a value
(A,2,3,4,5,6,7,8,9,10,J,Q,K)

Difficult Questions

11. Create a Pizza class with the attributes order_number and ingredients . Only the ingredients
will be given as input.Make to choose a ready made pizza flavour rather than typing out the
ingredients manually.

4 Department of Computer Science & Engg, PESU


2020
Unit V: Assessment: Assignments

Name Ingredients
hawaiian ham, pineapple
meat_festival beef, meatball, bacon
garden_feast spinach, olives, mushroom

12.Create an class, “Box”, and has the following methods:


a) add() for adding any number of items to the box,
b) empty() for taking all the items out of the box and returning them as a list
c) count() for counting the items which are currently in the box.
Write a class named “Item” which has a name attribute and a value attribute – you can assume
that all the items you will use will be Item objects. Box” has two subclasses “ListBox” should use
a list, and “DictBox” should use a dict.

13.Write a function, repack_boxes, which takes any number of boxes as parameters, gathers up all
the items they contain, and redistributes them as evenly as possible over all the boxes. Order is
unimportant. Test your code with a ListBox with 25 items, a ListBox with 10 items and a DictBox
with 6 items. You should end up with two boxes with 10 items each, and one box with 11 items.

14.Create a class time and initialize it with hours and minutes.


a) create a method add_Time which should take two time object and add them.
E.g.- (2 hour and 50 min)+(1 hr and 20 min) is (4 hr and 10 min)
b) create a method display_Time which should print the time.
c) create a method Display_Minute which should display the total minutes in the Time.
E.g.- (1 hr 2 min) should display 62 minute.

15.Create a class called Numbers, which has a single class attribute called MULTIPLIER, and a
constructor which takes the parameters x and y (these should all be numbers).

5 Department of Computer Science & Engg, PESU


2020
Unit V: Assessment: Assignments

a) Write a method called add which returns the sum of the attributes x and y.
b) Write a class method called multiply, which takes a single number parameter a and
returns the product of a and MULTIPLIER.
c) Write a static method called subtract, which takes two number parameters, b and c,
and returns b - c.
d) Write a method called value which returns a tuple containing the values of x and y.
Make this method into a property, and write a setter and a deleter for manipulating
the values of x and y.

16. Briefly describe a possible collection of classes which can be used to represent a music
collection (for example, inside a music player), focusing on how they would be related by
composition. You should include classes for songs, artists, albums and playlists. Hint: write down
the four class names, draw a line between each pair of classes which you think should have a
relationship, and decide what kind of relationship would be the most appropriate.

For simplicity you can assume that any song or album has a single “artist” value (which could
represent more than one person), but you should include compilation albums (which contain
songs by a selection of different artists). The “artist” of a compilation album can be a special value
like “Various Artists”. You can also assume that each song is associated with a single album, but
that multiple copies of the same song (which are included in different albums) can exist.

Write a simple implementation of this model which clearly shows how the different classes are
composed. Write some example code to show how you would use your classes to create an
album and add all its songs to a playlist. Hint: if two objects are related to each other
bidirectionally, you will have to decide how this link should be formed – one of the objects will
have to be created before the other, so you can’t link them to each other in both directions
simultaneously!

6 Department of Computer Science & Engg, PESU

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