(8 Questions)

【week 12】Homework(II)_v3_20240508 (1).pdf

CProgramming_IV_HW(II)_Ch.12_v3_20240508 (1).pdf

C Programming (IV) 112-2 Homework(II) 2024.05.08, due: 2024.05.22 23:59

【Ch.11】

11.13:

3 (Telephone-Number Word Generator) Standard telephone keypads contain the digits 0–9. The numbers 2–9 each have three letters associated with them, as is indicated by the following table:

(電話號碼的單字產生器)標準的電話鍵盤都有數字按鍵 0 到 9。而其中 2 到 9 的按鍵上每一個都有三個字母,如下表 所示:

Untitled

Many people ϐind it difϐicult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686- 2377 might use the correspondence indicated in the above table to develop the seven-letter word “NUMBERS.” Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then, no doubt, the business will receive a few more calls. Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e.,“TAKEOUT”). Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It’s possible, however, that the owner of a barber shop would be pleased to know that the shop’s telephone number, 424-7288, corresponds to “HAIRCUT.” The owner of a liquor store would, no doubt, be delighted to ϐind that the store’s telephone number, 233-7226, corresponds to “BEERCAN.” A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters “PETCARE.” Write a C program that, given a seven-digit number, writes to a ϐile every possible seven-letter word corresponding to that number. There are 2187 (3 to the seventh power) such words. Avoid phone numbers with the digits 0 and 1.

許多人覺得電話號碼很難記,所以他們使用數字和字母間的對應將電話號碼對應到 7 個字母的單字。例如,若某人 的電話號碼是 686-2377,他可以利用以上的對照表,發明出「NUMBERS」這個七個字母的單字。 企業界經常會想辦法使他們的電話號碼容易被客戶們記住。如果某家公司能以一個簡單的單字來代表他的電話號碼,無 疑地這家公司將可以接到更多的電話。 每個 7 個字母的單字都只會對應到一組 7 位數的電話號碼。餐廳如果希望增進外賣業務,則可以使用 825-3688(註: TAKEOUT)的電話號碼。 每個 7 位數的電話號碼,會對應到許多單獨的 7 個字母的單字。不幸的是,大部分拼湊出來的單字都是沒有意義 的。然而,當理髮店的老闆發現店裡的電話號碼 424-7288 會對應到「HAIRCUT」時,可能會非常高興。無疑地,酒店 老闆也會對 233-7226 這支號碼感到欣喜若狂,因其對應到「BEERCAN」。而擁有 738-2273 這支號碼的獸醫,會很高興 知道該號碼對應到「PETCARE」。 撰寫一個程式,對於每個指定的七位數號碼,產生所有可能對應的 7 個字元的單字組合,並將它們寫入檔案中。共有 2187(3 的 7 次方)個單字。請避免使用 0 與 1 的電話號碼。

11.16:

(Outputting Type Sizes to a File) Write a program that uses the sizeof operator to determine the sizes in bytes of the various data types on your computer system. Write the results to the ϐile "datasize.dat" so you may print the results later. The format for the results in the ϐile should be as follows (the type sizes on your computer might be different from those shown in the sample output):

(將資料型別的大小寫入檔案)請使用 sizeof 運算子寫一支程式,判斷電腦系統上各種資料型別的位元組大小。將結 果寫入檔案 “datasize.dat”,以便稍後印出結果。檔案中的結果格式應如下所示(你的電腦上各種資料型別的大小 可能與範例的輸出結果之顯示不同):

Untitled

12.6:

(Concatenating Lists) Write a program that concatenates two linked lists of characters. The program should include function concatenate that takes pointers to both lists as arguments and concatenates the second list to the ϐirst list.

(插入串列後串接)試撰寫一支程式,串接兩個鏈結的字元串列的程式。此程式應該包含函式 concatenate,將兩個 表的指標作為引數,並將第二個串列串接到第一個串列。