#include using namespace std; // Author: Chikashi KIMURA // Date: 09/Jul/03 // Course: CompSci 6 // Section: // Purpose: To practice using functions with parameters and // to practice using the input operator, cin. void addTime (int min1, int sec1, int min2, int sec2) // pre: min1 and min2 are integers between 0 and 59, inclusive // sec1 and sec2 are integers between 0 and 59, inclusive // ost: the sum of the times is printed to the screen { int secSum, minSum, hrSum; int addsec, addmin; addsec = sec1 + sec2; addmin = min1 + min2; secSum = (addsec) % 60; minSum = (addmin + (addsec) / 60) % 60; hrSum = (addmin + (addsec) / 60) / 60; cout << "The sum of the times is " << hrSum << ":" << minSum << ":" << secSum << endl; } void addDistance (int feet1, int inches1, int feet2, int inches2) { int inchesSum, feetSum, milesSum; int addInches, addFeet; addInches = inches1 + inches2; addFeet = feet1 + feet2; inchesSum = (addInches) % 12; feetSum = (addFeet + (addInches / 12)) % 5729; milesSum = (addFeet + (addInches) / 12) / 5729; cout << "The sum of the distance is " << milesSum << "miles and " << feetSum << "feet and " << inchesSum << "inches " << endl; } void addMoney (int shillings1, int pence1, int shillings2, int pence2) { int penceSum, shillingsSum, poundsSum; int addPence, addShillings; addPence = pence1 + pence2; addShillings = shillings1 + shillings2; penceSum = (addPence) % 12; shillingsSum = (addShillings + (addPence / 12)) % 20; poundsSum = (addShillings + (addPence) / 12) / 20; cout << "The sum of the distance is " << poundsSum << "pounds and " << shillingsSum << "shillings and " << penceSum << "pence " << endl; } void testAddTime () { cout << endl << endl; cout << "empty case (0min0sec + 0min0sec)" << endl; addTime(0, 0, 0, 0); cout << "The sum of the times *should be* 0:0:0" << endl; cout << endl; cout << "standard case (30min50sec + 25min20sec)" << endl; addTime(30, 50, 25, 20); cout << "The sum of the times *should be* 0:56:10" << endl; cout << endl; cout << "overflow case" << endl; addTime(30, 50, 45, 20); cout << "The sum of the times *should be* 1:16:10" << endl; cout << endl; cout << "boundary case" << endl; addTime(30, 50, 29, 10); cout << "The sum of the times *should be* 1:0:0" << endl; cout << endl; cout << "standard case" << endl; addTime(0, 30, 0, 6); cout << "The sum of the times *should be* 0:0:36" << endl; cout << endl; cout << "overflow case" << endl; addTime(0, 30, 0, 36); cout << "The sum of the times *should be* 0:1:6" << endl; cout << endl; cout << "boundary case" << endl; addTime(0, 50, 0, 10); cout << "The sum of the times *should be* 0:1:0" << endl; cout << endl; } void testAddDistance() { cout << "empty case (0feet0inch + 0feet0inch)" << endl; addDistance(0, 0, 0, 0); cout << "The sum of the times *should be* 0mile and 0feet and 0inch" << endl; cout << endl; cout << "standard case (5feet6inch + 14feet10inch)" << endl; addDistance(5, 6, 14, 10); cout << "The sum of the times *should be* 0mile and 20feet and 4inch" << endl; cout << endl; cout << "overflow case (3000feet10inch + 6000feet11inch)" << endl; addDistance(3000, 10, 6000, 11); cout << "The sum of the times *should be* 1mile and 3722feet and 9inch" << endl; cout << endl; cout << "boundary case (1486feet10inch + 3792feet2inch)" << endl; addDistance(1486, 10, 3792, 2); cout << "The sum of the times *should be* 1mile and 0feet and 0inch" << endl; cout << endl; } void testAddMoney() { cout << "empty case (0shillings0pence + 0shillings0pence)" << endl; addMoney(0, 0, 0, 0); cout << "The sum of the times *should be* 0pound and 0shillings and 0pence" << endl; cout << endl; cout << "standard case (4shillings5pence + 3shillings2pence)" << endl; addMoney(4, 5, 3, 2); cout << "The sum of the times *should be* 0pound and 7shillings and 7pence" << endl; cout << endl; cout << "overflow case (13shillings10pence + 19shillings9pence)" << endl; addMoney(13, 10, 19, 9); cout << "The sum of the times *should be* 1pound and 13shillings and 7pence" << endl; cout << endl; cout << "boundary case (10shillings10pence + 9shillings2pence)" << endl; addMoney(10, 10, 9, 2); cout << "The sum of the times *should be* 1pound and 0shillings and 0pence" << endl; cout << endl; } int main () { int minutes1, seconds1; int minutes2, seconds2; int feet1, inches1; int feet2, inches2; int shillings1, pence1; int shillings2, pence2; cout << "Enter first time [minutes seconds]: "; cin >> minutes1 >> seconds1; cout << "Enter second time [minutes seconds]: "; cin >> minutes2 >> seconds2; cout << "Enter first distance [feet inches]: "; cin >> feet1 >> inches1; cout << "Enter second distance [feet inches]: "; cin >> feet2 >> inches2; cout << "Enter first money [shillings pence]: "; cin >> shillings1 >> pence1; cout << "Enter second money [shillings pence]: "; cin >> shillings2 >> pence2; addTime(minutes1, seconds1, minutes2, seconds2); addDistance(feet1, inches1, feet2, inches2); addMoney(shillings1, pence1, shillings2, pence2); testAddTime(); testAddDistance(); testAddMoney(); return 0; }