Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

(Writing the Word Equivalent of a Check Amount) Continuing the discussion of the previous example, we reiterate the importance of designing checkwriting systems to prevent alteration of check amounts. One common security method requires that the check amount be both written in numbers and "spelled out" in words. Even if someone is able to alter the numerical amount of the check, it is extremely difficult to change the amount in words. Write a program that inputs a numeric check amount and writes the word equivalent of the amount. Your program should be able to handle check amounts as large as $99.99. For example, the amount 112.43 should be written as ONE HUNDRED TWELVE and 43/100

Short Answer

Expert verified
Convert the check amount into word equivalent and cents as a fraction of 100.

Step by step solution

01

Understand the Problem

The task is to convert a numeric check amount (up to $99.99) into its equivalent word form. The major part of the amount (before the decimal) should be written in words, while the decimal part should be expressed as a fraction of a hundred.
02

Identify Number Ranges

The program needs to handle two significant parts: numbers from 0 to 99 before the decimal and two-digit numbers after the decimal (cents). Specific terms like 'HUNDRED', and numbers 1 to 19, and multiples of ten (20, 30, ..., 90) need to be mapped to their word equivalents.
03

Create Number Conversions

For numbers 1 to 19, associate each with its word equivalent (e.g., 1 - 'ONE', 2 - 'TWO'). Similarly, for tens (20, 30, ..., 90), create a list that includes these in word form (e.g., 20 - 'TWENTY'). This will include the basic building blocks for larger numbers.
04

Decompose Numbers into Words

For amounts below 100, break down numbers into tens and units to convert into words. For example, '56' should be translated to 'FIFTY SIX' by combining 'FIFTY' (from tens) and 'SIX' (from units).
05

Format the Check Amount

Combine the word equivalent of the integer part of the check amount with the fraction representing cents. For example, if the amount is 43, it should be displayed as 'FORTY THREE and 43/100'.
06

Compose the Full Check Amount in Words

For amounts involving hundreds (e.g., 112), convert and combine word equivalents, adding 'HUNDRED' as needed. Example: '112' becomes 'ONE HUNDRED TWELVE'. Ensure the output includes both parts: 'ONE HUNDRED TWELVE and 43/100'.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

Checkwriting Systems
Checkwriting systems play a crucial role in maintaining the security and integrity of financial transactions. This is achieved by utilizing a dual-format system in which check amounts are displayed both numerically and in written words. This method helps prevent any unauthorized changes, as it is quite challenging for someone to alter not only the numbers but also their spelled-out equivalent. This dual-format approach ensures that recipients and banks recognize any discrepancies and can address them promptly. The blending of numerical and written forms acts as a deterrent against potential fraud, offering more peace of mind to both the issuer and receiver.
Number to Words Conversion
Number to words conversion is a fundamental task within checkwriting systems. It involves transforming a numerical value into a corresponding set of words, which is essential for visually confirming the intended amount. This process is highly beneficial as it adds an additional layer of verification.
To effectively convert numbers into words, one must consider:
  • Numbers from 1 to 19, each having unique word equivalents like 'ONE', 'TWO', etc.
  • Multiples of ten such as 'TWENTY', 'THIRTY', etc., up to 'NINETY'.
  • The use of 'HUNDRED' for hundreds places to articulate larger numbers.
Combine these elements logically to create word representations. For instance, the number 56 translates into 'FIFTY SIX' by combining 'FIFTY' and 'SIX'. This conversion is also applied to amounts involving decimals, displaying them as a fraction of a hundred, such as '43/100'.
C++ Programming
In C++ programming, implementing the conversion of numbers to words involves utilizing arrays or switch-case statements to map numbers to their corresponding words. C++ is particularly well-suited for this task due to its robust handling of arrays and logical flow control.
C++ provides the tools needed to:
  • Decompose a number into its constituent parts: hundreds, tens, and units.
  • Iterate through these parts using loops, ensuring each part is translated correctly.
  • Convert and print each numerical segment sequentially, followed by formatting the decimal as a fraction of 100.
By handling these manipulations effectively, a C++ program can accurately translate figures like 112.43 into 'ONE HUNDRED TWELVE and 43/100', preserving the integrity of the checkwriting system.
Algorithm Design
Designing an algorithm to convert numbers to words requires a structured approach. A successful algorithm efficiently breaks down a numerical value into understandable segments and converts each segment into its word equivalent.
Essential steps in the algorithm design include:
  • Identifying the number range, ensuring that the algorithm can handle both the units and tens effectively.
  • Mapping individual numbers to words through data structures such as arrays or dictionaries, which store known values for easy access.
  • Incorporating logical structures—like loops and conditional statements—to manage different numerical scenarios, especially those involving numbers in the tens and hundreds brackets.
