The objectives for this lab are:
To get started, you can follow this recipe. First create a directory for this course, then a sub-directory for lab one:
mkdir cse20211 mkdir cse20211/lab1Now, change directory (cd) into the newly created directory.
cd cse20211/lab1In this class, we will show you how to use the nano editor, because it is easy to explain, and easy to use when remotely connected. Most Linux systems have several editors, such as gedit, emacs, vi, which you are welcome to figure out and use on your own. To create a text file called myfile.txt, run this command:
nano myfile.txtThe nano editor will start, and show you a mostly blank screen with one title line at the top, and a menu of options at the bottom. Type about five lines of text (anything you like) into the editor. Now, look at the menu at the bottom, where you should see items like ^X Exit, ^K Cut Text and ^U UnCut Text. The ^ (caret) symbol stands for the Control key, so you press Control-X to exit, Control-K to cut text, and so forth. Come back and experiment with the various control keys later. Now, press Control-X to save your file and exit. nano will ask you to confirm and give you the option to change the file name.
Now, you are back at the terminal prompt. You can use the ls command, which lists the files in the current directory:
lsAdding the -l option will show more details about the file:
ls -lThe mv command will move (or rename) a file. Try renaming your file, and then listing the directory again, like this:
mv myfile.txt newfile.txt ls -lThe cp command will copy a file under a new name. Try copying like this:
cp newfile.txt newfile2.txt ls -lFinally, the rm command will remove (delete) a file. Try this:
rm newfile2.txt ls -lYou now know about the following Linux commands: mkdir, cd, ls, mv, cp, and nano. That's enough to get started on most of the assignments in this class. There is much more to learn about Linux, but you will pick it up week by week with practice.
Create a C program (prog3.c) that computes the result of a non-trivial formula of three or more inputs that is useful to you. Choose a formula that you are familiar with, perhaps something from another math or science class. The program should ask the user for each of the relevant input variables, then display the result of the formula. If any of the given inputs is inappropriate for the formula, then you should instead display an error message and stop the program.
For example, your program output might be:
./prog3 This program computes the airspeed of the common sparrow. Enter the wingspan in inches: 6 Enter the altitude in feet: 150 Enter the temperature in Celsius: 32 The flight speed is 348 furlongs per fortnight.On the other hand:
./prog3 This program computes the airspeed of the common sparrow. Enter the wingspan in inches: -5 Sorry, the wingspan must be greater than zero.A few hints to get the program right:
This lab report should explain the following things:
nano report.txt
All submissions will be done electronically, so as to save a few trees, and make life a little easier for the graders.
Copy all of your source files (prog1.c, prog2.c, prog3.c) and the lab report (report.txt) into your handin directory. Your handin directory is /afs/nd.edu/courses/cse/cse20211.01/dropbox/NETID/lab1. (Obviously, replace NETID with your netid.)
For example, to copy part one to your handin directory:
cp prog1.c /afs/nd.edu/courses/cse/cse20211.01/dropbox/NETID/lab1(Hint: type in one command, then use the up-arrow to modify the command, and then repeat it.) You can verify that your files are handed in by running the following command:
ls -l /afs/nd.edu/courses/cse/cse20211.01/dropbox/NETID/lab1If you find a mistake after turning in but before the deadline, you can update your submission by simply copying the necessary files again. You are free to turn in assignments multiple times before the deadline expires. It would be a good habit to turn in an incomplete but working assignment on a daily basis. Thus, there is no excuse for failing to turn in an assignment: everyone should turn in something long before the deadline.