// Programmer: Dylan McDonald // Class & Section: CS 54, Section // Date: February 13, 2007 // Purpose: To fire up Da Vinci's time machine (learn functions & references) #include using namespace std; /* constants */ const double LITERSPERGILL = 0.1421; const double KILOSPERSTONE = 6.35; const double CHAINSPERMETER = 20.1168; const double KILOMETERSPERMETER = 0.001; const double SECONDSPERHOUR = 3600.0; const double MAXTANVELOCITY = 2.5; const double MAXTIMESPACEVELOCITY = 100.0; /* Part I function - by value */ /* takes the number of gills, converts it, and returns the number of liters */ double gillsToLiters(double gills) { double liters; liters = LITERSPERGILL * gills; return liters; } /* Part I function - by reference */ /* takes the number of gills, converts it, and updates the conversion value */ void gillsToLitersRef(double &conversionValue) { conversionValue = LITERSPERGILL * conversionValue; } /* Part II function - by value */ /* takes the number of stones, converts it, and returns the number of kilos */ double stonesToKilos(double stones) { double kilos; kilos = KILOSPERSTONE * stones; return kilos; } /* Part II function - by reference */ /* takes the number of stones, converts it, and updates the conversion value */ void stonesToKilosRef(double &conversionValue) { conversionValue = KILOSPERSTONE * conversionValue; } /* Part III function - tangential velocity */ /* takes the number of chains / s, converts it, and returns km / h */ double chainsToKilometers(double chains) { double kilometers; /* convert to m / s */ kilometers = chains * CHAINSPERMETER; /* now we go to m / hr */ kilometers = kilometers * SECONDSPERHOUR; /* and to km / h */ kilometers = kilometers * KILOMETERSPERMETER; return kilometers; } /* Part III - time/space velocity */ /* takes chains / s, finds the remaning potential, and returns the velocity */ double timeSpaceVelocity(double tanVelocity) { double timeSpace; /* find the remaining potential */ timeSpace = (MAXTANVELOCITY - tanVelocity) / MAXTANVELOCITY; /* now find our time/space velocity */ timeSpace = timeSpace * MAXTIMESPACEVELOCITY; return timeSpace; } /* our main function :) */ int main() { double chains, gills, stones; double liters, kilograms, kilometers, timeSpace; /* Part I - ask for gills */ cout << "How many gills of wine do we have? "; cin >> gills; /* Part I - convert gills to liters */ liters = gillsToLiters(gills); gillsToLitersRef(gills); cout << "So, we have " << liters << " L." << endl; cout << "By reference, we get " << gills << " L." << endl; /* Part II - ask for stones */ cout << "How many stones of cheese do we have? "; cin >> stones; /* Part II - convert stones to kilograms */ kilograms = stonesToKilos(stones); stonesToKilosRef(stones); cout << "So, we have " << kilograms << " kg." << endl; cout << "By reference, we get " << stones << " kg." << endl; /* Part III - ask for chains / s */ cout << "What is our velocity (in chains / s)? "; cin >> chains; /* Part III - calculate using chains / s */ kilometers = chainsToKilometers(chains); timeSpace = timeSpaceVelocity(chains); cout << "At " << chains << " chains / s, we are going " << kilometers << " km / h." << endl; cout << "This implies we are travelling across the time-space " << "continuum at a rate of " << timeSpace << " yr / s." << endl << endl << "Now all we need is a flux capacitor!" << endl; return 0; }