Docsity

Computer Science 121 - Quiz5, Quizzes of Computer Science

Toggle sidebar
bg1
CptS 121 – Program Design and Development
Date Assigned: Mon, Oct 6, 2025 Due Date: Fri, Oct 10, 2025
Take Home: Quiz 5 (15 pts) – Pointers/Output Parameters
Using Canvas https://canvas.wsu.edu/, please submit your solution to the
correct quiz folder. Your solution should be a .pdf file with the name <your
last name>_quiz5.pdf and uploaded. To upload your solution, please
navigate to your correct Canvas
lab
course space. Select the “Assignments”
link in the main left menu bar. Navigate to the correct quiz submission folder.
Click the “Start Assignment” button. Click the “Upload File” button. Choose
the appropriate .pdf file with your solution. Finally, click the “Submit
Assignment” button.
NOTE: The use of gen AI is forbidden for quizzes.
1. (11 pts) Write a function dispense_bills(). The function determines the
minimum
number of bills to dispense given a
withdrawal
amount. The possible
bills dispensed include: 100’s, 50’s, 20’s, and 10’s. The number of each bill to
dispense should be stored indirectly through the pointers: hundreds_ptr,
fifties_ptr, twenties_ptr, and tens_ptr. If the withdrawal_amount exceeds the
balance, then the number of each bill to dispense should be set to 0, and 0
should be returned. If the withdrawal_amount is less than or equal to the
balance, then the number of each bill to dispense should be calculated, and 1
should be returned. The function header has been provided for you.
// precondition: withdrawal amount must be a multiple of 10
// return: 1 if the balance >= withdrawal_amount; 0 otherwise
int dispense_bills(double balance, double withdrawal_amount,
int *hundreds_ptr, int *fifties_ptr, int
*twenties_ptr, int *tens_ptr)
{
if (withdrawal_amount > balance) {
*hundreds_ptr = 0;
*fifties_ptr = 0;
*twenties_ptr = 0;
*tens_ptr = 0;
return 0;
}
int amount = (int)withdrawal_amount;
*hundreds_ptr = amount / 100;
amount %= 100;
*fifties_ptr = amount / 50;
amount %= 50;
*twenties_ptr = amount / 20;
amount %= 20;
*tens_ptr = amount / 10;
return 1;
}
Instructor: Andrew S. O’Fallon
pf2

Partial preview of the text

Download Computer Science 121 - Quiz5 and more Quizzes Computer Science in PDF only on Docsity!

CptS 121 – Program Design and Development

Date Assigned: Mon, Oct 6, 2025 Due Date: Fri, Oct 10, 2025

Take Home: Quiz 5 (15 pts) – Pointers/Output Parameters Using Canvas https://canvas.wsu.edu/, please submit your solution to the correct quiz folder. Your solution should be a .pdf file with the name _quiz5.pdf and uploaded. To upload your solution, please

navigate to your correct Canvas lab course space. Select the “Assignments”

link in the main left menu bar. Navigate to the correct quiz submission folder. Click the “Start Assignment” button. Click the “Upload File” button. Choose the appropriate .pdf file with your solution. Finally, click the “Submit Assignment” button. NOTE: The use of gen AI is forbidden for quizzes.

  1. (11 pts) Write a function dispense_bills(). The function determines the

minimum number of bills to dispense given a withdrawal amount. The possible

bills dispensed include: 100’s, 50’s, 20’s, and 10’s. The number of each bill to dispense should be stored indirectly through the pointers: hundreds_ptr, fifties_ptr, twenties_ptr, and tens_ptr. If the withdrawal_amount exceeds the balance, then the number of each bill to dispense should be set to 0, and 0 should be returned. If the withdrawal_amount is less than or equal to the balance, then the number of each bill to dispense should be calculated, and 1 should be returned. The function header has been provided for you. // precondition: withdrawal amount must be a multiple of 10 // return: 1 if the balance >= withdrawal_amount; 0 otherwise int dispense_bills(double balance, double withdrawal_amount, int *hundreds_ptr, int *fifties_ptr, int *twenties_ptr, int *tens_ptr) { if (withdrawal_amount > balance) { *hundreds_ptr = 0; *fifties_ptr = 0; *twenties_ptr = 0; *tens_ptr = 0; return 0; } int amount = (int)withdrawal_amount; *hundreds_ptr = amount / 100; amount %= 100; *fifties_ptr = amount / 50; amount %= 50; *twenties_ptr = amount / 20; amount %= 20; *tens_ptr = amount / 10; return 1; }

Instructor: Andrew S. O’Fallon

CptS 121 – Program Design and Development

Date Assigned: Mon, Oct 6, 2025 Due Date: Fri, Oct 10, 2025

  1. (4 pts) Given the following declarations and statements, write an appropriate function call for the function implemented above. The value returned from the function should be stored in variable result. double balance = 0.0, withdrawal_amount = 0.0; int hundreds = 0, fifties = 0, twenties = 0, tens = 0, result = 0; printf("Enter your bank balance: "); scanf("%lf", &balance); printf("Enter the amount to withdraw in multiples of 10s: "); scanf("%lf", &withdrawal_amount); // write the function call below result = dispense_bills(balance, withdrawal_amount, &hundreds, &fifties, &twenties, &tens);

Instructor: Andrew S. O’Fallon