Instructions
For this assignment you should place each solution in a separate directory. Each directory should contain a Makefile that builds the code in that directory, and, your solution, e.g.,
|-- P1 | |-- Makefile | |-- solution.c |-- P2 | |-- Makefile | |-- solution.c |-- P3 | |-- Makefile | |-- solution.c |-- P4 |-- Makefile |-- solution.c
Each C source file should have a main
function
at the end of the file. All other function definitions for your solution should be
before main
.
The body of main
should contain all your test.
You should use assert.h
and assert
to write your test.
Problem 1: Calculate rental
You are asked to design a program to calculate the cost of
a rental car. The rental company charges $1.00 per hour.
However, if usage of the car adds up to a full day (24
hours) then the company charges $30. On top of the usage
charges, the customer has to also pay a 17% service charge.
Design a function named rental_cost_total
that consumes a
the number of hours a car was rented, and returns the total amount due in
dollars.
Problem 2: Dealing with arrays
-
Design a function called
bubble_sort
that given an array ofint
s, and the size of the array, updates the array and places the integers in order from smallest to largest. -
Design a function called
replace_all
that given an arrays ofchar
s, the size of the array, and twochar
sa
andb
, updates the input array and replaces all occurrences ofa
withb
. -
Design a function called
print_row
that takes in a two dimensional array of integers, the width and height of the 2d array, and an integer,r
, and prints the row at indexr
as one line with each element separated by a coma. -
Design a function called
print_column
that takes in a two dimensional array of integers, the width and height of the 2d array, and an integer,c
, and prints the column at indexc
as one line with each element separated by a coma.
Problem 3: Coordinates and Shapes
-
Design a function called
cartesian_distance
that consumes two coordinates and returns the distance between the two coordinates. A coordinate is made up of two integers, one to represent the x coordinate and one to represent the y coordinate. -
Design a function called
circles_overlap
that consumes two circles and returns true if the circles overlap and false otherwise. A circle is made up of a coordinate that designates its center and its radius. -
Design a function called
squares_overlap
that consumes two squares and returns true if the squares overlap and false otherwise. A squares is made up of the coordinate of its top left hand corner and the size of its side.
Problem 4: Students and Grades
You are asked to design a program that will calculate the final grade for each student in a class. A Student is represented by using
- the student id, an integer
- an array of 5 integers; each integer is between 0 and 100.
A Class is represented as an array of Students. The final grade for each student is the average of the 5 integers that represent the homework grades.
The output of your program prints should print the student's identity number a colon and the final grade. One student per line, e.g.,
123 : 45 345 : 90 349 : 88