CS代写 Programming Concepts

Programming Concepts
Assignment 1 – Programming with C
SAIBT in collaboration with UniSA STEM University of South Australia

Copyright By PowCoder代写 加微信 powcoder

Introduction
Assignment Overview
Practical Requirements
Submission Details
Extensions and Late Submissions Academic Misconduct
Marking Criteria
Sample Output

INTRODUCTION
This document describes the second assignment for Programming Concepts.
The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course
by applying your knowledge and skills to the implementation of a game/puzzle called Petals Around the Rose.
You are required to write a C program that allows a user to play a game called Petals Around the Rose. The program allows the user to repeatedly guess the answer to the puzzle until the user chooses to stop guessing/playing. Once the user chooses to stop guessing, the program will report the game play statistics to the screen. You may like to play a web version of the game: http://www.borrett.id.au/computing/petals-j.htm.
This assignment is an individual task that will require an individual submission. You will be required to submit your work via Moodle before Friday Week 8, 1:30pm
This document is a kind of specification of the required end product that will be generated by implementing the assignment. Like many specifications, it is written in English and hence will contain some imperfectly specified parts. Please make sure you seek clarification if you are not clear on any aspect of this assignment.

ASSIGNMENT OVERVIEW
You are required to write a C program that allows a player to play a game of Petals Around the Rose. The program allows the user to repeatedly guess the answer to the puzzle until the user chooses to stop guessing/playing. Once the user chooses to stop guessing, the program will report the game statistics to the screen. You may also like to read and Petals Around the Rose: http://www.borrett.id.au/computing/petals-bg.htm.
We will be adhering to the following ‘Petals Around the Rose’ rules and game play for the assignment. Petals Around the Play and Rules:
The game is called Petals Around the Rose and The name is important. The computer will roll five dice and ask the user to guess the score for the roll. The score will always be an even number (including zero). The user’s mission is to work out how the computer calculates the score in order to become a Potentate of the Rose.
• To begin, the following instructions are displayed to the screen and the user is asked whether they would like to play Petals Around the Rose, i.e.:
Petals Around the Rose
———————-
The game is called ‘Petals Around the Rose’. The name of the
game is important. The computer will roll five dice and ask you to
guess the score for the roll. The score will always be zero or an
even number. Your mission, should you choose to accept it, is to
work out how the computer calculates the score. If you succeed in
working out the secret and guess correctly four times in a row, you
become a Potentate of the Rose.
Would you like to play Petals Around the Rose [y|n]?
If the user enters ‘n’, the following message is displayed to the screen only:
No problem… I hope to see you again soon.
If the user enters ‘y’, game play continues as normal.

• Game play is as follows:
• The dice face values are then displayed to the screen and the user is asked to guess the score for the roll, for
Please enter your guess for the roll:
The numbers in the above output will change depending on the dice values rolled.
• If the user guesses correctly, the following message is displayed: Well done! You got it!
• If the user does not guess correctly one of two possible messages is displayed to the screen. If the user enters an incorrect non-even number, the following message is displayed to the screen, for example:
No sorry, it’s 8 not 7. The score is always even.
If the user enters an incorrect even number, the following message is displayed to the screen, for example:
No sorry, it’s 8 not 6.
The numbers in the above output will change depending on what the user has entered and the score value for the roll.
• The user is then asked whether they would like to play again with the following prompt. Game play continues while the user enters ‘y’ at the prompt:
Would you like to roll again [y|n]?
• If the user has four (4) incorrect guesses in a row (i.e. consecutively) the following message is displayed to the screen:
Hint: The name is important… Petals Around the Rose.
• Note: the above message must be displayed to the screen every time four consecutive incorrect guesses are achieved.
• If the user has four (4) correct guesses in a row (i.e. consecutively), the following message is displayed to the screen:
Congratulations! You have worked out the secret!
Shhhh. Don’t tell anyone!
• Note: the above message must be displayed to the screen every time four consecutive correct guesses are achieved.
• Game play continues until the user chooses to quit, i.e. enters ‘n’ at the following prompt: Would you like to roll again [y|n]?
Die 1 Die 2 Die 3 Die 4 Die 5 [3] [4] [3] [5] [4] * ** * ** **
* ** * ** **

