CS112: Lab 7 :: Loops, file listings, working with images

Task 1. A guessing game

Write a script called lucky to play a guessing game with the user. Your loop will keep asking for guesses until the user either 1) guesses correctly or 2) quits. Your output might look something like this (in the example below, my lucky number is 14):

 
  >>lucky  
   Guess my lucky number (q to quit) ==> 2
   Nope, that's not it, guess again ==> 5
   Nope, that's not it, guess again ==> 10
   Nope, that's not it, guess again ==> 25
   Nope, that's not it, guess again ==> 100
   Nope, that's not it, guess again ==> q
  >> 
  >>lucky  
   Guess my lucky number (q to quit) ==> 18
   Nope, that's not it, guess again ==> 50
   Nope, that's not it, guess again ==> 14
   YAHOOOOO!!!!  You got it!!!
  >>
 

Task 2. Listing files in a folder/directory in MATLAB

Write a MATLAB script called filelist to list the full names of the *.m files in your current directory. Your output should look something like this (with your username in place of slee below):
 
 >>filelist 
 /Users/slee/Desktop/assign5_programs/lucky.m
 /Users/slee/Desktop/assign5_programs/filelist.m
 /Users/slee/Desktop/assign5_programs/displayCurves.m

Note that these built-in MATLAB commands might be useful: pwd, dir, mkdir, filesep.

Task 3. Reading in and writing out an image

Write a short MATLAB script called makeNegative that reads in an image, creates the negative image, and then writes the negative image into a new folder called negatives.

For example, your script can read in the color image harry.jpg (shown below, left) and then transform it to a negative version (shown below, right), and write the new image into a new negatives folder.

Prelude to Assignment 5

Assignment 5 (due Wednesday, March 16) contains two Problems.
You'll write code from scratch to create thumbnail images from a set of class photos and allow the user to select their favorites, and a program to explore the interaction of supply and demand.
Click here for the Assignment.

Uploading your saved work

Use Fetch to upload your saved work.
Work-in-progress should go into your personal cs112/ folder.