ELEC129 C语法解说

【ELEC129 C语法解说】Department of Electrical Engineering and Electronics
Introduction to
Programming in C
(ELEC129)
Assignment 4
Introduction to Programming in C (ELEC129) Assignment 4
Dept. Electrical Eng. & Electronics Page 2 / 4 University of Liverpool
Objectives
To design, implement and document modular programs that use functions and I/O files.
Assessment
This assignment is an assessed component and the mark for this work will contribute towards
the overall module mark. The weight of Assignment 4 is 12%. The marking criteria can be
found in the Exam Resources section of ELEC129 in VITAL.
This assignment is composed of a number of exercises. The relative weight of each exercise on
the overall assignment mark is indicated between brackets.
Instructions
Students are required to do all exercises and submit a single Word file in the Assessment
section of ELEC129 in VITAL (https://vital.liv.ac.uk) by Monday 04/03/2019 at 17:00 (5pm) UK
local time (week 6 of semester 2). Delay penalties apply. Please double check your report and
make sure your work is in its final form before submission as the online application will not
allow resubmissions. Email submissions and/or resubmissions will not be accepted.
Submissions must be a single Word file containing the work done by the student (student
name and student ID should be clearly stated in the first page). The file must contain two
parts for each exercise proposed in this assignment as detailed below.
Part I: The first part must contain the source code. Please use font Courier New with a size of 8
points, use indentation to make the code readable, and observe the following requirements:
The source code must be the result of your own original and individual work.
The source code must be entirely written in the C programming language. Source code
written in any other programming languages (e.g., C++) will receive a mark of zero.
The use of global variables is (in general) not needed in ELEC129 assignments and its
use is not allowed unless otherwise stated. All variables should be local to a function
(i.e., declared within the body of a function). The use of global variables will be
penalised. If you are in doubt, ask a lab demonstrator to check your source code.
All exercises can be solved based on concepts explained in previous lectures. Students
are allowed to use concepts from other (future) chapters but this is not expected. Feel
free to discuss your approach to solving the exercises with a lab demonstrator.
Part II: The second part must contain a detailed explanation of the software development
process followed by the student (i.e., the first five steps of the software development method):

  1. Problem specification: Formulation of the problem and its objectives.
  2. Analysis: Identification of: i) inputs, ii) outputs, and iii) other relevant aspects,
    requirements or constraints (e.g., relevant formulas, etc.).
  3. Design: Formulation of the algorithm (list of steps) needed to solve the problem. At
    this stage, the problem should be divided into a number of sub-problems that can be
    solved using functions.
    Introduction to Programming in C (ELEC129) Assignment 4
    Dept. Electrical Eng. & Electronics Page 3 / 4 University of Liverpool
  4. Implementation: List of functions used in the program (function names), indicating for
    each function which step(s) of the algorithm is/are implemented by the function.
  5. Testing and verification: Explanation of how the program was tested and verified.
    Snapshots of the program's output window can be obtained by using [Alt] + [PrtScr(or
    PrintScreen)] and pasting into the report.
    Please indicate clearly if in your opinion the program works correctly. If you do not think the
    program works correctly or does not compile, indicate what the problems are. You will then be
    able to get points for that programming task. If in the testing section of your design document
    you have indicated that the program works correctly but it turns out that your code does not
    even compile (because of syntax errors, for example) you will not receive adequate points.
    Academic integrity
    Students should familiarise themselves with Section 6 of the University’s Code of Practice on
    Assessment, which provides important information regarding the submission of assessed
    coursework (link: http://www.liv.ac.uk/tqsd/cod...).
    Students should also familiarise themselves with Section 9 (Academic Integrity) and Appendix L
    (Academic Integrity Policy) of the University’s Code of Practice on Assessment which provide
    the definitions of academic malpractice and the policies and procedures that apply to the
    investigation of alleged incidents (including collusion, plagiarism, fabrication of data, etc.).
    Students found to have committed academic malpractice are liable to receive a mark of zero
    for the assessment or the module concerned. Unfair and dishonest academic practice will
    attract more severe penalties, including possible suspension or termination of studies.
    By electronically submitting this coursework you confirm that:
    You have read and understood the University’s Academic Integrity Policy.
    You have acted honestly, ethically and professionally in conduct leading to assessment
    for the programme of study.
    You have not copied material from another source nor committed plagiarism nor
    fabricated data when completing the attached piece of work.
    You have not previously presented the work or part thereof for assessment for
    another University of Liverpool module.
    You have not copied material from another source, nor colluded with any other
    student in the preparation and production of this work.
    You have not incorporated into this assignment material that has been submitted by
    you or any other person in support of a successful application for a degree of this or
    any other University or degree awarding body.
    Students are encouraged to contact the module instructor if any clarifications are needed.
    Introduction to Programming in C (ELEC129) Assignment 4
    Dept. Electrical Eng. & Electronics Page 4 / 4 University of Liverpool
    Exercise 1 (100% of assignment mark)
    You are required to write a program that implements a simple game. The game involves a user
    guessing a number. The program is based on a text file numbers.txt that stores 55 integer
    numbers comprised within the interval from 12 to 112.
    The game starts by asking the name of the player and a position for a secret number within the
    file numbers.txt. This position is a number between 1 and 55 that corresponds to a number
    within the file, so that the player cannot know this initial secret number. Then the objective is
    for the player to guess this secret number in a series of guesses. The program should take a
    number input from the player via the keyboard. If this number as guessed by the player is the
    secret number then the player wins. Otherwise the computer should indicate whether the
    guess is lower or higher than the secret number (but do not reveal what this number is!). The
    computer should keep asking the player, providing indications on whether the guess is lower
    or higher than the secret number, until the user correctly guesses the secret number.
    Finally, depending on the number of attempts needed by the user to guess the secret number,
    the program should display one of the following messages:
    "You are too lucky!!!" – If the user guesses the secret number in the 1st attempt.
    "Excellent!!" – If the user guesses the secret number in the 2nd or 3rd attempt.
    "Good!" – If the user guesses the secret number in the 4th or 5th attempt.
    "Ok" – If the user needs 6 or more attempts to guess the secret number.
    Also, the play history of past games (player name, secret number and number of attempts) for
    all players should be saved in a single file. Previously saved games can be read from the file
    and shown in the screen with the aid of a menu where the user can chose between showing
    the previous play history or playing a new game.

    推荐阅读