// comments from sample solution profiles and main
// welcome() gives the user an introduction to our program
// getName(adjective) prompts the user to enter an employee name, reads and returns it
// (the adjective is to for qualifiers like "first", "second", etc)
// getCallsAnswered(empname) prompts the user to enter the number of calls that
// the named employee answered, reads and returns the value
// getCallsUnanswered() prompts the user to enter the number of calls that went unanswered
// calcHours(callsAns, totCalls) takes the number of calls answered and the
// total calls made, then calculates and returns an estimate for the
// number of hours worked that week
// displayResults(emp1name, emp1hours, emp2name, emp2 hours, emp3name, emp3hours, unstaffedhours) -
// this function takes the names and hour estimates for each employee, plus the estimate
// for the unstaffed hours, and displays it all in a nice format
int main()
{
// declare string variables for each of the three employee names
// declare int variables for each of the 3 employee calls-answered,
// plus one for the total calls made and one for the calls-unanswered
// declare float variables for each of the 3 employee hour estimates
// plus one more for the unstaffed estimate
// call welcome function, to display overall program instructions
// get the employee names, calling getName once for each employee, storing the results
// call getCallsAnswered once per employee, storing the results
// obtain the number of calls that were unanswered
// calculate the total calls made
// call calcHours once per employee and once for unanswered, in each case
// passing the number of calls answered and the total calls made,
// and storing the resulting hours estimate for the employee
// call display results, passing all the names and estimates
return 0;
}
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);
}
|