Question

19. Check Writer Write a program that displays a simulated paycheck. The program should ask the user to enter the date, the p

this is for c++ please and thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>

using namespace std;

void display(string date,string name,double amount)
{
   if(amount<0 || amount>10000){ //Ignoring negative values and above 10000
       return;
   }
   //printing values
   cout<<"Date: "<<date<<endl;
   cout<<"Pay to the order of: "<<name<<endl;
   cout<<"$"<<amount<<endl;
   //to get the decimal(cent) value and integer part separately
   int value=amount;
   double decimal=amount-value;
   int cent=ceil(decimal*100);
   string cents=""+cent;
   //convert the value to string to access each integer
   char *num;
   itoa(value,num,10);
int len = strlen(num);
//To print the ones digit value
char *single_digits[] = { "zero", "one", "two", "three", "four","five", "six", "seven", "eight", "nine"};
  
   //To print tens value, to get the values we are putting starting index empty.
char *two_digits[] = {"", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
  
  
char *tens_multiple[] = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  
char *tens_power[] = {"hundred", "thousand"};

  
    //if only single value then simply display it.
if (len == 1) {
cout<<single_digits[num[0] - '0']<<" and "<<cents<<" cents"<<endl;
return;
}
  
  
/* Iterate while num is not '\0' */
while (*num != '\0') {
  
/* Code path for first 2 digits */
if (len >= 3) {
if (*num -'0' != 0) {
   cout<<single_digits[*num-'0']<<" ";
   cout<<tens_power[len-3]<<" "; // here len can be 3 or 4
}
--len;
}
  
/* Code path for last 2 digits */
else {
/* Need to explicitly handle 10-19. Sum of the two digits is
used as index of "two_digits" array of strings */
if (*num == '1') {
int sum = *num - '0' + *(num + 1)- '0';
cout<<two_digits[sum]<<" ";
break;
}
  
/* Need to explicitely handle 20 */
else if (*num == '2' && *(num + 1) == '0') {
   cout<<"twenty ";
break;
}
  
/* Rest of the two digit numbers i.e., 21 to 99 */
else {
int i = *num - '0';
               cout<<(i? tens_multiple[i]: "")<<" ";
++num;
if (*num != '0')
   cout<<single_digits[*num-'0']<<" ";
}
}
++num;
}
cout<<"and "<<cent<<" cents"<<endl;
}

Input:

24/10/2019

jhonny

1920.85

12/01/2000

John

1900

14/12/2018

Philips

9832.67

Output:

Date: 24/10/2019
Pay to the order of: shanmukha
$1920.85
one thousand nine hundred twenty and 85 cents


Date: 12/01/2000
Pay to the order of: John
$1900
one thousand nine hundred and 0 cents


Date: 14/12/2018
Pay to the order of: Philips
$9832.67
nine thousand eight hundred thirty two and 68 cents

Add a comment
Know the answer?
Add Answer to:
this is for c++ please and thank you! 19. Check Writer Write a program that displays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write it in a c++ language Extra 11 - Pay to the Order Of.. (Due 5/29) A check writer.program. Write a program that...

    write it in a c++ language Extra 11 - Pay to the Order Of.. (Due 5/29) A check writer.program. Write a program that displays a simulated check. The program should ask the user for the date, payee's name and the amount of the check. It should then display a simulated check with the dollar amount spelled out as follows: Date: 05/31/2016 $2,567.97 Pay to the order of Donald Trump Two Thousand five hundred sixty-seven dollars and ninety-seven cents F8 F7...

  • Must be written in C++ Bank Charges A bank charges $15 per month plus the following...

    Must be written in C++ Bank Charges A bank charges $15 per month plus the following check fees for a commercial checking account: $0.10 per check each for fewer than 20 checks (1-19) $0.08 each for 20–39 checks $0.06 each for 40–59 checks $0.04 each for 60 or more checks Write a program that asks for the number of checks written during the past month, then computes and displays the bank’s fees for the month. Input Validation: Display an error...

  • In this assignment, you must write a C program to check the validity of a Sudoku solution. You must at least do the foll...

    In this assignment, you must write a C program to check the validity of a Sudoku solution. You must at least do the following: 1- Ask the user to provide a minimum of first two rows of the Sudoku grid. For the rest of the entries, you should use a random number generator. 2- Use appropriate logic to make sure the random number generator generates a distinct set of valid integers! 3- It should be a console-based, yet convenient and...

  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • The XYZ Company needs you to write a program that will allow them to enter the...

    The XYZ Company needs you to write a program that will allow them to enter the weekly sales for a salesperson and then the program will calculate things such as most sales (and what day on which they happened), least sales (and day on which they happened), total sales, and daily average. The program will need to do the following: • Validate the user input to ensure that it is not less than 0.0 (0.0 will be acceptable if there...

  • C++ please help thank you so much the results Prog ram Overview: This program will calculate...

    C++ please help thank you so much the results Prog ram Overview: This program will calculate and output ordering products from a vendor. This will include calculating the price for each item ordered, adding sales tax, and outputting the results in a nicely formatted table. Relevant Details and Formulas: Fireworks for sale: $12.99 Red Dragons Blue Chrysanthemums $14.99 Vermilion Lotuses $19.49 el14414, Yo Sparkler Boxes $4.25S s S 21 25 $11144 Sales Tax: 8.1% applied to all purchases Subtotal =...

  • Must be written in C++ Bank Charges A bank charges $15 per month plus the following...

    Must be written in C++ Bank Charges A bank charges $15 per month plus the following check fees for a commercial checking account: $0.10 per check each for fewer than 20 checks (1-19) $0.08 each for 20–39 checks $0.06 each for 40–59 checks $0.04 each for 60 or more checks Write a program that asks for the number of checks written during the past month, then computes and displays the bank’s fees for the month. Input Validation: Display an error...

  • Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity...

    Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity to practice functions, functions that call other functions, reference variables, logical statements (what is meant by logical statement is a statement such as if, if/else if, switch), and input validation, HW7 (Graded out of 100) A talent competition has 5 judges, each of whom awards a score between 0 and 10 for each performer. Fractional scores, such as 8.3, are allowed. A performer's final...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following...

    ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following two problems. Upload your source code files to Canvas. The file names must be of the form coins_your_name.cpp and bonus_your_name.cpp for problems 1 and 2, respectively. Substitute your first and last name for "your_name" in the file name. Problem Statements 1. Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT