Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. /*
  2. ===================================================================
  3. Author:
  4. Title:
  5. Date: 5/11/19
  6. Description: Program which calculates total carbon footprint based on
  7. values inputed by user
  8. ===================================================================
  9. */
  10.  
  11. #include <iostream>
  12. #include <iomanip>
  13. #include "carbonFootprint.hpp"
  14. using namespace std;
  15.  
  16. //declaring functions.
  17. double transportationFootprint(double KmPerDay, double efficiency);
  18. double electricityFootprint(double kWhPerMonth, int numPeople);
  19. double foodFootprint(double meat, double dairy, double fv, double carb);
  20. double totalFootprint(double trans, double elec, double food);
  21.  
  22. int main() {
  23. std::cout << std::fixed;
  24. std::cout << std::setprecision(2);
  25.  
  26. //declaring varables for transportationFootprint
  27. double KmPerDay, efficiency;
  28. //declaring variables for foodFootprint
  29. double kWhPerMonth;
  30. int numPeople;
  31. //declaring variables for calculating foodFootprint
  32. double meat, dairy, fv, carb;
  33. //declaring variables for values of footprint of each type and total footprint
  34. double trans, elec, food, total;
  35.  
  36. //Transportation footprint
  37. cout << "How many km do you drive in one day? ";
  38. cin >> KmPerDay;
  39. cout << "Choose the appropriate fuel efficiency for your car: \n";
  40. cout << "\tvery small car: 7.1 km/L\n";
  41. cout << "\tsmall car: 8.2 km/L\n";
  42. cout << "\tsports car: 14.9 km/L\n";
  43. cout << "\tSUV: 12.3 km/L\n";
  44. cout << "Or, if you know the efficiency rating, choose another number: ";
  45. cin >> efficiency;
  46.  
  47. trans = transportationFootprint(KmPerDay,efficiency);
  48. cout <<"Your Carbon footprint with respect to car use is " << trans <<"kg/year.\n";
  49.  
  50. //Electricity footprint
  51. cout <<"What is the average electricity consumption per month, in kilowatts? ";
  52. cin >> kWhPerMonth;
  53.  
  54. cout <<"How many people live in the house: ";
  55. cin >> numPeople;
  56.  
  57. elec = electricityFootprint(kWhPerMonth, numPeople);
  58. cout <<"Your carbon footprint with respect to electricity use is " << elec <<" kg/year.\n";
  59.  
  60. //Food footprint
  61. cout <<"Of all the food you eat, what percent consists of meat or fish? ";
  62. cin >> meat;
  63.  
  64. cout <<"Of all the food you eat, what percent consists of dairy products? ";
  65. cin >> dairy;
  66.  
  67. cout <<"Of all the food you eat, what percent consists of fruit or vegetables? ";
  68. cin >> fv;
  69.  
  70. cout <<"Of all the food you eat, what percent consists of carbohydrates? ";
  71. cin >> carb;
  72.  
  73. food = foodFootprint(meat, dairy, fv, carb);
  74. cout <<"Your carbon footprint with respect to food consumption is " << food <<" kg/year\n" << endl;
  75.  
  76. //Total footprint
  77. total = totalFootprint(trans, elec, food);
  78. cout <<"You produce an annual total of " << total << " metric tons of CO2 per year";
  79.  
  80. return 0;
  81. }
  82.  
  83. double transportationFootprint(double KmPerDay, double efficiency){
  84. double kgCO2;
  85. double LitersPerYear = 365 * (KmPerDay / efficiency);
  86. kgCO2 = 2.3 * LitersPerYear;
  87. return kgCO2;
  88. }
  89.  
  90. double electricityFootprint(double kWhPerMonth, int numPeople){
  91. double kgCO2;
  92. kgCO2 = (kWhPerMonth * 12 * 0.257) / numPeople;
  93. return kgCO2;
  94. }
  95.  
  96. double foodFootprint(double meat, double dairy, double fv, double carb) {
  97. double kgCO2;
  98. kgCO2 = ((meat/100) * 53.1) + ((dairy/100) * 13.8) + ((fv/100) * 7.6) + ((carb/100) * 3.1);
  99. return kgCO2;
  100. }
  101.  
  102. double totalFootprint(double trans, double elec, double food) {
  103. double kgCO2;
  104. kgCO2 = (trans + elec + food)/1000;
  105. return kgCO2;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement