本文共 1729 字,大约阅读时间需要 5 分钟。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Many computer programs use menus as part of the user interface. A menu offers the user a choice of responses. The user then enters one of these choices, and the program acts on that choice.
For example:
Enter the operation of your choice:
a. judge character b. print character
c. get a power d. base_n
e. exit/quit
Write a program that shows you a menu offering you the choice of :
a: Write a function that reads characters from the standard input to end-of-file. For each character, have the program report whether it is a letter. If it is a letter, also report its numerical location in the alphabet. For example, c and C would both be letter 3. Incorporate a function that takes a character as an argument and returns the numerical location if the character is a letter and that returns –1 otherwise.
b: Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes use of this function.
c: Write a power() function that returned the result of raising a type double number to a positive integer value. Improve the function so that it correctly handles negative powers. Also, build into the function that 0 to any power is 0 and that any number to the 0 power is 1.
d: Write a to_base_n() function that takes a second argument in the range 2–10. It then should print the number that is its first argument to the number base given by the second argument. For example, to_base_n(129,8) would display 201, the base-8 equivalent of 129.
e: end this program
怎么写?
多谢
转载地址:http://zmiox.baihongyu.com/