• The solution or formula for Petals Around the Rose can be found here:
https://en.wikipedia.org/wiki/Petals_Around_the_ key to working out the answer is given by the name of the puzzle, where the “rose” is the centre dot that appears only on the 3 and 5 faces of a die, while the “petals” are the dots which surround the centre dot. Therefore, the result can be calculated by counting 2 for each 3 face and 4 for each 5 face. In the example provided above, there is one 5 face and one 3 face, so the result is four plus two, resulting in a total of six.
• Once the user chooses to quit (after having played at least one game), game summary statistics are displayed to the screen, for example:
Game Summary
************
You played 2 games:
|–> Number of correct guesses: 1
|–> Number of incorrect guesses: 1
Thank you for playing!
The numbers in the above output will change depending on the results of the user’s games and the dice values rolled. The above should not be displayed if the user has not played any games.
You do not have to write the code that displays the die face values to the screen, a function that does that for you has been provided. The function is called display_dice. You are required to use this as part of this assignment, however, please do not modify the display_dice function.

PRACTICAL REQUIREMENTS
It is recommended that you develop this assignment in the suggested stages.
It is expected that your solution will include the use of:
• Your solution in a file called yourSAIBTID_rose.c. For example: 54321_rose.c
• Appropriate and well constructed while/for loops.
o Marks will be lost if you use break, pass, goto, continue, return or similar statements in order to exit from within loops). Must exit loops via Boolean expression.
• Appropriate and well constructed if, else if, else statements.
• The supplied display_dice function. This is provided for you – please DO NOT modify this function.
• The use of the rand() function in order to simulate the roll of a six sided die.
• Three functions (refer to stage 7 for description):
o void display_details(void);
o int roll_die(void);
o int calculate_petals_total(int, int, int, int, int);
• Output that strictly adheres to the assignment specifications. If you are not sure about these details, you should check with the ‘Sample Output’ provided at the end of this document or post a message to the discussion forum.
• No global variables.
• Use of #define for symbolic constants (if necessary). i.e. no magic numbers.
• Good programming practice:
o Consistent commenting and indentation. You are to provide comments to describe: your details, program description, all variable definitions, all function prototypes and definitions and every significant section of code.
o Meaningful variable names (no single letter identifier names). o Consistent indentation.
significant mark deduction.
Do not use break, pass, goto, or continue statements in your solution – doing so will result in a
PLEASE NOTE: You are reminded that you should ensure that all input and output conform to the specifications listed here; if you are not sure about these details you should check with the sample output provided at the end of this document or post a message to the discussion forum in order to seek clarification.
The layout and presentation of your output should EXACTLY match the sample output provided (refer to the end of this document).

It is recommended that you develop this assignment in the suggested stages. Many problems in later stages are due to errors in early stages. Make sure you have finished and thoroughly tested each stage before continuing.
The following stages of development are recommended:
Stage 0 (preparation)
1. Setup your project
• Setup a new project in Microsoft Visual Studio or a new folder in Microsoft Visual Studio Code (refer to instructions on the course website if you are unsure of how to do this).
• Download the starter file from Moodle. The file is called yourSAIBTID_rose.c. This file contains the display_dice function for this assignment
• Change yourId to your actual email id.
• Add the file (called yourSAIBTID_rose.c) to your project
o Copy the file into the project folder.
o Select the Project menu, then Add existing item…).
2. Test your setup
• Enter the following within the main function of your yourSAIBTID_rose.c file:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
/* Function display_dice to display the face value of dice to the screen.
You are provided with this function (see below) – please do not modify it. */
void display_dice(int, int, int, int, int);
int main() {
/* This line will eventually be removed – used for development purposes only. */
printf(“\n\nProgramming assignment – this will be deleted in stage 1!\n\n”);
display_dice(2,3,4,5,6);
return 0; }
• Run the yourSAIBTID_rose.c file. If this is working correctly, you should now see the following output when you run your program:
Programming assignment – this will be deleted in stage 1!
Die 1 Die 2 Die 3 Die 4 Die 5 [2] [3] [4] [5] [6] * * ** ** ** * * ** * * ** ** **
3. Save a back up
• Save a copy of this file before moving on to the next Stage – do this at the end of every stage.

