0% found this document useful (0 votes)
20 views3 pages

Exercises For May 2023

This document provides programming exercises for students to complete during the week of May 8-12, 2023. The exercises involve: 1) Creating a Library class to manage books, including adding/removing books and printing book information. 2) Creating a Scooter rental class to calculate rental prices based on company, fees, and distance. Students are to write code to display rental options and process rentals/recharges. Students should document their solutions, explain their approaches, and reflect on their experiences with the exercises. Submissions are due by 12:10PM on May 12 for review.

Uploaded by

Precious Ayoade
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)
20 views3 pages

Exercises For May 2023

This document provides programming exercises for students to complete during the week of May 8-12, 2023. The exercises involve: 1) Creating a Library class to manage books, including adding/removing books and printing book information. 2) Creating a Scooter rental class to calculate rental prices based on company, fees, and distance. Students are to write code to display rental options and process rentals/recharges. Students should document their solutions, explain their approaches, and reflect on their experiences with the exercises. Submissions are due by 12:10PM on May 12 for review.

Uploaded by

Precious Ayoade
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/ 3

CSC202/208: Computer Programming II

Rain Semester, 2021/2022 Session

Exercises for the week – 8th – 12th May, 2023


Note that programming exercises will be defended by each student and documented in the Lab
2 space inside the manual. The exercise will be due on Friday 12th May 2023 at 12pm

• Up to 5 points may be earned for each set of programming exercises.


• There is a deadline for this task, and you have multiple opportunities to submit your work
before the deadline.
• While you are strongly encouraged to do so, there is no obligation to solve all tasks
correctly. What counts is the effort you make when trying to solve them.
• Submit your typed documentation via Google Classroom. Also, write in your manual.
• Every department will be given a submission link on Friday 12th May 2023 at 11:45
AM. The submission link will be closed at 12:10 PM same day.

What to do with the Ques.ons in this Exercise:


1) Answer the question by writing the source code using any available python IDE. We
advise you to use Thonny IDE.
2) Write a documentation of your solution inside your CSC202/208 Lab manual. Use the Lab
2 working space inside your lab manual.
3) Do a 5 minute video explaining what and how you understand the exercise, and your
approach in solving the exercise.
4) In your documentation, include the following:
a. The output of the program
b. Flowchart
c. Algorithm
d. Your reflection regarding the solution, what interest you the most in the exercises,
the time it took you to write the source code, the most difficult/challenging part
of solving the exercises, your personal experience when running the code, and
your impression about the exercise. Please, be honest with your reflection.
e. The time it took you to solve each exercise, and the overall time for all the
exercise.

1. Library

Create a class called Book whose constructor's parameters are title, author, number of pages, and type
of a book (novel, fairy tale, detective, etc.). The class also has a method print_info, which prints the
book's information on the screen in a readable form.

Create a class called Library, whose constructor creates an empty list of books. The class must have
the following methods:

• Method add_book, which takes an instance of the class Book as an argument and adds it to
the list of books.
• Method print_books, which prints the information of all the books in the library using the
method print_info.
• Method borrow_book, whose argument is the book title as a string. The capitalization of
letters in the argument may not be correct. The method searches for a book with that title in
the list of books. If the book exists in the list, then removes it from the list and returns the
book instance found. If the book doesn't exist, then leaves the list unchanged and returns the
value None.

Write the main program that creates an instance of the Library class, adds all the books in the
file books.txt to it, and prints all the books in the library to the screen. It then asks the user for the title
of the book they want to borrow. If a book with this name is in the library, the program borrows it and
again prints all books in the library. If the book is not in the library, the program asks the user for the
name of the book again until the user enters the title of an existing book. After that the program
terminates.

2. Scooter rental

Create a class called Scooter, whose constructor's parameters are the name of the rental company,
the starting fee for a ride, the price per 100 meters of riding, and the available riding distance of the
scooter in kilometers.

The class must have the following methods.

• Method price, which takes the length of the ride in kilometers as an argument. If the ride
length requested does not exceed the available riding distance of the scooter, the method
returns the price of a ride of that length, taking into account the starting fee and the price per
100 meters. However, if the ride length exceeds the scooter's available riding distance, the
method returns the integer 1000.
• Method ride, which takes the length of the ride as an argument and subtracts it from the
available riding distance. If the available riding distance becomes exhausted, it assigns the
value 0 to the distance field.
• Method charge, whose argument is the number of kilometers, and which increases the
available riding distance of the scooter by the given number of kilometers.

Create a class called Rental whose constructor's parameter is a list of instances of the class Scooter.

The Rental class must have the following methods.

• Method display_choices, which takes the length of the ride in kilometers as an argument and
prints the name of each scooter and the price of the ride, ordering the scooters from top to
bottom, starting with the cheapest. To find the price of the ride, use the price method.
• Method rent, whose arguments are the name of the scooter the user wants to ride and the
length of the ride. If the requested length does not exceed the available riding distance of the
scooter, then it prints the price of the ride and rides the scooter so many kilometers
(method ride). Otherwise, it prints an appropriate message and does nothing.
• Method charge_scooter, which takes the name of the scooter to be charged and the number
of kilometers as arguments. The method increases the available riding distance of the scooter
by the requested number of kilometers (method charge).
Finally, write a program that prompts the user for the details of three scooters:

• Bolt, 1.5, 0.1, 20


• Tuul, 1, 0.15, 18
• Bird, 0, 0.3, 34

The data for each scooter is entered as one line. All three scooters are added to the list of scooters of
an instance of the Rental class, and then the following methods are called on that instance:

• display_choices(2)
• rent("Bolt", 3)
• rent("Tuul", 18)
• rent("Tuul", 5)
• charge_scooter("Tuul", 5)
• rent("Tuul", 2)

You might also like