Welcome to the StairCounter! We calculate your total stair climbing for your Math/CS courses based on how often you go from building to building and from floor to floor. At the moment it just handles travel between buildings 210 (2nd floor), 315 (floors 1 and 2), and 460 (3rd floor). How many times did you travel from building 210 to the ground floor of building 315? 4 Within building 315, how many times did you travel from floor 1 up to floor 2? 2 How many times did you travel from the upper floor of building 315 to the third floor of building 460? 3 Based on the information you provided you climbed 578 total stairs, or roughly the equivalent of 41 flights of stairs Thanks for using StairCounter! |
// #include the libraries we need
// declare constants for the stair counts for each route
int main()
{
// declare variables for the number of times each trip is made
// a variable for the total calculated stair count
// a variable for the total calculated number of flights
// prompt (cout) the user for the number of times they traveled 210-315
// read (cin) their response
// prompt the user for the number of times they traveled 315 floor one to floor two
// read (cin) their response
// prompt the user for the number of times they traveled 315-460
// read (cin) their response
// calculate the sum of the total distances and store in the final result variable
// (# times each trip was made * the stair count for that route)
// calculate how many flights of stairs this represents
// (the total number of stairs / our constant for stairs per flight)
// display (cout) the final results
}
|
void displayResults(int stairCount, int numFlights)
{
std::cout << "Based on the information you provided, you climbed " << stairCount;
std::cout << " total stairs" << std::endl;
std::cout << "or roughly the equivalent of " << numFlights;
std::cout << " flights of stairs" << std::endl << std::endl;
std::cout << "Thanks for using Stair Counter!" << std::endl << std::endl;
}
int calcFlights(int stairCount)
{
int flights;
flights = stairCount / StairsPerFlight;
return flights;
}
(assuming our constant up top for the number of stairs in a flight had been
declared using the name StairsPerFlight)
#include <iostream>
// constants for the buildings handled
const int B210 = 210;
const int B315 = 315;
const int B460 = 460;
// counts of the number of stairs from building to building
const int Stairs_210_315 = 75;
const int Stairs_315_460 = 60;
// counts of the number of stairs from floor to floor
const int Stairs_315_F1_F2 = 16;
const int FlightStairs = 14;
// displays the welcome message/instru tion
void displayIntro();
// displays the final results: both the total number of stairs
// and an approximation of the number of floors of stairs
void displayTotals(int stairCount);
// asks the user how often they go up from one floor to another within a specific building,
// then computes and returns how many total stairs that involved
// (oneTrip is the number of stairs between them for a single trip)
int betweenFloors(int bldg, int lowerFl, int upperFlr, int oneTrip);
// asks the user how often they go up from one specific building to another,
// then computes and returns how many total stairs that involved
// (oneTrip is the number of stairs between them for a single trip)
int betweenBuildings(int lowerBld, int upperBld, int oneTrip);
int main()
{
displayIntro();
int totalCount = 0;
totalCount += betweenBuildings(B210, B315, Stairs_210_315);
totalCount += betweenFloors(B315, 1, 2, Stairs_315_F1_F2);
totalCount += betweenBuildings(B315, B460, Stairs_315_460);
displayTotals(totalCount);
}
void displayIntro()
{
std::cout << std::endl;
std::cout << "Welcome to the StairCounter!" << std::endl;
std::cout << std::endl;
std::cout << "We calculate your total stair climbing for your Math/CS courses based on ";
std::cout << "how often you go from building to building";
std::cout << " and from floor to floor." << std::endl;
std::cout << std::endl;
std::cout << "(At the moment it just handles buildings 210, 315, and 460.)" << std::endl;
std::cout << std::endl;
}
void displayTotals(int stairCount)
{
std::cout << "Based on the information you provided you climbed ";
std::cout << stairCount << " total stairs," << std::endl << "or roughly the equivalent of ";
std::cout << (stairCount/FlightStairs) << " flights of stairs" << std::endl;
std::cout << "Thanks for using StairCounter!" << std::endl << std::endl;
}
int betweenBuildings(int lowerBld, int upperBld, int oneTrip)
{
std::cout << "How often did you travel from building " << lowerBld;
std::cout << " to building " << upperBld << "?" << std::endl;
int trips;
std::cin >> trips;
return (trips*oneTrip);
}
int betweenFloors(int bldg, int lowerFl, int upperFl, int oneTrip)
{
std::cout << "Within building " << bldg <<", how often did you travel from floor ";
std::cout << lowerFl << " up to floor " << upperFl << "?" << std::endl;
int trips;
std::cin >> trips;
return (trips*oneTrip);
}
|
// welcome() gives the user an introduction to our program
void welcome();
// getCName() prompts the user to enter a container name, reads and returns it
string getCName();
// getCSize(containerName) prompts the user to enter the size of the specified
// container type in litres, then reads and returns the value
float getCSize(string containerName);
// displayFit(containerName, containerSize)
// for the named container and its size, calculates and displays
// the range of how many marbles, ping pong balls, and tennis balls
// will fit in the container with the results columnized as shown
// below (1 digit after the decimal point, width 6 for the column)
// example for displayFit("carton", 1.5):
// A carton of size 1.5 litres holds
// 105.3 to 128.7 small marbles
// 27.7 to 33.8 ping pong balls
// 5.0 to 6.1 tennis balls
void displayFit(string containerName, float containerSize);
int main()
{
// set up variable storage for the name and size of the container
// call welcome to display overall program instructions
// use getCName and getCSize to get the container name and size,
// storing our declared variables
// pass displayFit the container name and size
// (it will compute and display how many of each item fit in the container)
}
|