With this thought-out methodology, the algorithm ensures reliable and repeatable conversions from numbers like 112 into word forms such as 'ONE HUNDRED TWELVE'. This approach not only reinforces the security in financial processes but also enhances the user experience by providing clarity and consistency.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Write a program that uses function strcmp to compare two strings input by the user. The program should state whether the first string is less than, equal to or greater than the second string

(Check Protection) Computers are frequently employed in check-writing systems such as payroll and accounts-payable applications. Many strange stories circulate regarding weekly paychecks being printed (by mistake) for amounts in excess of \(1 million. Weird amounts are printed by computerized check-writing systems, because of human error or machine failure. Systems designers build controls into their systems to prevent such erroneous checks from being issued. Another serious problem is the intentional alteration of a check amount by someone who intends to cash a check 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 that a paycheck contains eight blank spaces in which the computer is supposed to print the amount of a weekly paycheck. If the amount is large, then all eight of those spaces will be filled, for example, 12345678 (position numbers) On the other hand, if the amount is less than \)1000, then several of the spaces would ordinarily be left blank. For example, 99.87 \-------- 12345678 contains three 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 \-------- 12345678 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.

Perform the task specified by each of the following statements: a. Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value. b. Write the function prototype for the function in part (a). c. Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer. d. Write the function prototype for the function in part (c). e. Write two statements that each initialize character array vowel with the string of vowels, "AEIOU".

(Quicksort) You have previously seen the sorting techniques of the bucket sort and selection sort. We now present the recursive sorting technique called Quicksort. The basic algorithm for a single-subscripted array of values is as follows: a. Partitioning Step: Take the first element of the unsorted array and determine its final location in the sorted array (i.e., all values to the left of the element in the array are less than the element, and all values to the right of the element in the array are greater than the element). We now have one element in its proper location and two unsorted subarrays. b. Recursive Step: Perform Step 1 on each unsorted subarray. Each time Step 1 is performed on a subarray, another element is placed in its final location of the sorted array, and two unsorted subarrays are created. When a subarray consists of one element, that subarray must be sorted; therefore, that element is in its final location. The basic algorithm seems simple enough, but how do we determine the final position of the first element of each subarray? As an example, consider the following set of values (the element in bold is the partitioning elementit will be placed in its final location in the sorted array): 37 2 6 4 89 8 10 12 68 45 a. Starting from the rightmost element of the array, compare each element with 37 until an element less than 37 is found. Then swap 37 and that element. The first element less than 37 is 12, so 37 and 12 are swapped. The values now reside in the array as follows: 12 2 6 4 89 8 10 37 68 45 Starting from the left of the array, but beginning with the element after 12, compare each element with 37 until an element greater than 37 is found. Then swap 37 and that element. The first element greater than 37 is 89, so 37 and 89 are swapped. The values now reside in the array as follows: 12 2 6 4 37 8 10 89 68 45 Starting from the right, but beginning with the element before 89, compare each element with 37 until an element less than 37 is found. Then swap 37 and that element. The first element less than 37 is 10, so 37 and 10 are swapped. The values now reside in the array as follows: 12 2 6 4 10 8 37 89 68 45 Starting from the left, but beginning with the element after 10, compare each element with 37 until an element greater than 37 is found. Then swap 37 and that element. There are no more elements greater than 37, so when we compare 37 with itself, we know that 37 has been placed in its final location of the sorted array. Once the partition has been applied to the array, there are two unsorted subarrays. The subarray with values less than 37 contains 12, 2, 6, 4, 10 and 8. The subarray with values greater than 37 contains 89, 68 and 45. The sort continues with both subarrays being partitioned in the same manner as the original array. Based on the preceding discussion, write recursive function quickSort to sort a single subscripted integer array. The function should receive as arguments an integer array, a starting subscript and an ending subscript. Function partition should be called by quickSort to perform the partitioning step

State whether the following are true or false. If false, explain why. a. Two pointers that point to different arrays cannot be compared meaningfully. b. Because the name of an array is a pointer to the first element of the array, array names can be manipulated in precisely the same manner as pointers.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free