合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

        代寫 tic-tac-toe game 、代做Python/Java程序語言

        時間:2024-06-09  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



        Homework 4 Revision 1
        Due: June 6, 2024; late due date is June 11
        Points: 100
        1. In problem 1, if the square is occupied, you need to give the error message. “%c has played %d,%d\n” (where “%c” is either “X” or “O”, whichever is already in the square, and “%d,%d” are the co-ordinates of the occupied square).
        2. In problem 1, the dimensions of the “O” was added; it is to be 5 × 5 centered in the square.
        3. For all problems, the exit status code is 0.

        (25 points) Enhance the tic-tac-toe game so 2 people can play. To do this, you need to add an“O” that, like the “X”, is drawn in the square. Then prompt the user for a square identifier, and alternate between drawing “X”s and “O”s at those locations on the board. The first move is for “X”. You need to detect and reject when a user plays a square that is already taken. Stop after the board is full (that is, 9 plays). You do not have to worry about who wins.
        The “O” is to be 5 × 5, centered in the middle of the square.

        Here are the messages your program should print to the standard output:

        The tic-tac-toe board, with “X”s and “O”s as appropriate;
        When it is “X”’s turn, print “X’s turn > ” (note the space after the “>”); and
        When it is “O”’s turn, print “O’s turn > ” (again, note the space after the “>”).
        Here are the error messages; all are to be printed on the standard error:

        When the user enters only 1 co-ordinate: “Need 2 co-ordinates\n” (the ‘\n’ is a newline);
        When there is an illegal character in the input: “Illegal character in input "%c"\n” (the “%c” is to print the offending character); and
        When the square is already occupied: “%c has played %d,%d\n” (where “%c” is either “X” or “O”, whichever is already in the square, and “%d,%d” are the co-ordinates of the occupied square); and
        When an invalid set of co-ordinates are entered: “%d,%d” is not a valid square; the numbers must be between 1 and 3 inclusive\n” (each %d is one of the invalid numbers).
        If the program reads an end of file at the prompt, print a newline and quit.

        The program should exit with an exit status code of 0.

        Please call your program ttt4a.c and submit it through Gradescope. A sample executable, used to generate the Gradescope validation outputs, is available on the CSIF at /home/bishop/hw4/ttt4a.

        (25 points) Now enhance what you did for question 1. Have your program determine when the game is over — that is, there is a winner (three in a row, column, or diagonal) or a tie (no winner and all 9 squares on the board are full). Print the results on the standard output:
        If X wins, print “Game over! X won!\n”;
        If O wins, print “Game over! O won!\n”; or
        If X wins, print “Game over! It’s a tie!\n”.
        Please call your program ttt4b.c and submit it through Gradescope. A sample executable, used to generate the Gradescope validation outputs, is available on the CSIF at /home/bishop/hw4/ttt4b.

        (50 points) The birthday problem asks how many people must be in a room so that the probability of two of them having the same birthday is 0.5. This problem has you explore it by simulation. Basically, you will create a series of lists of random numbers of length n = 2, …, and look for duplicates. You will do this 5000 times for each length. For each length, count the number of lists with at least 1 duplicate number; then divide that number by 5000. That is the (simulated) probability that a list of n generated numbers has at least one duplicate. As the random numbers you generate are between 1 and 365 (each one corresponding to a day of the year), this simulates the birthday problem.
        Now, breathe deeply and calm down. We will do this in steps; you only have to turn the final program in to Canvas (not Gradescope).

        First, detecting duplicates. Write a function called hasduplicates(bday) that takes an array bday and returns 1 if it contains a duplicate element, and 0 if it does not. For example, if bday is

        int bday[] = { 1, 2, 3, 4, 5, 5, 2 };
        then hasduplicates(bday) returns 1 and if

        int bday[] = { 1, 2, 3, 4, 5, 6, 7 };
        then hasduplicates(bday) returns 0.
        Now, deal with one set of birthdays. Write a function called onetest(count) that generates a list of count random integers between 1 and 365 inclusive, and returns 1 if it contains a duplicate element, and 0 if it does not. Please use the function hasduplicates(bday) to test for duplicates.
        Now for the probability for count people. Write a function probab(count, num) that runs num tests of count people, and counts the number of tests with duplicates. It returns the fraction of the tests with duplicates; that is, the number of duplicates divided by num.
        Now for the demonstration. Start with 2 people, and begin adding people until the probability of that many people having two people with a birthday in common is over 0.5. (In other words, start with a list of 2 elements, and increase the number of elements in the list until the simulation shows a probability of 0.5 that a number in the list is duplicated.) Print each probability; your output should look like this:

        For  2 people, the probability of 2 birthdays in common is 0.001400
        For  3 people, the probability of 2 birthdays in common is 0.006600
        For  4 people, the probability of 2 birthdays in common is 0.015200
        For  5 people, the probability of 2 birthdays in common is 0.025400
        For  6 people, the probability of 2 birthdays in common is 0.041400
        For  7 people, the probability of 2 birthdays in common is 0.053000
        For  8 people, the probability of 2 birthdays in common is 0.082000
        For  9 people, the probability of 2 birthdays in common is 0.092200
        For 10 people, the probability of 2 birthdays in common is 0.121800
        Hint: Don’t be surprised if your probabilities are slightly different than the ones shown in the sample output. As randomness is involved, it is very unlikely your numbers will match the ones shown here.
        To turn in: Please call your program bday.c and submit it through Canvas (not Gradescope). A sample executable is available on the CSIF at /home/bishop/hw4/ttt4b.
        請加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp























         

        掃一掃在手機打開當前頁
      1. 上一篇:菲律賓9A簽證有哪些(9A簽證詳細介紹)
      2. 下一篇:菲律賓旅游簽證回國流程(回國不能帶什么東西)
      3. 無相關信息
        合肥生活資訊

        合肥圖文信息
        出評 開團工具
        出評 開團工具
        挖掘機濾芯提升發動機性能
        挖掘機濾芯提升發動機性能
        戴納斯帝壁掛爐全國售后服務電話24小時官網400(全國服務熱線)
        戴納斯帝壁掛爐全國售后服務電話24小時官網
        菲斯曼壁掛爐全國統一400售后維修服務電話24小時服務熱線
        菲斯曼壁掛爐全國統一400售后維修服務電話2
        美的熱水器售后服務技術咨詢電話全國24小時客服熱線
        美的熱水器售后服務技術咨詢電話全國24小時
        海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
        海信羅馬假日洗衣機亮相AWE 復古美學與現代
        合肥機場巴士4號線
        合肥機場巴士4號線
        合肥機場巴士3號線
        合肥機場巴士3號線
      4. 上海廠房出租 短信驗證碼 酒店vi設計

        主站蜘蛛池模板: 亚洲乱码一区av春药高潮| 蜜桃传媒视频麻豆第一区| 一区二区三区日韩精品| 乱人伦一区二区三区| 午夜AV内射一区二区三区红桃视| 国内偷窥一区二区三区视频| 中文字幕一区二区视频| 亚洲日本中文字幕一区二区三区| 2021国产精品视频一区| 无码乱码av天堂一区二区| 国产乱人伦精品一区二区| 免费播放一区二区三区| 日韩精品无码一区二区中文字幕 | 日韩精品电影一区亚洲| 国偷自产视频一区二区久| 亚洲大尺度无码无码专线一区| 99精品国产高清一区二区麻豆| 亚洲制服丝袜一区二区三区| 亚洲av无码片区一区二区三区| 精品无码人妻一区二区三区 | 无码人妻一区二区三区av| 国产日韩精品视频一区二区三区 | 国产综合精品一区二区| 高清在线一区二区| 精品乱子伦一区二区三区高清免费播放| 国产一区视频在线免费观看| 精品乱码一区二区三区在线| 国产成人高清视频一区二区| 国产高清精品一区| 无码精品国产一区二区三区免费| 亚洲欧洲一区二区| 人妻av综合天堂一区| 一区视频免费观看| 国产AV午夜精品一区二区入口| 日韩人妻精品一区二区三区视频| 日韩av片无码一区二区不卡电影| 日本在线电影一区二区三区| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲国产av一区二区三区丶| 在线欧美精品一区二区三区 | 国内精品一区二区三区东京|