Simple Computation in C and handing in Assignments Solution

$30.00

Description

Winter 2018

The goal of this laboratory is to create a simple C program that receives typed input from the user of the program, and calculates a simple output. In addition, we’d like you to get used to the methods of handing in assignments in this course, which have two parts –

  1. Marking of program style and questions in the lab by your TA, and

  1. Electronic submission of your program for grading by a computer program.

All labs in this course are due at the end of your scheduled lab period. This means that you must have both been graded by your TA, and you must have gone through the submission process described in this lab. The same process will be used in every one of the coming eight labs! Lab 1 is due on January 19 (Friday) or January 22 (Monday), depending on your lab section.

Preparation

Read through this entire document carefully, and do the work to create the program that is described in the Program to Write section below, and try to make it work. You can do this on your own home computer if you have installed CodeLite as instructed in Lab 0. You can also do this work in the ECF labs prior to your lab period. If you are having difficulty making your program work prior to the lab period, you can do one of several things:

  1. Read the class bulletin board on Piazza, to see if others had similar problems. If you don’t see anything helpful there, ask a question. Don’t ask for, or ever give, though, a solution in the form of the full computer program!

  1. You can check out www.stackoverflow.com, and even ask a question there too. They are great answering questions to great detail, but only if they see that you are not just asking for a solution to your assignment (they will call you out on that)!

  1. The TA in your lab can give you help.

  1. A TA will be available in your weekly tutorial period, simply to give help.

Program to Write

Create a C program that executes in order the following tasks:

prompts a user to input three numbers, which are read in as type double. Use this message (with a space after the colon character):

Enter three numbers:

calculates the mean and standard deviation of the three numbers;

prints the mean and standard deviation with a precision of two decimal places, with these messages and results on the same line:

The mean is (number here) and the standard deviation is (number here)

You will need the math library in C, called math.h to compute the results. This library will be presented to you in class, but you should read up on it ahead of time, and use some of its functions in this assignment, particularly for the computation of the square and the square root.

The definition for the standard deviation sx of x1; x2; : : : ; xn is given below. The mean is x.

sx =

q

P n 1

(xi x)2

Below we give a description of the example inputs and outputs as they must be presented by your program. The text that is to be entered by the program user is displayed using a bold font. The text <enter> stands for the user pressing the enter key on the keyboard. On some keyboards, the enter key may be labeled return. When you execute your programs, the user’s text will not be displayed in bold and <enter> will not be shown.

Here is an example output from an execution of the program:

Enter three numbers: 58.28<space>11.39<space>2.52<enter> The mean is 24.06 and the standard deviation is 29.96

Notes:

  1. You can assume that the user enters valid numbers.

  1. For output of the double numbers, be sure to use the appropriate output format code.

  1. Important: The marking program will be looking for the exact letters as described in the output above, including the capitalization. When you test your program using the exercise program given below, you will see that it is expecting the output to be exactly this, so you’ll have to use it to see if you have this output correct.

  1. Notice that there is a single space after the colon (:) in each output line.

Grading by TA and Submitting for Program for Auto-Marking

You must put your C program in a file named Lab1.c (be sure to make the capitalization

in the file name correct). You can set the name of the file when you first create the project (as described in the CodeLite document) or change the name of the main.c file in CodeLite by right clicking on the name, and selecting Rename…

There are a total of 10 marks available in this lab, marked in two different ways:

  1. By your TA, for 4 marks out of 10. Once you are ready, show your program to your TA so that we can mark your program for style, and to ask you a few questions to test your understanding of what is happening. Programs with good style have been described in class, but briefly, they are:

Clear comments that describe what is happening in the program.

Good choices for variable names that indicate their purpose (e.g. inputNum-ber1 or divisionOutput in the case of this lab). Please adopt the following nam-ing convention illustrated above – if have you a variable that is described by multiple words, user lower case for the first letter of the first word, and Upper case for all subsequent words – e.g. longestLengthString or closeWindowDe-lay.

2

Properly indented code that has appropriate spacing between lines for readabil-ity.

The TA will also ask you some questions to be sure that you understand the under-lying concepts being exercised in this lab.

  1. By an auto-marking program for 6 marks out of 10. You must sumbit your Lab1.c program file through the ECF computers for marking. We will use a software pro-gram to compile and run your program, and test it with different inputs. Long be-fore you submit your program for marking, you should run the exercise program that compiles and runs your program and gives it sample inputs, and checks that the outputs are correct. To do this you should do the following:

Open a terminal window on ECF, using xterm, as described in the Getting Started with Linux and ECF document from Lab 0.

Change into the directory (folder) containing your Lab1.c file, using the Linux cd command.

Run the following program by typing: /share/copy/aps105s/lab1/exercise

This program will look for the file Lab1.c in your directory, compile it, and run it on a some of the test cases that will be used to mark your program automatically later. If there is anything wrong, the exercise program will report this to you, so read its output carefully.

A key part of what you are to learn in this lab is the use of this program – most software programs give this kind of report. Read through the output of the ex-ercise program and see if it is happy with everything, or if it is reporting an error. If there is an error, it will say so, and then it is up to you to fix what is wrong and try again. You’ll need to do this for every subsequent lab.

  1. Once you have determined that your program is as correct as you can make it, then you must submit your program for auto-marking. This must be done by the end of your lab period as that is the due time. To do so, go into the directory containing your Lab1.c file (and make sure this is the right place!) and type the following command:

/share/copy/aps105s/lab1/submit

This command will re-run the exercise program to check that everything looks OK. If it finds a problem, it will ask you if you are sure that you want to submit. Note that you may submit your work as many times as you want prior to the deadline; only the most recent submission is marked.

Important Note: You must submit your lab by the end of your assigned lab period. Late submissions will not be accepted, and you will receive a grade of zero.

You can also check to see if what you think you have submitted is actually there, for peace

of mind, using the following command:

/share/copy/aps105s/lab1/viewsubmitted

3

This command will download into the directory you run it in, a copy of all of the files that have been submitted. If you already have files of that same name in your directory, these files will be renamed with a number added to the end of the filename.

After the Final Deadline – Obtaining Automark

After all lab sections have finished, a short time later, you will be able to run the au-tomarker to determine the automarked fraction of your grade on the code you have sub-mitted. To do so run the following command:

/share/copy/aps105s/lab1/marker

This command will compile and run your code, and test it with all of the test cases used to determine the automark grade. You will be able to see those test cases’ output and what went right or wrong.

4