” XJCO1711编程语言 辅导、 写作C/C++程序University of Leeds School of ComputingProcedural Programming COMP1711/XJCO1711Semester 1, 2020-2021Coursework 3100 Marks (40% of the total module mark)To be submitted before: 23:00 (UK time) on 11 December 2020Late penalties: 5% will be deducted from the overall mark of this coursework for everylate daySkills TestedThis coursework will test your ability to write C code that correctly uses structures, character strings,pointers, and file i/o. You will also learn how a program can be divided across multiple source files.The BriefYou will write a program that allows people to name pairs of stars in a hypothetical universe by theirnames.The DetailsAn astronomer wanted to surprise their spouse on their anniversary by showing them a simulation ofthe Big Bang on a computer, then naming the closest pair of stars created by this Big Bang with theirnames. Big Bang is the name of a cosmological theory that assumes that the universe started from theexpansion of a single very high-density singularity.Fortunately, the program is not supposed to go anywhere close to a real simulation of the Big Bang.For the purposes of this simple program, our Big Bang simply fills a flat rectangular space with starsscattered at random positions. The program then allows a user to find the closest pair of unnamedstars in this universe and assign the users name to the first star in this pair, and the name of the usersspouse to the second star.The TaskWrite a command driven program that accepts the following commands:The Bang commandThis command creates a hypothetical universe comprised of stars only. The stars should be randomlyscattered across the universe.We are assuming that the universe is flat and rectangular and is 60 light years long and 30 light yearswide. A light year is a unit of measure of distance and is equal to the distance that light can travel inone year (5.879×1012 miles). Do not get daunted by this jargon, just assume that your space is arectangle 60 units long and 30 units wide.The bang command takes one integer argument representing the number of stars to be created. Forexample, if the player types: bang 100the program will create 100 stars randomly distributed within the universe (the 60×30 rectangle). Theposition of a star is determined by two coordinates, x and y. No two stars should have the samecoordinates. For simplicity, assume that x and y are both integers. Also assume that the origin of thecoordinate system is at the upper left corner of the universe, with the x axis pointing to the right, andthe y axis pointing downwards, as shown in the following figure:Note that in the above figure, the aspect ratio (ratio of height to width) of the universe is distorted.The reason for this will be explained later on.It is important to keep the origin of the coordinate system at the upper left corner, and the directionsof the axes as shown. Changing these assumptions could make it more difficult to implement thedrawing functions of the game.Each star must have a unique serial number (id) generated by the program when the universe iscreated. Initially, stars have no names, but players can later name stars using the name command (seebelow).If the bang command is issued again (after a universe has been created), the existing universe isdestroyed and a new one is created in its place.The list commandThis command Simply prints a list of all stars in the universe. For each star, the command prints thestars serial number, name (if the star is named), and the stars x and y coordinates. For example, ifthe player types: listthe program prints a list similar to this one:Note that in the above list none of the stars has a name, which is the situation when a new universeis created.The name commandThis command is used to find the closest pair of stars that has not been named yet and allow the userto name this pair. The program prompts the user to enter their name and that of their spouse. Thefirst star in the pair is named after the player, and the second is named after the players spouse. Oncea pair of stars is named, this pair is permanently reserved for its owners and cannot be renamed byother players. Here is an example of the name command:However, if all pairs have already been named, the program prints a message similar to this:The pairs commandThis command prints a list of all star pairs that have been named so far. For each pair, the programprints the pairs number, the distance between the two stars of this pair, and the details of the twostars. Here is an example:The draw commandThis command is used to draw the universe. Named stars appear as asterisks (*), while unnamed starsappear as dots (.). Here is an example:You will NOT be using any graphics library to draw the universe. Instead, you will use a simple trick toconvert the Standard terminal to a primitive drawing window. This will be explained below.The show commandThis command is used to display the names of the couple who own a pair of stars. When this commandis executed the program prompts the user to enter their name as shown belowThe program then searches for a pair of stars named after this user, and if a pair is found, the programdisplays the names of the couple who own the pair under the stars of this pair, as shown in thefollowing example:The save commandThis command is used to save the universe. By this we dont mean saving the universe from the evilsof a supervillain. Instead, this command saves the programs data into a file. The command shouldsave all stars and all named pairs in the universe into a binary file called universe.bin located in theprograms directory. Here is an example:The load commandThis command is used to load (read) saved data from the universe.bin file. When the command isexecuted the program reverts to the point at which it was saved.The quit commandThis command is used to terminate the program.Implementation GuidelinesGenerating random numbersTo generate random values for star coordinates, you can use the rand function. This function is definedin the stdlib.h library. When the function is called it returns a random integer between 0 andRAND_MAX. The value of RAND_MAX is system dependent but is guaranteed to be at least 32767.You can scale the Random number returned by rand to any required range [0, x-1] by applying themodulo operator on the value returned by the function, like this:int r = rand() % x; // r is a random number in the range [0, x-1];Unfortunately, the rand function is a pseudorandom number generator, which means that it willalways generate the same sequence of random numbers every time you run the program. To get adifferent sequence each time, you can use the srand function (also defined in stdlib.h). The srandfunction seeds the random number generator with an initial value. By changing the initial value, wecan get different random number sequences. We need a value that is different every time we run theprogram. This can be some distinctive runtime value, like the value returned by the time functiondefined in the time.h. The time function returns the time in seconds that elapsed since some pastpoint in time. You should seed your random number generator only once at the beginning of yourprogram like this:time_t t;srand((unsigned) time(t));Using the terminal as a Graphics windowTo draw the stars of the universe on the terminal, we will use a simple trick based on the fact thatthe terminal prints characters in a rectangular grid of rows and columns. The cursor that determinesthe position of the next character to be printed is initially at the top left corner of the terminal window.When a single character is printed, the cursor moves exactly one column to the right. When the newline character (\n) is printed the cursor moves to the first column in the next row. The following figureshows how the terminal will look like when 30 rows of characters, with 60 characters (columns) perrow, are printed.In this sense, the terminal can be considered as a very coarse grid of pixels, just like any other graphicsdisplay. However, the elements of the grid are characters rather than pixels. Notice that the abovegrid appears rather squarish although it has twice as many columns as it has rows. This is because theheight of the font used to display the characters is almost twice as its width. Most Latin fonts are likethis, but you may find one on your machine that is not.To draw things on the terminal, you will need a two-dimensional array (matrix) of characters. We willcall this matrix the frame buffer because it will be used to prepare the frame (picture) of the universebefore printing it on the screen. Each row in this matrix corresponds to one row of characters on theterminal. The frame buffer will have 31 rows and 61 columns, as shown below:Now, to draw a star whose (x, y) coordinates are (4, 1) for example, we simply store the asterisk (*) inrow 1 and column 4 of the frame buffer as shown above. And, to draw the letter X in location (57, 3)we put X in row 3 and column 57 of the frame buffer.After all the stars of the universe are stored in their correct positions in the frame buffer, the wholeframe buffer can be Displayed on the terminal in one go.Submission Instructions Write the program in standard C. If you write your code in any other language, it will NOT bemarked, and you will get a zero for this coursework. Gradescope will be used to mark this coursework. Detailed instructions on how to prepare andsubmit your code to Gradescope will be published on Minerva. Four files – called uni.h, graph.c, logic.c, and main.c – are provided for you to start developingyour code. Do not alter anything in uni.h and do not submit it to Gradescope. File uni.h contains some function prototypes. You must implement the body of these functionsin the graph.c, logic.c and main.c files. You will also need to use these functions to implementthe program functionality. Make sure that you fill in your name, University number, and the date you started working onthe assignment in the space provided at the top of each file. This is an individual project, and you are not supposed to work in groups or pairs with otherstudents. Please be aware that plagiarism in your code will earn you a zero mark and will have veryserious consequences. It is much better to submit your own partially finished work, than tofall into the trap of plagiarism. We use software to detect plagiarism, so if you do workwith someone else, or submit someone elses work it WILL be detected.Finally, lets hope that the astronomers wife will be impressed by the game after all this hard work.Marking SchemeGraphics FunctionsFunction ClearBuffer () (4 marks)Function plot () (2 marks)Function peek () (2 marks)Function writeAt () (6 marks)Function showBuffer () (6 marks)Program Logic FunctionsFunction findStarByXY () (5 marks)Function bigBang () (12 marks)Function pointDistance () (2 marks)Function ClosestPair () (12 marks)Function nameStar () (5 marks)Function findPairByName () (4 marks)Function saveUniverse () (6 marks)Function loadUniverse () (6 marks)Interface Functions and the User InterfaceFunction printStar () (2 marks)Function listStars () (2 marks)Function listPairs () (4 marks)Function drawUniverse () (6 marks)Function TagPair () (6 marks)The user interface works correctly (8 marks)———————————————————————-Total mark: [100 marks]如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。