Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ===================================================================
- Author:
- Title:
- Date: 5/11/19
- Description: Program which calculates total carbon footprint based on
- values inputed by user
- ===================================================================
- */
- #include <iostream>
- #include <iomanip>
- #include "carbonFootprint.hpp"
- using namespace std;
- //declaring functions.
- double transportationFootprint(double KmPerDay, double efficiency);
- double electricityFootprint(double kWhPerMonth, int numPeople);
- double foodFootprint(double meat, double dairy, double fv, double carb);
- double totalFootprint(double trans, double elec, double food);
- int main() {
- std::cout << std::fixed;
- std::cout << std::setprecision(2);
- //declaring varables for transportationFootprint
- double KmPerDay, efficiency;
- //declaring variables for foodFootprint
- double kWhPerMonth;
- int numPeople;
- //declaring variables for calculating foodFootprint
- double meat, dairy, fv, carb;
- //declaring variables for values of footprint of each type and total footprint
- double trans, elec, food, total;
- //Transportation footprint
- cout << "How many km do you drive in one day? ";
- cin >> KmPerDay;
- cout << "Choose the appropriate fuel efficiency for your car: \n";
- cout << "\tvery small car: 7.1 km/L\n";
- cout << "\tsmall car: 8.2 km/L\n";
- cout << "\tsports car: 14.9 km/L\n";
- cout << "\tSUV: 12.3 km/L\n";
- cout << "Or, if you know the efficiency rating, choose another number: ";
- cin >> efficiency;
- trans = transportationFootprint(KmPerDay,efficiency);
- cout <<"Your Carbon footprint with respect to car use is " << trans <<"kg/year.\n";
- //Electricity footprint
- cout <<"What is the average electricity consumption per month, in kilowatts? ";
- cin >> kWhPerMonth;
- cout <<"How many people live in the house: ";
- cin >> numPeople;
- elec = electricityFootprint(kWhPerMonth, numPeople);
- cout <<"Your carbon footprint with respect to electricity use is " << elec <<" kg/year.\n";
- //Food footprint
- cout <<"Of all the food you eat, what percent consists of meat or fish? ";
- cin >> meat;
- cout <<"Of all the food you eat, what percent consists of dairy products? ";
- cin >> dairy;
- cout <<"Of all the food you eat, what percent consists of fruit or vegetables? ";
- cin >> fv;
- cout <<"Of all the food you eat, what percent consists of carbohydrates? ";
- cin >> carb;
- food = foodFootprint(meat, dairy, fv, carb);
- cout <<"Your carbon footprint with respect to food consumption is " << food <<" kg/year\n" << endl;
- //Total footprint
- total = totalFootprint(trans, elec, food);
- cout <<"You produce an annual total of " << total << " metric tons of CO2 per year";
- return 0;
- }
- double transportationFootprint(double KmPerDay, double efficiency){
- double kgCO2;
- double LitersPerYear = 365 * (KmPerDay / efficiency);
- kgCO2 = 2.3 * LitersPerYear;
- return kgCO2;
- }
- double electricityFootprint(double kWhPerMonth, int numPeople){
- double kgCO2;
- kgCO2 = (kWhPerMonth * 12 * 0.257) / numPeople;
- return kgCO2;
- }
- double foodFootprint(double meat, double dairy, double fv, double carb) {
- double kgCO2;
- kgCO2 = ((meat/100) * 53.1) + ((dairy/100) * 13.8) + ((fv/100) * 7.6) + ((carb/100) * 3.1);
- return kgCO2;
- }
- double totalFootprint(double trans, double elec, double food) {
- double kgCO2;
- kgCO2 = (trans + elec + food)/1000;
- return kgCO2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement