1

i have the following question:

Computers are frequently used in check-writing systems, such as payroll and accounts payable applications. Many stories circulate regarding weekly pay- checks being printed (by mistake) for amounts in excess of $1 million. Weird amounts are printed by computerized check-writing systems because of human error and/or machine failure. Systems designers, of course, make every effort to build controls into their systems to prevent erroneous checks from being issued. Another serious problem is the intentional alteration of a check amount by some- one who intends to cash it fraudulently. To prevent a dollar amount from being altered, most computerized check-writing systems employ a technique called check protection.

Checks designed for imprinting by computer contain a fixed number of spaces in which the computer may print an amount. Suppose a paycheck contains nine blank spaces in which the com- puter is supposed to print the amount of a weekly paycheck. If the amount is large, then all nine of those spaces will be filled

for example:

11,230.60 (check amount)
---------
123456789 (position numbers)

On the other hand, if the amount is less than $1000, then several of the spaces will ordinarily be left blank—for example,

99.87
---------
123456789

contains four blank spaces. If a check is printed with blank spaces, it is easier for someone to alter the amount of the check. To prevent a check from being altered, many check-writing systems insert leading asterisks to protect the amount as follows:

****99.87
---------
123456789

Write a program that inputs a dollar amount to be printed on a check and then prints the amount in check-protected format with leading asterisks if necessary. Assume that nine spaces are available for printing an amount.

im not asking anyone to write the code for me or anything, i just need a starting point, we have this huge list of all these different functions, can anyone recommend what function i could use from the string-handling library?

4

3 回答 3

2

我不会为你做功课,但我会鼓励你看看以下函数:

sprintf - 格式化输出。

提示:0 填充左侧的输出

strspn / strcspn - 计算字符集中/不在字符集中的跨度

提示:替换多余的零。

memset - 用字节值填充内存区域

我假设您知道如何在 C 中使用字符和“字符串”进行指针运算。如果不知道,请继续学习。我还假设 ASCII,而不是 unicode。如果它是 unicode,你可以教我如何用 C 来做 :-)

于 2012-04-27T04:38:14.770 回答
2

考虑要打印的位数与应在数字前面的星号数之间的关系。它们加起来应该是一个常数,在本例中为 9。因此,如果您获得要打印的数字字符串的长度,您可以确定首先打印多少个星号。

于 2012-04-27T04:39:11.777 回答
0
  1. 使用itoa转换 amt并找到长度

  2. 现在从 9(最大位数)中减去长度,您将得到要打印的星号数

  3. 打印那个星号,然后是你的 Amt。


int amt,count;
char s[10];
printf("Enter Amt");
scanf("%d",&amt);

/* Store Amount as String */
itoa(amt,s,10);

/* Calculate Count  */
count=9-strlen(s);

/* Print asterisks */
for(int i=0;i<count;i++)
printf("*");

/* Print Amount */
printf("%d",amt);
于 2012-04-27T04:50:32.833 回答