CS368 Homework 3
| ||
AnnouncementsCheck here periodically.
| ||
ProblemsIn this homework you will gain experience writing functions in MATLAB as well as doing user (console) and file input and output. The main program (the outline of which is provided for you) interacts with the user to test the functions you have written. Note: in order to get full credit for the functions you write in this assignment, you may NOT use any control-flow statements (like if, for, or while) in your functions. You must make use of MATLAB's ability to perform mathematical operations on entire vectors (or matrices) of information. The calculateGPA functionDefine a function named calculateGPA in a file named calculateGPA.m. The calculateGPA function takes one input argument: a file name (i.e., a string). The string passed in to the function must be the name of a text-only file with exactly three columns of numbers (separated by spaces). Each line in the file corresponds to one course: the first column is the semester in which the course was taken (e.g., 1, 2, 3), the second column is the grade received in the course (0.0 to 4.0), and the third column is the number of credits for the course. The function computes and returns the overall grade point average (GPA) for the student. You may assume that the filename passed in to the calculateGPA function is the name of a file that exists and has the correct format and that all values in the file are in the correct range. Note that because the input file just contains a matrix of numbers, you can use a simple load command to read it in. The calculatePercent functionDefine a function named calculatePercent in a file named calculatePercent.m. The calculatePercent function computes a weighted percentage based on three vectors of scores passed as arguments to the function: exams, homeworks, and quizzes (in that order).
Exams are worth 60% of the overall score, homeworks are worth 25%, and quizzes are worth 15%. The value returned by calculatePercent should be between 0 and 100 (e.g., 87.65). Your calculatePercent function must work for matrices of input as well as row vectors of input. In other words, it must be able to take a N × E matrix of exam scores, a N × H matrix of homework scores, and a N × Q matrix of quiz scores, calculate the percentages for each of the N rows, and return a column vector of the N percentages. The main program (homework3.m)The main program will be the homework3.m script. The file homework3.m contains an outline; use it as a starting point. The program presents the user with a menu of choices of functions to test along with an option to quit. The user makes a selection, the program performs the selected test, and the user is presented with the menu of choices again. The process repeats until the user selects 'quit'. You will need to add code to implement the choices that test the functions so that they do the following:
Tips and hints:
| ||
Handing inUpload your m-files to your Dropbox in Learn@UW. See these instructions for uploading files to a Learn@UW Dropbox. The files you should upload are:
In order for your work to be considered to have been turned in on-time, you must upload your files to your Learn@UW Dropbox by 11:59 pm Wednesday, March 2. | ||
Last Updated: 2/21/2016 © 2016 Beck Hasti, hasti@cs.wisc.edu |