Add code to simulate the rolling of five dice. Use the rand() function (i.e. 1 + rand() % 6) to simulate the roll of a die.
Modify your code to now display the randomly generated dice roll to the screen, for example, if your variables (that store the randomly generated die rolls) are called die1, die2, die3, die4, and die5, you would then modify the code from stage zero so that the randomly generated values are passed to the function instead, like so:
/* Place code to randomly generate the roll of five dice here… */
display_dice(die1, die2, die3, die4, die5);
Sample output (this will look different given we are generating random values here):
Die 1 Die 2 Die 3 Die 4 Die 5
[1] [2] [4] [6] [2]
* ** ** * * **
Add code to prompt for and read the user’s guess (i.e. the score guess for the roll), calculate the petals total and display an appropriate message to the screen depending on the user’s input. For example:
• If the user guesses correctly, the following message is displayed: Well done! You got it!
• If the user enters an incorrect non-even number, the following message is displayed to the screen, for example:
No sorry, it’s 2 not 7. The score is always even.
• If the user enters an incorrect even number, the following message is displayed to the screen, for example: No sorry, it’s 2 not 4.
The numbers in the above output examples will change depending on what the user has entered and the score value for the roll.
Sample output 1:
Die 1 Die 2 Die 3 Die 4 Die 5 [3] [3] [4] [5] [5] * * ** ** **
** ** * * ** ** **
Please enter your guess for the roll: 12
Well done! You got it!

Display the user’s guess, the actual score and appropriate message to the screen as seen below:
Sample output 2:
Die 1 Die 2 Die 3 Die 4 Die 5 [5] [2] [4] [5] [4] ** * ** ** **
** * ** ** **
Please enter your guess for the roll: 3
No sorry, it’s 8 not 3. The score is always even.
Sample output 3:
Die 1 Die 2 Die 3 Die 4 Die 5
[2] [3] [2] [5] [1]
* * * ** ***
Please enter your guess for the roll: 8 No sorry, it’s 6 not 8.
Now… it’s time to allow the player to play more than one game. Let’s add a loop that loops until the user either enters ‘n’ (to quit the game). Think about where this code should go – what needs to be repeated, etc.
Sample output:
Would you like to play Petals Around the Rose [y|n]? y
Die 1 Die 2 Die 3 Die 4 Die 5
[3] [2] [5] [1] [1]
* *** * * **
Please enter your guess for the roll: 6
Well done! You got it!
Would you like to roll again [y|n]? y
Die 1 Die 2 Die 3 Die 4 Die 5 [5] [1] [5] [3] [4] ** ** * **
** ** * **
Please enter your guess for the roll: 5
No sorry, it’s 10 not 5. The score is always even.
Would you like to roll again [y|n]? y

Die 1 Die 2 Die 3 Die 4 Die 5 [2] [3] [2] [2] [5] * * * * **
** * * * * **
Please enter your guess for the roll: 2
No sorry, it’s 6 not 2.
Would you like to roll again [y|n]? n
Add code to keep track of how many games were played, the number of correct guesses and the number of incorrect guesses. Display this to the screen as seen in the sample output.
Add code to keep track of how many correct and incorrect guesses are recorded in a row (consecutively) and display the appropriate messages to the screen (only if four in a row are achieved, i.e. must be consecutive) as seen in the sample output. Note, that the appropriate messages must be displayed to the screen every time four consecutive correct or incorrect guesses are recorded.
Add code to validate the following user input only:
• Would you like to play Petals Around the Rose [y|n]?
Sample output:
Would you like to play Petals Around the Rose [y|n]? w
Please enter either ‘y’ or ‘n’.
Would you like to play Petals Around the Rose [y|n]? y
• Would you like to roll again [y|n]?
Sample output:
Would you like to roll again [y|n]? z
Please enter either ‘y’ or ‘n’.
Would you like to roll again [y|n]? y

