ENGGEN 131作业代做、代做Programming留学生作业、c/c++实验作业代写、代写c++编程语言作业
ENGGEN 131 – Summer School – 2019C Programming ProjectDeadline: 1:00pm, Monday 18th FebruaryCorrectness: 90 marksCode style: 10 marksWorth: 14% of your final gradeNo late submissions accepted ENGGEN 131, Summer School, 2019 - 2 - C ProjectIntroductionWelcome to the final project for the ENGGEN131 course!You have ten tasks to solve. For each task there is a problem description, and you must writeone function to solve that problem. You may, of course, define other functions which theserequired functions call upon (such functions are often called “helper” functions).Do your very best, but don’t worry if you cannot complete every function. You will get creditfor every task that you solve.This must be addressed somewhere so we may as well get it out of the way – this is anindividual project. You do not need to complete all of the tasks, but the tasks you do completeshould be an accurate reflection of your capability. You may discuss ideas in general with otherstudents, but writing code must be done by yourself. No exceptions. You must not give anyother student a copy of your code in any form – and you must not receive code from any otherstudent in any form. There are absolutely NO EXCEPTIONS to this rule. Immediate coursefailure, as well as University disciplinary action, will result.Please follow this advice while working on this project – the penalties for plagiarism (whichinclude your name being recorded on the misconduct register for the duration of your degree,and/or a period of suspension from Engineering) are simply not worth the risk.Acceptable Unacceptable Describing problems you are having to someone else,without revealing any code you have written Asking for advice on how to solve a problem, where theadvice received is general in nature and does not includeany code Discussing with a friend, away from a computer, ideas orgeneral approaches for the algorithms that you plan toimplement (but not working on the code together) Drawing diagrams that are illustrative of the approachyou are planning to take to solve a particular problem(but not writing source code with someone else) Working at a computerwith another student Writing code on paper or ata computer, and sharingthat code in any way withanyone else Giving or receiving anyamount of code fromanyone else in any form Code sharing = NOThe rules are simple - write the code yourself!OK, now, on with the project… ENGGEN 131, Summer School, 2019 - 3 - C ProjectUnderstanding the project filesThere are three files that you will be working with when you are developing your solutions to theproject tasks. The most important of these three files is summer_2019.c. This is the source filethat you will submit for marking. Please note the following: summer_2019.c is a source file that ONLY CONTAINS FUNCTION DEFINITIONS there is no main() function defined in summer_2019.c (and you must not add one) a separate program, test_summer_2019.c, containing a main() function has beenprovided to you to help you test the function definitions you write in summer_2019.cThe diagram below illustrates the relationship between the three files.The blue shaded regions in the above diagram indicate where you should write code when youare working on the project. There are three simple rules to keep in mind: You MUST NOT write any code in summer_2019.h (the header file) You MUST write implementations for the functions defined in summer_2019.c You SHOULD write additional test code in test_summer_2019.c to thoroughly test thecode you write in summer_2019.cENGGEN 131, Summer School, 2019 - 4 - C ProjectGetting startedTo begin, download the file called ProjectResources.zip from Canvas. There are three files inthis archive:summer_2019.c This is the source file that you will ultimately submit. In this source fileyou will find the ten functions that you should complete. Initially eachfunction contains an incorrect implementation which you should deleteand then correct. You may add other functions to this source file as youneed. You must not place a main() function in this source file. Thisis the only file that you will submit for marking.summer_2019.h This is the header file that contains the prototype declarations for the tenfunctions you have to write. You must not edit this header file in anyway. Both source files (summer_2019.c and test_summer_2019.c)include this header file, and the automated marking program will use theprovided definition of summer_2019.h. Modifying this header file inany way will be an error.test_ summer_2019.c This is the source file that contains the main() function. This file hasbeen provided to you to help you test the functions that you write. Inthis file, you should create some example inputs and then call thefunctions that you have defined inside the summer_2019.c source file.Some simple examples have been included in this file to show you howthis can be done.Place these three source files in an empty folder.You might like to start by looking at the summer_2019.c source file. In this source file you willfind ten function definitions, however they are all implemented incorrectly. The prototypedeclarations are as follows:int SecondsBetween(int minuteA, int secondA, int minuteB,int secondB);double Volume(int radius);int AppleBoxesNeeded(int numStudents, int lastDayOfWeek,int remainingApples, int applesPerBox);int PrimeBelow(int upper);int SumInRange(int *values, int numValues, int low, int high);void PositionOfMaximum(int *values, int rows, int cols, int *row,int *col);void Capitalise(char *phrase);int CountDistinct(int *values, int numValues);int ApprovedArea(Square squares[MAX_ARRAY_SIZE], int numSquares);void Squash(char *word, int maximum);You need to modify and correct the definitions of these ten functions. You may add additionalfunction definitions (i.e. “helper” functions) in this file. ENGGEN 131, Summer School, 2019 - 5 - C ProjectNext, you should run the program in test_summer_2019.c. To do this, you will need to compileboth source files. For example, from the Visual Studio Developer Command Prompt, you couldtype: cl /W4 summer_2019.c test_summer_2019.cOr, simply: cl /W4 *.cYou should see no warning messages generated when the code compiles.If you run the program, you will see that some test code has been provided for the first task ofthe project. You should add additional tests for this first task, and create your own tests for all ofthe other tasks in the project.It is your responsibility to test the functions that you write carefully. Your functions shouldproduce the expected output for any set of input values.ENGGEN 131, Summer School, 2019 - 6 - C ProjectWhat to submitYou must not modify summer_2019.h, although you can modify test_summer_2019.c. Youwill not be submitting either of these files.You must only submit ONE source file – summer_2019.c – for this project. This source filewill be marked by a separate automated marking program which will call your functions withmany different inputs and check that they produce the correct outputs.TestingPart of the challenge of this project is to test your functions carefully with a range of differentinputs. It is very important that your functions will never cause the marking program to crash orfreeze regardless of the input. If the marking program halts, you cannot earn any marks for thecorresponding function. There are three common scenarios that will cause the program to crashand which you must avoid: Dividing by zero Accessing memory that you shouldn’t (such as invalid array indices) Infinite loopsUsing functions from the standard libraryThe summer_2019.h header file already includes <stdio.h>, <stdlib.h> and <string.h>. Youmay not use any other functions from the standard library. If you want some functionality, youmust code it!MarkingYour submitted source file will be marked for style (use of commenting, consistent indentation,good use of additional “helper” functions rather than placing all of the logic in the requiredfunctions, etc.) Your code style will be assessed and marked by your lecturer.For correctness, your submitted file will be marked by a program that calls your functions withlots of different input values. This program will check that your function definitions return theexpected outputs for many possible inputs. Your mark will essentially be the total number ofthese tests that are successful, across all ten tasks.Some tasks are harder than others. If you are unable to complete a task, that is fine – justcomplete the tasks that you are able to. However, please do not delete any of the ten functionsfrom the summer_2019.c source file. You can simply leave the initial code in the functiondefinition if you choose not to implement it. All ten required functions must be present in thesummer_2019.c file you submit for marking.ENGGEN 131, Summer School, 2019 - 7 - C ProjectNever crashThere is one thing that you must pay important attention to. Your functions must never cause thetesting program to crash. If they do, your will forfeit the marks for that task. This is yourresponsibility to check. There are three common situations that you must avoid: Never divide by zero Never access any memory location that you shouldn’t (such as an invalid array access) Never have an infinite loop that causes the program to haltYou must guard against these very carefully – regardless of the input values that are passed toyour functions. Think very carefully about every array access that you make. In particular, acommon error is forgetting to initialise a variable (in which case it will store a “garbage” value),and then using that variable to access a particular index of an array. You cannot be sure what the“garbage” value will be, and it may cause the program to crash.Array allocationIf you need to declare an array in any of your function definitions, you can make use of thisconstant from summer_2019.h: #define MAX_ARRAY_SIZE 500You can assume that you functions will not need to deal with arrays that are larger than this size.CommentsYou will see in the template summer_2019.c source file that on the line above each functiondefinition there is a place-holder comment of the form: /* Your comment goeshere*/You must replace these place-holders with your own comments, written in your own words. Foreach function, you must briefly describe the problem that your function is trying to solve (insome sense, this will be a paraphrasing and summarising of the project task description). Youmust also briefly describe the algorithm that you used in your implementation for each task. Youneed to communicate your ideas clearly - this is a very important skill. Other than this, try tokeep commenting within functions to a minimum.Good luck! ENGGEN 131, Summer School, 2019 - 8 - C ProjectTask One: “It’s time!” (9 marks)Write a function that is passed four integer inputs representing two different time periods (eachexpressed as a number of minutes and seconds). The function should calculate and return thedifference between those two time periods (expressed as a number of seconds).Function prototype declaration: int SecondsBetween(int minuteA, int secondA,int minuteB, int secondB)Assumptions: You can assume that all four input values will be greater than or equal to 0.Example: int result1, result2, result3; result1 = SecondsBetween(5, 45, 7, 35); result2 = SecondsBetween(7, 35, 5, 45); result3 = SecondsBetween(0, 0, 10, 0); printf("%d %d %d \n", result1, result2, result3);Expected output: 110 110 600ENGGEN 131, Summer School, 2019 - 9 - C ProjectTask Two: “Sphere” (9 marks)Define a function called Volume() that is passed one integer input representing the radius of asphere. The function must return the volume of the sphere. The following formula gives thevolume of a sphere in terms of its radius:The output of the function must be a double. If the input value is negative, the function shouldreturn 0.0.Function prototype declaration: double Volume(int radius)Assumptions: You cannot assume the input is positive. If the input is negative, you must return 0.0. The math library is not available to you, so you cannot use the pow() function. You may use the provided value for PI: double PI = 3.141592654;Example: printf("Volume = %f\n", Volume(10)); printf("Volume = %f\n", Volume(123)); printf("Volume = %f\n", Volume(-5));Expected output: Volume = 4188.790205 Volume = 7794781.463028 Volume = 0.000000 ENGGEN 131, Summer School, 2019 - 10 - C ProjectTask Three: “How do you like them apples?” (9 marks)You are running a new café on campus, where students pre-order their meals the night before.Students receive complimentary apples with their meals, and every morning you purchase theapples you need for the day from the fruit shop. Apples come in boxes, and the number ofapples in each box varies depending on the season. You must purchase enough boxes so that nostudent misses out, but you don’t want to purchase more boxes than you need.Every student must receive exactly one apple, unless it is the last day of the week in which caseevery student receives exactly two apples. Any apples that were remaining from the previousday can be reused today so do not need to be purchased. For this task, you must write a functionthat takes four integer inputs: the number of students, whether or not it is the last day of the week(either 0 or 1), the number of apples remaining from the previous day that can therefore bereused, and the number of apples being sold per box at the fruit shop. You can assume that noneof these inputs will be negative values. Your function must return the minimum number ofboxes you need to purchase today so that no student misses out. This function should be calledAppleBoxesNeeded(). You can assume that the input value applesPerBox is at least 1.Function prototype declaration: int AppleBoxesNeeded(int numStudents, int lastDayOfWeek,int remainingApples, int applesPerBox);Example: printf("Boxes = %d \n", AppleBoxesNeeded(47, 1, 5, 8)); printf("Boxes = %d \n", AppleBoxesNeeded(13, 1, 6, 10)); printf("Boxes = %d \n", AppleBoxesNeeded(21, 0, 0, 10));Expected output: Boxes = 12 Boxes = 2 Boxes = 3ENGGEN 131, Summer School, 2019 - 11 - C ProjectTask Four: “Prime time” (9 marks)Define a function called PrimeBelow() that is passed one integer input representing an upperbound. The function must return the largest prime number that is less than this upper bound. Asthe smallest prime number is 2, if the input to the function is 2 or less, the function should return-1 to indicate an error.Function prototype declaration:int PrimeBelow(int upper)Assumptions: You cannot assume the input is greater than 2. If the input to the function is 2 or less, then you must return -1.Example: printf("Prime = %d\n", PrimeBelow(10)); printf("Prime = %d\n", PrimeBelow(47)); printf("Prime = %d\n", PrimeBelow(2));Expected output: Prime = 7 Prime = 43 Prime = -1ENGGEN 131, Summer School, 2019 - 12 - C ProjectTask Five: “Sum of them” (9 marks)Write a function that is passed four inputs: an array of integers, the number of elements in thearray, a low value and a high value. The function should calculate and return the sum of everyelement in the array that is between low and high (inclusive). In other words, you must calculatethe sum of all values in the array that are greater than or equal to the value of low and less thanor equal to the value of high. Any value that falls outside of that range should be ignored whenyou calculate the sum.Function prototype declaration: int SumInRange(int *values, int numValues, int low,int high)Assumptions: You can assume that there will be at least one element in the input array and that the value of low will be less than or equal to the value of high.Example: int numbers[11] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}; int result1, result2, result3; result1 = SumInRange(numbers, 11, 0, 100); result2 = SumInRange(numbers, 11, -2, 2); result3 = SumInRange(numbers, 11, -4, -4); printf("%d %d %d \n", result1, result2, result3);Expected output: 15 0 -4ENGGEN 131, Summer School, 2019 - 13 - C ProjectTask Six: “Another dimension” (9 marks)A matrix, or two-dimensional grid of numbers, can be represented using a one-dimensional arraywhere all of the values in the matrix are listed one row after another. For this task, you mustwrite a function which takes as input a one-dimensional array (representing a matrix) along withthe number of rows and columns in the matrix. You must calculate the row and column positionof the largest value in the matrix. The last two inputs to the function are pointers into which youshould store this result. You can assume the number of elements provided in the first inputmatch the given dimensions of the matrix, and that any input array will have at least one elementand a unique maximum value (i.e. there won’t be two values which are both the largest).Function prototype declaration: void PositionOfMaximum(int *values, int rows, int cols,int *row, int *col);Example: int maxRow, maxCol; int values[15] ={4,2,7,70,20,90,732,612,108,44,65,52,0,1,9}; PositionOfMaximum(values, 5, 3, &maxRow, &maxCol); printf("Maximum is at row: %d and col: %d", maxRow,maxCol);Expected output: Maximum is at row: 2 and col: 0 ENGGEN 131, Summer School, 2019 - 14 - C ProjectTask Seven: “Capital importance” (9 marks)A phrase consists of a sequence of words which are separated by one or more space characters.For this task, you must write a function which takes a single string as input representing a phrase,and capitalises the first character in each word in the phrase. A word may be composed ofnumeric, alphabetic or punctuation characters, but only lower case alphabetic characters (that is,‘a’ - ‘z’) should be capitalised. You can assume the input string will have at least one character. void Capitalise(char *phrase);Example char song[1000] = "god of nations at thy feet"; char here[1000] = "The University of Auckland"; char also[1000] = "a,b,c 888 d!e!f"; Capitalise(song); Capitalise(here); Capitalise(also); printf("%s \n", song); printf("%s \n", here); printf("%s \n", also);Expected output God Of Nations At Thy Feet The University Of Auckland A,b,c 888 D!e!fENGGEN 131, Summer School, 2019 - 15 - C ProjectTask Eight: “Unique” (9 marks)Write a function that is passed two inputs: an array of integers, and the number of elements in thearray. The function should return the number of distinct (i.e. different) values that exist in thearray.Function prototype declaration: int CountDistinct(int *values, int numValues)Assumptions: You can assume that there will be at least one element in the input array.Example: int valuesA[10] = {1, 2, 3, 2, 3, 2, 1, 2, 3, 2}; int valuesB[5] = {10, 100, 1000, 10000, 100000}; int valuesC[7] = {10, 11, 12, 13, 12, 11, 10}; int result1, result2, result3; result1 = CountDistinct(valuesA, 10); result2 = CountDistinct(valuesB, 5); result3 = CountDistinct(valuesC, 7); printf("%d %d %d \n", result1, result2, result3);Expected output: 3 5 4ENGGEN 131, Summer School, 2019 - 16 - C ProjectTask Nine: “Building consent” (9 marks)You are the town planner for a new town called Squaresville, where property prices are out ofcontrol due to the fact there is very little space. Every building has a perfectly square groundarea, however some buildings have larger areas than others. Anyone can submit plans for a newbuilding, and your job is to calculate how much ground area is going to be consumed by thesenew buildings. However, not all submissions will be approved. If any two building plansoverlap or intersect then they will be denied and you can ignore them from your calculation ofthe total area (in such cases, the builders will have to go to court to fight it out, and this processcould take years).In this task, the ground area for a building is represented using the Square type. This is astructure type which is composed of three fields: row, col and size. The “row” and “col” fieldsrepresent the top-left position of the square and the “size” field represents the length of one ofthe sides of the square.For this task, you must write a function called ApprovedArea() which takes two inputs: an arrayof type Square (where each element in the array represents the proposed ground area for onebuilding), and the number of elements in the array. Your function must calculate the total area ofall buildings in the array that will be approved. In other words, you should exclude from yourcalculation of the total area any buildings which intersect or overlap with one another. You canassume that for any given Square representing a building, the row and col fields will be positivenumbers, and the size field will be at least 1. You can also assume that the input array will haveat least one element. int ApprovedArea(Square squares[MAX_ARRAY_SIZE],int numSquares);ENGGEN 131, Summer School, 2019 - 17 - C ProjectExample: Square squares[5]; squares[0].row = 200; squares[0].col = 150; squares[0].size = 100; squares[1].row = 490; squares[1].col = 490; squares[1].size = 20; squares[2].row = 20; squares[2].col = 390; squares[2].size = 200; squares[3].row = 290; squares[3].col = 240; squares[3].size = 100; squares[4].row = 195; squares[4].col = 575; squares[4].size = 10; result = ApprovedArea(squares, 5); printf("The valid area is %d \n", result);Expected output: The valid area is 400Assumptions:Each building base is represented by a square,where the “row” and “col” value indicate thetop left hand corner. It might help to think ofthis as being positioned on a grid like theexample on the right - which shows a squarepositioned at (2, 3) and with a “size” of 4.Two squares will “overlap” or “intersect” ifany of the filled in grid pieces overlap. ENGGEN 131, Summer School, 2019 - 18 - C ProjectTask Ten: “Squash it” (9 marks)Write a function to eliminate long sequences of consecutive characters in a word. Your functionshould take two inputs. The first is the word itself (i.e. a string), and the second is the maximumnumber of consecutive characters that are allowed to appear in the word - all consecutivecharacters exceeding this maximum should be eliminated. Your function will not return anoutput, but instead must modify the input word.Function prototype declaration: void Squash(char *word, int maximum)Assumptions: You can assume that the input string will consist of at least one character (in addition to the null terminating character). You can also assume that the value of maximum will be greater than or equal to 0.Example: char word0[MAX_ARRAY_SIZE] ="LLLLeeeeeeerrrrrooooy Jeeeeeeenkkkins"; char word1[MAX_ARRAY_SIZE] ="Heeeeeelllllllooooooo wwwwwooorldddd"; char word2[MAX_ARRAY_SIZE] ="xxxxyyyyxxxyyyxxyyxyxxyyxxxyyyxxxxyyyy"; char word3[MAX_ARRAY_SIZE] = "OOOKKKKKKKKKK"; char word4[MAX_ARRAY_SIZE] = "Hello world"; char word5[MAX_ARRAY_SIZE] = "Hello world"; Squash(word0, 1); Squash(word1, 2); Squash(word2, 1); Squash(word3, 5); Squash(word4, 1); Squash(word5, 0); printf("0) (%s) \n", word0); printf("1) (%s) \n", word1); printf("2) (%s) \n", word2); printf("3) (%s) \n", word3); printf("4) (%s) \n", word4); printf("5) (%s) \n", word5);ENGGEN 131, Summer School, 2019 - 19 - C ProjectExpected output: 0) (Leroy Jenkins) 1) (Heelloo wwoorldd) 2) (xyxyxyxyxyxyxy) 3) (OOOKKKKK) 4) (Helo world) 5) ()? ?ENGGEN 131, Summer School, 2019 - 20 - C ProjectBEFORE YOU SUBMIT YOUR PROJECTWarning messagesYou should ensure that there are no warning messages produced by the compiler (using the /W4option from the VS Developer Command Prompt).REQUIRED: Compile with Visual Studio before submissionEven if you haven’t completed all of the tasks, your code must compile successfully. You willget some credit for partially completed tasks if the expected output matches the output producedby your function. If your code does not compile, your project mark will be 0.You may use any modern C environment to develop your solution, however prior to submissionyou must check that your code compiles and runs successfully using the Visual Studio DeveloperCommand Prompt. This is not optional - it is a requirement for you to check this. Duringmarking, if there is an error that is due to the environment you have used, and you failed to checkthis using the Visual Studio Developer Command Prompt, you will receive 0 marks for theproject. Please adhere to this requirement.In summary, before you submit your work for marking:STEP 1: Create an empty folder on diskSTEP 2: Copy just the source files for this project (the summer_2019.c andtest_summer_2019.c source files and the unedited summer_2019.h header file) intothis empty folderSTEP 3: Open a Visual Studio Developer Command Prompt window (as described in Lab 7)and change the current directory to the folder that contains these filesSTEP 4: Compile the program using the command line tool, with the warning level on 4: cl /W4 *.cIf there are warnings for code you have written, you should fix them. You shouldnot submit code that generates any warnings.Do not submit code that does not compile!ENGGEN 131, Summer School, 2019 - 21 - C ProjectStyle marking - components (10 marks)To be eligible to earn full marks for style, you will need to have completed *at least half* of theten required functions. Even if you have not completed all of the ten functions, you should stillleave the templates of all ten functions in your submitted file (do not delete any of the tenfunctions from the template that was provided to you). The following provides a briefdescription of what style components will be assessed:Comments (5 marks):Read the description of what is required on Page 7 of the project document. You must write acomment for each of the required functions you have implemented at the very top of the functiondefinition (by replacing the placeholder comment: "Your comment goes here" in the template fileprovided to you). Each function's comment should describe (in your own words) the problemthat the function is solving, and (also in your own words) the approach that you took to solve thefunction. The expectation is that this comment will be a short paragraph, consisting of at leastseveral sentences (written in your own words) that would serve as useful documentation forsomeone who wanted to understand what your code is all about. You are welcome to alsoinclude short comments within the function body, however you should avoid "over-commenting"the code body - this marks it hard to read.Indentation (2 marks):Your code should be indented consistently and laid out neatly. There are many examples in thecoursebook (particularly at the end of each lecture) that you can refer to here, as well asexamples on page 3. There is also a brief style guide on page 4. It is recommended that youfollow these style guidelines, however if you strongly prefer a different style (such as placing theopening brace for an if statement on a new line, which differs from the advice on page 4 underthe heading "Braces for other blocks of code") then that is fine - as long as you apply that styleconsistently throughout your source file. You should also lay out your code neatly - for example,do not place blank lines between every single line of code, but rather separate short "blocks" ofcode (lines that are related) with a single blank line.Helper functions (3 marks):You should define at least two "helper" functions, and call these functions from one or more ofthe required functions. All of the helper function definitions should appear at the top of yoursource file (where the comment "HELPER FUNCTIONS" appears in the template file providedto you) so that it is easy for your marker to locate them. You should apply the same styleelements to these helper functions - that is, they must begin with a comment describing thepurpose of the function - and you should also mention which of the required functions make useof each helper function. A good reason to define a helper function is to reduce the complexity ofone of the required functions - particularly if the code would otherwise be particularly long. Agood "rule of thumb" (derived from Google's style conventions for C-based code) is that if thelength of a function exceeds about 40 lines of code then you should think carefully aboutwhether a helper function could be used to reduce this length. Your marker will not be countingyour lines of code exactly, so this 40-line rule is not a strict limit, but should serve as a usefulguideline. ENGGEN 131, Summer School, 2019 - 22 - C ProjectThe final wordThis project is an assessed piece of coursework, and it is essential that the work you submitreflects what you are capable of doing. You must not copy any source code for this project andsubmit it as your own work. You must also not allow anyone to copy your work. Allsubmissions for this project will be checked, and any cases of copying/plagiarism will be dealtwith severely. We really hope there are no issues this semester in ENGGEN131, as it is a painfulprocess for everyone involved, so please be sensible!Ask yourself:have I written the source code for this project myself?If the answer is “no”, then please talk to us before the projects are marked.Ask yourself:have I given anyone access to the source codethat I have written for this project?If the answer is “yes”, then please talk to us before the projects are marked.Once the projects have been marked it is too late.There is more information regarding The University of Auckland’s policies on academic honestyand plagiarism here:http://www.auckland.ac.nz/uoa/home/about/teaching-learning/honesty因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:
微信:codinghelp