// Name: Convenience store owner
// Version: 1.0
// Purpose: Convert the price of an item in U.S. pennies per pound to
// Canadian dollars per kilogram.
#include <iostream.h>
//------------------------ calculator object ------------------------------
void main()
{
double theOutput; // Answer displayed to the user
double dollarsPerKg; // Item's cost in Canadian dollars per kilogram
int theInput; // Input entered by the user
int penniesPerLb; // Price in U.S. pennies per pound of an item
//-------------------- input object ---------------------------------------
// Get the input.
cin >> theInput;
//------------------- end of input object --------------------------------
penniesPerLb = theInput;
//-------------------- computing object -----------------------------------
const double kgPerLb = .4536; // Number of kilograms in a pound
const double dollarsCanPerUS = 1.26; // Number of Canadian dollars per
// U.S. dollar (exchange rate)
const int penniesPerDollar = 100; // Number of pennies per U.S. dollar
dollarsPerKg = penniesPerLb/kgPerLb * dollarsCanPerUS/penniesPerDollar;
//-------------------- end of computing object ---------------------------
theOutput = dollarsPerKg;
//-------------------- output object --------------------------------------
// Display the answer.
cout << theOutput << endl;
//------------------- end of output object --------------------------------
}
//---------------------- end of calculator object -------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#include <iostream.h>
//------------------------ teller object ----------------------------------
void main()
{
int countOfTwenties; // Count of $20Us to be returned
int countOfTens; // Count of $10Us to be returned
int countOfFives; // Count of $5Us to be returned
int countOfOnes; // Count of $1Us to be returned
int countOfQuarters; // Count of quarters to be returned
int countOfDimes; // Count of dimes to be returned
int countOfNickels; // Count of nickels to be returned
int countOfPennies; // Count of pennies to be returned
int theAmount; // Amount to be changed
//-------------------- input object ---------------------------------------
// Get the amount from the user.
cin >> theAmount;
//----------------- end of input object -----------------------------------
//-------------------- computing object -----------------------------------
//-------------------- cash drawer object ---------------------------------
const int twentyValue = 2000; // Number of pennies in $20
const int tenValue = 1000; // Number of pennies in $10
const int fiveValue = 500; // Number of pennies in $5
const int oneValue = 100; // Number of pennies in $1
const int quarterValue = 25; // Number of pennies in a quarter
const int dimeValue = 10; // Number of pennies in a dime
const int nickelValue = 5; // Number of pennies in a nickel
const int pennyValue = 1; // Number of pennies in a penny
const char twentyName[] = "twenties"; // Label for $20 bills
const char tenName[] = "tens"; // Label for $10 bills
const char fiveName[] = "fives"; // Label for $5 bills
const char oneName[] = "ones"; // Label for $1 bills
const char quarterName[] = "quarters"; // Label for quarter coins
const char dimeName[] = "dimes"; // Label for dime coins
const char nickelName[] = "nickels"; // Label for nickel coins
const char pennyName[] = "pennies"; // Label for penny coins
//----------------- end of cash drawer object -----------------------------
// Determine the amount of each denomination to be returned.
countOfTwenties = theAmount / twentyValue;
theAmount = theAmount % twentyValue;
countOfTens = theAmount / tenValue;
theAmount = theAmount % tenValue;
countOfFives = theAmount / fiveValue;
theAmount = theAmount % fiveValue;
countOfOnes = theAmount / oneValue;
theAmount = theAmount % oneValue;
countOfQuarters = theAmount / quarterValue;
theAmount = theAmount % quarterValue;
countOfDimes = theAmount / dimeValue;
theAmount = theAmount % dimeValue;
countOfNickels = theAmount / nickelValue;
theAmount = theAmount % nickelValue;
countOfPennies = theAmount / pennyValue;
theAmount = theAmount % pennyValue;
//----------------- end of computing object -------------------------------
//-------------------- output object --------------------------------------
// Display the results.
cout << countOfTwenties << " " << twentyName << endl;
cout << countOfTens << " " << tenName << endl;
cout << countOfFives << " " << fiveName << endl;
cout << countOfOnes << " " << oneName << endl;
cout << countOfQuarters << " " << quarterName << endl;
cout << countOfDimes << " " << dimeName << endl;
cout << countOfNickels << " " << nickelName << endl;
cout << countOfPennies << " " << pennyName << endl;
//----------------- end of output object ----------------------------------
}
//---------------------- end of teller object -----------------------------
Last Updated on 02/04/03