Modify your code to include and make use of the following three functions:
▪ void display_details(void);
▪ int roll_die(void);
▪ int calculate_petals_total(int, int, int, int, int);
1. Write a function called display_details that will display your details to the screen. The function takes no parameters and does not return any values. Defining the function does not execute the function – you will need to call the function from the main function in the program. Your function should produce the following output (with your details).
File : wayby001_rose.c
Author : Batman
Stud ID : 0123456X
Email ID : wayby001
This is my own work as defined by the University’s Academic Misconduct Policy.
2. Write a function called roll_die that simulates the rolling of one die. The function will generate a random number in the range 1 – 6 (the face value on the die are 1 – 6 inclusive). The function takes no parameters and returns the random number generated.
Defining the function does not execute the function – you will need to call the function from the main function in the program (more than once).
For example:
die1 = roll_die();
die2 = roll_die();
3. Write a function called calculate_petals_total that takes the five die values as parameters, calculates and returns the total number of petals.
Defining the function does not execute the function – you will need to call the function from the main function in the program.
Stage 8 – THIS IS IMPORTANT!
Finally, check the sample output (see section titled ‘Sample Output’) and if necessary, modify your code so that:
• The output produced by your program EXACTLY matches the sample output provided.
• Your program EXACTLY behaves as described in these specs and the sample output provided.
OPTIONAL CHALLENGE:
• Modify your program to use arrays to store your die values and modify display_dice to take in an array rather than 5 integers
• Save this as a separate file e.g. SAIBTID_roseCHAL.c

SUBMISSION DETAILS
You are required to do the following in order to submit your work and have it marked:
▪ You are required to submit an electronic copy of your program via Moodle before class Week 8
The solution file should be called SAIBTID_rose.c. For example: 54321_rose.c. Ensure that your file is named correctly (as per instructions outlined in this document).
Ensure that the following file is included in your submission:
• SAIBTID_rose.c
All files that you submit must include the following comments.
File : 54321_rose.c
Author : First-name Family-name
SAIBT ID : 54321
This is my own work as defined by
SAIBT’s Academic Misconduct Policy.
Assignments that do not contain these details may not be marked.
You must submit your program before the online submission due date. You will also be required to demonstrate that you have correctly submitted your work to Moodle. Work that has not been correctly submitted to Moodle will not be marked.
It is expected that students will make copies of all assignments and be able to provide these if required.

EXTENSIONS AND LATE SUBMISSIONS
There will be no extensions/late submissions for this course without one of the following exceptions:
1. A medical certificate is provided that has the timing and duration of the illness and an opinion on how much the student’s ability to perform has been compromised by the illness. Please note if this information is not provided the medical certificate WILL NOT BE ACCEPTED. Late assessment items will not be accepted unless a medical certificate is presented to the Course Coordinator. The certificate must be produced as soon as possible and must cover the dates during which the assessment was to be attempted. In the case where you have a valid medical certificate, the due date will be extended by the number of days stated on the certificate up to five working days.
2. An Academic Coordinator or Student Learning Advisor contacts the Module Coordinator on your behalf requesting an extension. Normally you would use this if you have events outside your control adversely affecting your course work.
3. Unexpected work commitments. In this case, you will need to attach a letter from your work supervisor with your application stating the impact on your ability to complete your assessment.
4. Military obligations with proof.
Applications for extensions must be lodged with the Course Coordinator before the due date of the assignment.
Note: Equipment failure, loss of data, ‘Heavy work commitments’ or late starting of the course are not sufficient grounds for an extension.
ACADEMIC MISCONDUCT
ACADEMIC MISCONDUCT
Students are reminded that they should be aware of the academic misconduct guidelines available from the SAIBT website.
Deliberate academic misconduct such as plagiarism is subject to penalties. Information about Academic integrity can be found the SAIBT Academic Integrity Policy https:

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com