” CSCI 151程序设计 写作、C/C++实编程CSCI 151: Programming for Scientists and EngineersProgramming Assignment IIDeadline: 17 March 2021, 8:00pmExplanation for Task1 and Task 2:You will write programs to handle the games between the wrestlers and maintain theirscores in these tasks. First, create the following struct:typedef struct{int id;char firstName[100];char lastName[100];int birthYear;int score;} wrestler;A wrestler is identified by the following features: id (int), first name (char array/string),last name (char array/string), birth year (int), and score (int).Task 1 (25 points): Copypaste the following lines to the beginning of your mainfunction. Your task is to make your code work and complete it according to thedescriptions given below. (Your main will contain the following lines exactly).char inputFile[100];//creates a char array (string)strcpy(inputFile,in.txt);//copies in.txt into the string, inputFileint n = getNumberOfWrestlers(inputFile);/*retrieves the number of wrestlers in inputFile and assigns itto variable n*/wrestler list[n];/*creates a wrestler array, list, of size n to store wrestlersinfo*/init(list, inputFile);/*initializes list, which is defined above, with the informationin inputFile. You need to create a function named init thattakes 2 parameters suitable to its usage here*/printScoreBoard(list, n);/*prints the scoreboard to screen. You need to create afunction named printScoreBoard that takes 2 parameters suitableto its usage here*/writeTheChampion(list, n);/*prints the champion with the maximum score to screen. Youneed to create a function named writeTheChampion that takes 2parameters suitable to its usage here*/The format of the file in.txt is shown below:Number_of_wrestlers(N)id1 firstname1 lastname1 birthyear1 score1id2 firstname2 lastname2 birthyear2 score2idN firstnameN lastnameN birthyearN scoreNFor example, in.txt may contain the following lines:4118 john brown 2000 100234 tomas jhonson 2001 15056 kevin whale 2000 507909 Michael daisy 1998 200This means that there are 4 wrestlers in this game. The first wrestler (john brown) with id118 was born in 2000 And has a score of 100. The second wrestler (tomas jhonson) withid 234 was born in 2001 and has a score of 150, etc. Then, the above code fragmentinitializes the wrestler list array with all this information and prints out the followingoutput, where the first 5 lines are generated by printScoreBoard and the last 2 bywriteTheChampion.Printing the score board118 john brown 2000 100234 tomas jhonson 2001 15056 kevin whale 2000 507909 michael daisy 1998 200The champion is7909 michael daisy 1998 200Task 2 (25 points): Add the following lines to the end of your main. Your task is to makeyour code work and complete it according to the descriptions given below. (Your mainwill contain the lines given in Task 1 followed by the following lines exactly).strcpy(inputFile,games.txt);//copies games.txt into the string, inputFileprocessGames(inputFile, list, n);/*The matches between the wrestlers are examined as given ininputFile and then the list of size n is updated accordingly.You need to create a function named processGames that takes 3parameters suitable to its usage here*/printScoreBoard(list, n);/*prints the scoreboard to screen. This function is the same asthe one created in Task 1*/writeTheChampion(list, n);/*prints the champion with the maximum score to screen. Thisfunction is the same as the one created in Task 1*/The format of the file games.txt is shown below:wrestler_id1 wrestler_id2 match_result score…Explanation of the format: Each line consists of 4 integers. The first two numbersindicate that there is a match between wrestlers with wrestler_id1 andwrestler_id2. The Third number (match_result) can be either 0, 1, or 2, indicatingwho the winner is. If 1 then the first wrestler wins and his score is increased by score,which is the fourth integer in the line. If 2 then the second wrestler wins and his score isincreased by score. If 0 then there is a tie in the game and both wrestlers scores areincreased by score. There is no limit to the number of matches presented ingames.txt. processGames function has to read the games.txt and update list arrayaccordingly.For example, assume game.txt contains the following lines:118 234 1 20234 7909 2 407909 56 0 1056 118 1 50234 7909 0 15Then according to the first match, the wrestler with id 118 wins the match against thewrestler with id 234 and his score is increased by 20, making it 120. According to thesecond match, the wrestler with id 7909 wins the match against the wrestler with id 234and his score is increased by 40, making it 240, etc. At the end, the above codefragment modifies the scores using this information and prints out the following output,where the first 5 lines are generated by printScoreBoard and the last 2 bywriteTheChampion.Printing the score board118 john brown 2000 120234 tomas jhonson 2001 16556 kevin whale 2000 1107909 michael daisy 1998 265The champion is7909 michael daisy 1998 265Task 3 (25 points). In this assignment, you are asked to obtain a binary imageconsisting of 0s and 1s given a grayscale image img.txt consisting of values from 0to 255. The size of the provided input image img.txt is 64×96. Binarization is theprocess of taking a grayscale image and converting it to black-and-white, essentiallyreducing the information contained within the image from 256 gray levels to 2 levels:black and white.a. Import the Provided image called img.txt using file I/O functions.b. Use the following structure containing the image height, width andan array imgdata to store the image data:struct image{int height;int width;int imgdata[64][96];};c. Binarize the input image three times by using three differentthreshold values: T1 = 64, T2 = 128, T3 = 192. To do the binarization,perform the following step. If the input image is [, ], then the resultingbinary image isd. Store the 3 resulting binary images as .txt files called binary1.txt,binary2.txt, binary3.txt for three values of T, accordingly.Example of an input image with size 3×3:100 130 4020 74 50240 30 200After using T1 = 64, the binary image will be1 1 00 1 01 0 1After using T2 = 128, the binary image will be0 1 00 0 01 0 1After using T3 = 192, the binary image will be0 0 00 0 01 0 1Task 4 (25 points). Write a program that will determine a hidden integer 3-tuplegeometric progression written in consecutive order. Geometric progression is anordered list of numbers in Which each term after the first is found by multiplyingthe previous one by a fixed non-zero number called the common ratio. The initialarray should contain more than 3 integer elements and the values should begreater than 0. Output the geometric progressions and their common ratios. If nogeometric progressions are found, output None.For example,● If the input array is (1, 2, 4, 8, 7, 9) then the output should be thefollowing two geometric progressions: (1, 2, 4) with common ratioequal to 2, and (2, 4, 8) with common ratio equal to 2.● If the input array is (1, 4, 2, 8) then there are no geometricprogressions stored in consecutive order.● If the input array is (5, 2, 25, 5, 1, 3), then there is one geometricprogression: (25, 5, 1) with a common ratio equal to 1/5.● If the input is (1, 2, 4, 1, 3, 9), then there are two geometricprogressions: (1, 2, 4) with a common ratio equal to 2, and (1, 3, 9)with a common ratio equal to 3.Rules:● Late submissions will NOT be accepted. In the case of late submission, a grade 0is given.● No deadline extensions will be given.● You will lose 50 points if the program does not compile on the online compiler, httpss://repl.it/languages/c.● 5 points will be given for indentation and 5 for comments.● Assignments must be Done individually.● Submitted codes will be automatically checked using tools that detect plagiarism.● You may be asked to explain your code and rewrite a part of it in front of theinstructors.● Please submit each task in a separate .c file naming as task1.c, task2.c etc. foreach task of the assignment and submit in a zip file to the submission box ofMoodle.● All files must be with .c format. All other formats of files will not be accepted.如有需要,请加QQ:99515681 或WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。