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

CPT109 C Programming and Software Engineering 1  ASSESSMENT 2

Assessment Overview

This assessment aims at testing some basic concepts of C programming, in particular, the use of functions to produce basic modular program structures. It also initiates the routine of code development using the software development process (SDP) presented in Lecture 1, namely the five main steps of the software development process:

1.   Problem statement: formulate the problem.

2.   Analysis: determine the inputs, outputs, variables, etc.

3.   Design: define the list of steps (the algorithm) needed to solve the problem.

4.   Implementation: the C code has to be submitted as a separate file. Just indicate here the name of the file.

5.   Testing: explain how you have tested and verified your C program.

Exercise

Write a modular C program that will allow one player to play the game of tic-tac-toe (also       known as noughts and crosses) with your computer. See the game example output in Figure 1.

 

Program Requirements

O     Your program should provide users with the ability to create an account. An account should be a structure type variable containing: a username, a password and accumulative numbers of wins and losses.

O     All of the accounts should be stored in a data file and accessed by the program.

O     Once a user is logged on to the game they should be able to choose:

(i)        To go first or second

(ii)        To play again, or not at the end of each game

O     On choosing not to play again, the user’s account information should be updated in the file, i.e. number of wins and losses.

The player can place a token (an O’ or an X’) on the board by choosing a number 1-9. After that, the computer can put a different token (an X’ or an O’) on the board automatically. The player wins the game if he/she can place three tokens in a line, horizontally, vertically or diagonally. On the contrary, the computer wins the game if it can place three tokens in a line, horizontally, vertically or diagonally. The game is a draw if all of the squares are filled, and neither the player nor the computer has been able to make a row of three tokens.

Advice

This may initially appear very difficult. It is suggested that you first write down the steps that the program needs to perform and in what order (sequence), if necessary produce a flow chart and then think about how to do each part e.g:

O     player can create an account or log in.

O     Display the game board

O     Player chooses to play first or second.

O     Player enters the number of the square he/she wishes to choose

O      The game board is updated

O      The win status of the game is tested and the game finishes if the player has won

O      Computer automatically chooses a place

O      The game board is updated

O     The win status of the game is tested and the game finishes if the computer has won

O     and so on

Consider that for everything you want to repeat. For example, for each iteration of the player and computer, you will need a loop.

Produce the program one step at a time. E.g. if you can produce the input and test for the player then the computer will be similar. Work out how to display your board (note it does not have to look exactly the same as in Figure 1). Each square choice can be a variable (i.e. 9 variables), that you can change the value of when it is chosen. Then the whole board can be printed with one printf statement that uses the values stored in the 9 variables.

The assignment tests your understanding of creating a basic modular program. Therefore, repetitive actions such as printing the board or testing for a win should be performed in separate functions and called when required. In this assignment use of global variables is acceptable.

Example Code

To help you get started, a program for a number guessing game is available on LMO see character_game.c. Note that this is only to offer you ideas for writing your own program. You should not try to adapt the code to produce your work, this would be more difficult than writing your own.

What should be submitted?

You should submit the following:

1)    A short report (up to a few pages of text) detailing for each question:

a) SDP steps 1 to 3 in the report (Report + Specification + Analysis + Algorithm Design) (40%)

b) SDP step 4 (Implementation(35%) + Robustness(5%)): your C source code including the comments. (40%)

c) SDP step 5 in the report (testing): you will explain your testing methodology including: what you wanted to test, how you have tested it and the outcome of your tests. (20%). Note: you do not need to include screenshots of results.

Please refer to the file CPT109 Marking Guidelines Assignment 2” on LMO for a detailed marking scheme.

2)    The report in pdf format and C source code of your implementation for each question should be zipped into a single file, i.e. the zip file will contain 2 files, one document and one source code. (It is a good practice to include comments in your code stating the aim of the program, what are the inputs, what are the outputs, which algorithm is used, who is the author and so on.)

The naming of Report (.pdf), Source Code (.c) and Compressed file (.zip or .rar)

O     StudentID_LastName_FirstName_A2 .pdf

O     StudentID_ A2.c

O     StudentID_LastName_FirstName_A2.zip or .rar

For example

O     10115085_Zhang_Hanqing_A2.pdf

O     10115085_A2.c Zipped together into:

O     10115085_Zhang_Hanqing_A2.zip

How to submit the work?

It should be submitted electronically through LMO so that the marker can run your programs during marking. Feedback and your grade will also be given through LMO.

Remember that you are responsible for ensuring that your C code will run in Visual Studio 2013.  If it  does  not  without  documentary  explanation,  you  may  get  a  0  mark  for  your implementation.