DUE DATE: 23 September, 2015 @ 11:59pm

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

  1. Design a function called bubble_sort that given an array of ints, and the size of the array, updates the array and places the integers in order from smallest to largest.
  2. Design a function called replace_all that given an arrays of chars, the size of the array, and two chars a and b, updates the input array and replaces all occurrences of a with b.
  3. 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 index r as one line with each element separated by a coma.
  4. 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 index c as one line with each element separated by a coma.

Problem 3: Coordinates and Shapes

  1. 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.
  2. 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.
  3. 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

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