CSc 4630/6630 Programming Assignment #1

The first thing in your program should be documentation, such as the following. This should appear at the very top of your program.
  % hmwk1.m
  % Author: (Your Name)
  % Account: (your account name)
  % CSc 4630/6630 Program #1
  % Due date: (put the due date here)
  % Description:
  % (Give a brief description of what your program does.)
  % Input:
  % (State what the program inputs are.)
  % Output:
  % (State what the program outputs are.)
  % Usage:
  % (Give an example of how to use your program.)
  % (For example: out = myabs(in); )
Verify that the command help hmwk1 shows this information.


  1. Practice designing a program.
  2. Practice implementing a program design in MATLAB.
  3. Practice testing a program.
  4. To get familiar with the programming environment.

Your program will prompt the user for a few pieces of information, then print the information back to the command window.

This first assignment is focussed on following the directions and getting used to the environment. Most of these directions will be repeated on all future assignments.

To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Design your program by specifying its behavior, identifying the variables and operations it needs to solve the problem, and then organizing the variables and operations into an algorithm. For our purposes, include functions as operations. Then code your design in MATLAB using stepwise translation. Finally, test your program thoroughly.

Your program should input the user's name, their gender, and their age. Make sure to prompt the user for information, such as "please enter your name: ".

Once the user has entered this information, print the following to the screen: Welcome age year old salutation user-name. If the user enters male for his gender, use the salutation "Mr.". If the user enters female for her gender, use the salutation "Miss" if her age is under 18, or "Ms." if 18 or over.

What if the user does not want to indicate a gender? Your program should allow for this, and change the output accordingly. Use comments within the program to say how you handle this.

Your program should work for all possible inputs. Make sure that you test it with several different cases. For example, what if the age is given as a floating-point number, like 21.4? What if the user enters 0, -10, or 1000? You can assume that the user will enter numbers for the age prompt.

Helpful hint: If you want to print a single quote character, you need to use two in a row, as below.
    disp('driver''s licence');

Turn In Your Work
  1. your source code (hard copy)
  2. the output from at least three different executions in which you test the correctness of your program (using a script*). Use more if the testing needs it. (hard copy)
  3. Also, e-mail your code to the TA. (soft copy)

The printouts of the above must be handed in at the start of class. To be considered "on-time", you must e-mail the TA with the final version of your code before the due date, and turn in all of the above on-time. Make sure that your printouts use a monospaced font.

* A script is short for typescript, where everything typed is saved. This keeps a log of all the input and output. MATLAB provides this capability with the diary command. For example, diary out records all inputs and outputs in a file named ``out''. Do NOT call your script file ``hmwk1.m'', or it may overwrite your homework! Make sure to keep a backup of your work. Type help diary at the MATLAB prompt for more information.

The Mathworks refers to MATLAB programs as scripts. In computing in general, the term "script" can mean a program (i.e. what you make in the MATLAB editor) or it can mean a log (record) of activity (i.e. what is produced by the "diary" command). These are not exactly the same. Consider the simple case of a program with a single line. We can save the one-line program below in a file called simpleExample.m.

  a = 3 + 4

Now suppose we open MATLAB and type the following in the command window.

  diary simpleEx_log.txt
  diary off

The first command creates a new file called simpleEx_log.txt, and starts recording the MATLAB session. The second line above runs our simpleExample.m program, then the last one closes the diary file, and stops recording. When done, the file simpleEx_log.txt looks like this.

  a =
  diary off

Thus we have two files, simpleExample.m which is our program (source code, what you turn in as a hard copy and e-mail to the TA), and simpleEx_log.txt which is a log of our MATLAB session (the output from one execution of our program, what you also turn in as a hard copy).