

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: General Computer Science for Engineers; Subject: Computer/Information Sciences; University: University of Delaware; Term: Spring 2009;
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CISC 106, Spring 2009
1.(30 points) Write the Selection Sort algorithm first in pseudocode in a text editor (emacs) and save it in a .txt file called pseudoSelectionSort.txt. Then implement the Selection Sort algorithm in a function that takes as its input an array of random integers. Call this function selectionSort1.m Use the following code to generate a 10 element array of random integers.
input = round(rand(1,10)*100);
Call your selection sort algorithm using the 10 element random number array as input. Your function should print out the unsorted input array you began with and sorted array at the end. Create a diary, selectionDiary.txt , of you creating the random input from the command window and calling selectionSort1.m.
input = round(rand(2,10)*10);
Call your second selection sort algorithm using the 20 element random number array as input. Your function should print out the unsorted input array you began with and sorted array at the end. Create a diary selection2Diary.txt of you creating the random input from the command window and calling selectionSort2.m
3.Using the MATLAB patch function. The patch command can be used to draw one or more polygons by defining the coordinates of its vertices. You can use this command to draw shapes on a plot. e.g. goldfish or a shark.
Type the following into the graphical MATLAB interpreter:
patch([6 7 7 6], [6 6 7 7], 'g')
What do you see? The first array is the x-coordinates and the second array is the y-coordinates. E.g. the points respectively would be (6,6), (7,6), (7,7), (6,7). These points form a square. What does the ‘g’ mean? What are the bounds of your current plot?
Now type:
patch([8 9 9 8], [8 8 9 9], 'b')
This draws another square up and to the right of the first square.
Assignment:
(5 points) Now draw a red triangle and a green pentagon on the same plot using the patch command. Make sure the two shapes are not touching. Print out your plot as a png file titled twoShapes.png.
(5 points) Save your commands as a script file called twoShapes.m.
(20 points) Now draw an 8 by 8 checkerboard using either for or while loops and ONLY ONE patch command inside the loop(s). Your checkerboard will alternate between red and blue squares. Save this as a script file called drawCheckerboard.m.
For more information about the patch command see: www.mathworks.com/access/helpdesk/help/techdoc/ref/ patch .html