Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ACS130 Introduction to Systems Engineering and Software

Individual C Programming Assignment 1

Tara Baldacchino (t.baldacchino@sheffield.ac.uk, Room D13, AJB)

Assignment weighting: 10% of module mark

Assignment released: Wednesday 19 October (Semester 1, Week 4)

Assignment due: 11.59pm Monday 7 November (Semester 1, Week 7).

How to submit

The assignment must be submitted to Blackboard by 11.59pm Monday 7 November, at the link ACS130 > Assessment > C Programming ACS130-001. You must upload you *.c file. There is a separate drop box for ACSE and Aero students so please submit to the correct drop box. Please make sure you submit your .c file and nothing else. If, when I download your program from Blackboard I cannot run the file because it is not a .c file (or for any other reason), you will NOT be marked.

Marking

I will mark your program. The attached mark sheet provides a guide to the areas on which feedback will be provided. The rubric on Blackboard also provides a guide to the marks for this assignment. Mac users, you need to make sure that your program runs on the Windows Codeblocks (I do not own a Mac).

How you should work

This is an individual assignment, and it must be wholly your own work.  You should not discuss a solution to this assignment with anyone else, and you should not work with anyone else to produce a solution. I will check for collusion and plagiarism.

You must complete this assignment in your own time, NOT in ACS130 C practice sessions. Learning outcomes

In doing this assignment, you will demonstrate your ability to program in C to manipulate files, output to the screen,  implement the selection and  repetition constructs, and  manipulate variables, as well as use functions.

Assignment briefing

Write a C program to:

•    Read characters (no spaces but a combination of numbers, letters and symbols) all on the same line from the keyboard and write the characters (one at a time) to the  file File1.txt (all on the same line), then close the file.

•    Read the characters from the file File1.txt” that you have just created.  (Hint: read  the characters one at a time), at the same time printing only the number characters to the screen

•    Print the count of how many numbers there are and also print the sum of these numbers.

•    In a function float mean (float sum, float N) calculate the mean, where sum is the sum of the numbers entered, and N is the total number of numbers.

o calculate the mean of the numbers

o  return this mean to main

o  this function contains no printf statements

•    Print to the screen the mean (to 2 d.p.) of the numbers from main.

•    You need to check if the file exists.

•    Advanced objective 1: Cater for the situation when no numbers are entered at the start, and so there is no average. You need to use specifications given above.

•    Advanced objective 2: Program your code to keep looping until the user decides to quit the code. Have a statement, eg, ‘Would you like to run code again (y/n)?’ and if user enters y then loop to start, and if user enters n then the program exits. You will need to play around with fflush(stdin) to clear the buffer.

For example, your program should look like this when input sf98375hf^%839*&% is used:


 

Figure 1: Example output of code.

Please note:

•    The only library you may include is stdio.h, therefore you will not be allowed to use pre-defined functions from any other library. You will get 0 if you use more functions defined in other libraries (eg atoi() since this is defined in the stdlib.h library).

•     You may not use arrays or strings (which will be covered at the end of semester 1). You will get 0 if you use arrays or strings.

•     You may not use pointers (covered in semester 2). You will get 0 if you use pointers. NOTE: FILE *fIN is allowed.

•     You may not use goto/break/continue etc. You will get 0 marks if you use any of these.

•    You may not use global variables. These are variables declared outside main. You  will get 0 if you use global variables. #define is allowed but not needed for this program.

•    When your program is marked, I will type in a range of characters to test your program.  You should test your program thoroughly before you submit it.

•    Your program must have meaningful comments, including a header comment, and be well-laid out and readable.

•    Helpful tip 1:  You need to think about how you’re going to check for the end of line character when reading in the characters from the keyboard.

a.   If you are struggling to do this part then do the following: Create a file with a row of characters (including numbers) and do the rest of the assignment- so read the file, print numbers to the screen and find their mean. You can still   get a lot of marks.

•    Helpful tip 2:  You need to think about how you’re going to convert the numerical    characters into numbers in order to be able to find the sum. Use the ASCI table (see www.ascii-code.com) and refer to details given verbally in the lecture. You are not    allowed to use the function int atoi() because this is in the stdlib.h library.

Marking Scheme for Software

Marking Criterion

Mark

Does the code use :

     any other library other than stdio.h or

     arrays/strings or

     pointers or

     global variables

•     continue/break/goto - 0 marks!

 

Looking at the code

Program layout and readability including: is the code indented, does it have     comments, header comments and meaning variable names? Any one of these missing means you lose the mark!

/1

Running the code, using a test input

Does the code do what is asked in this assignment briefing when tested? Read line, print to file, read from file and print numbers to screen, calculate and print sum, calculate and print number of occurrences of number characters and prints mean. Are the calculations correct? (This step assumes numbers have been entered at the start)

Does it check for file and abort the program (with a suitable message) if the file is not found?

Does it use the function float mean (float sum, float N) to find the mean, which gets printed from main()?

Does the program cater for no numbers being entered at the start?

Does the program keep looping until the user requests to stop?

/3

 

 

 

 

/1

 

/2

 

/1

/1

Output

/ 1

Total marks possible

/ 10

Penalties for late submission

A  late  submission  will  be  any  assignment  not  submitted  to  Blackboard  by  the  deadline.  Late submissions will incur the usual penalties of a 5% reduction in the mark for every day (or part thereof) that the assignment is late and a mark of zero for submission more than five days late.

Unfair means

You  are  permitted to view the  resources  on ACS130  Blackboard,  C text  books  and  C  programs published on the internet, for insight into C programming, but you are not permitted to copy any code that you have not written to submit as your own work.  You are not permitted to seek or accept help on this assignment, or code for this assignment, from any internet site or forum.  You are not permitted to work with any other person on this assignment, and you are not permitted to submit any other person’s algorithm or code as your own work. Any suspicion of the use of unfair means will be investigated and may lead to penalties.  References must be provided to any other work that is used to inform the ideas for this assignment. Seehttp://www.shef.ac.uk/ssid/exams/plagiarismfor more information.

Extenuating Circumstances

If you have medical or serious personal circumstances which cause you to be unable to submit this assignment on time or which may have affected your performance, please inform me, and complete and submit an extenuating circumstances form along with documentary evidence of the circumstances. Seehttp://www.sheffield.ac.uk/ssid/forms/circs.

Help

This assignment briefing and the lectures and resources on the ACS130 Blackboard course and the training in C practice sessions provide all the information that is required to complete this assignment. It is not expected that you should need to ask further questions.    If you need clarifications on the assignment, then please post a question on the ACS130 Blackboard discussion board. The discussion board allows everyone the chance to view an answer to a question, as well as the opportunity to contribute to the discussion. I will not reply to assignment related questions via email.