Assignment 03
Assignment 03
Assignment 03
Design Methodologies
Homework 03
Fall 2023
1 Submission Policy
You need to submit this homework on 13th October at 6:00pm, on LMS. Late
submissions are allowed until 15th October 11:59pm, which will be penalized
by 20%. Your work will not be accepted once the submission is closed on
LMS.
2 Guidelines
• You need to do this homework alone.
• Some assignments will require you to submit multiple files. Always Zip
and send them.
• It is better to submit the work that you have done yourself than what
you have plagiarized.
• It is strongly advised that you start working on the assignment the day
you get it. Assignments WILL take time.
1
• Every assignment you submit should be a single zipped file containing
all the other files. Suppose your name is John Doe and your id is 0022
so the name of the submitted file should be JohnDoe0022.zip
• DO NOT send your assignment to your instructor, if you do, your
assignment will get ZERO for not following clear instructions.
• You can be called in for Viva for any assignment that you submit
You will be using the sample file, Input.txt for this assignment. Your
code should however take into account that if an entry is increased or reduced
(5 lines per entry) it reads all the entries in the file (You are going to assume
that there are no errors in the file). For example, if there is just one entry:
Elton John
34
AB218
9
7
Based on this entry, the driver’s name is Elton John, the truck has 34 liters
of petrol in its tank, its registration number is AB218. It covers 9 km per
liter if empty and 7 km per liter when loaded.
The function loadTrucks() reads the file Input.txt, and populates a BST
of trucks according to information given in the file. You can compare a
truck variable is less than other truck variable on the basis of its registration
number, hence based on this comparison you can populate the binary search
2
tree. As you read information of a truck, a new BSTNode is created and
inserted in proper location in the BST.
The function makeJourney() traverses all the trucks and updates their re-
maining fuels after a truck takes cargo and travel 60 km, drop the cargo
and return empty based on the fuel consumptions. For example, the truck
information given above can make this journey, as it has 34 litres petrol in its
tank and it requires 60/9 + 60/7 = 15.23 litre of petrol. Hence the remaining
fuel in this truck would be 18.77 litre. Those trucks who are unable to make
the journey will will not travel, and hence their fuel information will not be
updated.
The above-mentioned functions that you need to implement are part of the
TruckInventory class that stores a BinarySearchTree object as a private
variable. All details of implementation of the binary search tree are to be
hidden in the BinarySearchTree class that you need to implement. The
node structure that the tree uses is BSTNode defined in node.h. You may
add functions to the BSTNode class as per the needs of the BinarySearchTree
implementation. Finally, BSTNode stores the Truck object that is defined in
the truck.hpp file. You may also need to add functionality to the Truck
class to support the binary search.
4 HUMania
A sample code is given in HUMania folder, if you run it you can see a pigeon
is moving slightly towards right side. This example creates just one variable
of Unit type, and draws pigeon taken from assets file.
You are required to create 3 different types of objects drawn on the screen:
Pigeon, Butterfly and Bee. As you click on the screen the function createOb-
ject is called with mouse coordinates given in x, y variables. You have to
create a pigeon, butterfly or a bee randomly on the screen. You’ll be main-
taining 3 different std::vectors (refer to section 5), one for each of the type
of item drawn. Please refer to section 4.1, you only have to change srcRect
to draw different type of items.
3
Figure 1: SDL Drawing Basics
Animations: As you draw the objects on screen, you also have to animate
them. For this purpose, you cycle through the 3 different states of the object
as given in assets file. All of the objects should keep moving slightly towards
right, and when an object is reached to right most corner of the screen, it
should reappear from the left most corner of the screen.
4
the srcRect values to get a flying animation.
5 std::vector Tutorial
Following is a basic example to work with vector. Complete reference for
C++ vector is given here https://en.cppreference.com/w/cpp/container/
vector
#include<iostream>
#include<vector>
struct Distance{
int feet, inches;
};
int main(){
vector<Distance> dst; // It’s a vector that can store Distance
type objects
dst.push_back(Distance{3, 4}); // create an object, and push it
in vector
dst.push_back(Distance{5, 2});
dst.push_back(Distance{2, 7});
dst.push_back(Distance{7, 8});
dst.push_back(Distance{13, 1});
for(int i=0;i<dst.size();i++)
cout<<dst[i].feet<<"’"<<dst[i].inches<<’"’<<endl; // call
show method of dst[i] object
}
5
6 Some important points:
• Sample code is there for your benefit. If you are going to use it, under-
stand how it works.
• You do not need to follow the code given exactly. You can make changes
where you see fit provided that it makes sense.
• You need to define separate *.hpp and *.cpp files for all the classes.
• Exact x,y,w,h values for images in assets file can be found by http:
//www.spritecow.com/.
6
7 Rubric
8 Credits
Some questions in this assignment are derived from the work of Dr. Umair
Azfar Khan.