Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. // Program name: Lab3a
  2. //
  3. // Description: This program prints macro nutrional data.
  4. //
  5. // What's on your mind about this lab? This exercise gives me an
  6. // opportunity to learn how to use classes.
  7. //
  8. // Author: Aaron Rosales
  9. //
  10. // Date: 02/19/2020
  11. //
  12. // IDE Used: visual studio 2019
  13. //
  14.  
  15. // Note: DO NOT remove these include statements.#include <string>
  16.  
  17. #include <string>
  18. #ifndef NUTRITIONDATA_H
  19. #define NUTRITIONDATA_H
  20. using namespace std;
  21. class NutritionData {
  22.  
  23. private:
  24. // The name of the food.
  25. string foodName;
  26. // The size of the serving.
  27. int servingSize;
  28. // The calories from the carbs.
  29. double calFromCarb;
  30. // The calories from the fat.
  31. double calFromFat;
  32. // The calories from the protein.
  33. double calfromProtein;
  34. public:
  35. // Initializes the constuctor in list syntax form.
  36. NutritionData(string fd = "", int ss = 0,
  37. double cc = 0.0, double cf = 0.0, double cp = 0.0)
  38. :foodName(fd),
  39. servingSize(ss),
  40. calFromCarb(cc),
  41. calFromFat(cf),
  42. calfromProtein(cp) {
  43.  
  44. }
  45. /*NutritionData(string fd, int ss,
  46. double cc, double cf, double cp) {
  47.  
  48. }
  49. */
  50.  
  51.  
  52. //************************************************************************
  53. //* Function name: setFoodName
  54. //*
  55. //* This function sets the food name.
  56. //*
  57. //* Parameters:
  58. //* userFoodName - a value that passes the food name into the function
  59. //*
  60. //* Returns:
  61. //*
  62. //* void
  63. //*
  64. //************************************************************************
  65. void setFoodName(string userFoodName) {
  66. foodName = userFoodName;
  67. }
  68.  
  69. //************************************************************************
  70. //* Function name: setServingSize
  71. //*
  72. //* This function sets the serving size data.
  73. //*
  74. //* Parameters:
  75. //* size - a value that passes the food size into the function
  76. //*
  77. //* Returns:
  78. //*
  79. //* void
  80. //*
  81. //************************************************************************
  82. void setServingSize(int size) {
  83. servingSize = size;
  84. }
  85.  
  86. //************************************************************************
  87. //* Function name: setCalFromCarb
  88. //*
  89. //* This function sets the calories from carbs.
  90. //*
  91. //* Parameters:
  92. //* carbMacro - a value that passes the macro
  93. //* nutitional information of carbs into the function
  94. //*
  95. //* Returns:
  96. //*
  97. //* void
  98. //*
  99. //************************************************************************
  100. void setCalFromCarb(double carbMacro) {
  101. calFromCarb = carbMacro;
  102. }
  103.  
  104. //************************************************************************
  105. //* Function name: setCalFromFat
  106. //*
  107. //* This function sets the calories from fats.
  108. //*
  109. //* Parameters:
  110. //* fatMacro - a value that passes the macro
  111. //* nutitional information of fat into the function
  112. //*
  113. //* Returns:
  114. //*
  115. //* void
  116. //*
  117. //************************************************************************
  118. void setCalFromFat(double fatMacro) {
  119. calFromFat = fatMacro;
  120. }
  121.  
  122. //************************************************************************
  123. //* Function name: setCalFromProtein
  124. //*
  125. //* This function sets the calories from protein.
  126. //*
  127. //* Parameters:
  128. //* fatMacro - a value that passes the macro
  129. //* nutitional information of protein into the function
  130. //*
  131. //* Returns:
  132. //*
  133. //* void
  134. //*
  135. //************************************************************************
  136. void setCalFromProtein(double bodyBuildersBestFriend) {
  137. calfromProtein = bodyBuildersBestFriend;
  138. }
  139.  
  140. //************************************************************************
  141. //* Function name: getFoodName
  142. //*
  143. //* This function returns the food name.
  144. //*
  145. //* Parameters:
  146. //*
  147. //* Returns:
  148. //*
  149. //* foodName - The food name
  150. //*
  151. //************************************************************************
  152. string getFoodName() const {
  153. return foodName;
  154. }
  155.  
  156. //************************************************************************
  157. //* Function name: getServingSize
  158. //*
  159. //* This function returns the serving size.
  160. //*
  161. //* Parameters:
  162. //*
  163. //* Returns:
  164. //*
  165. //* servingSize - The serving size
  166. //*
  167. //************************************************************************
  168. int getServingSize() const {
  169. return servingSize;
  170. }
  171.  
  172. //************************************************************************
  173. //* Function name: getCalFromCarb
  174. //*
  175. //* This function returns the calories from carbs.
  176. //*
  177. //* Parameters:
  178. //*
  179. //* Returns:
  180. //*
  181. //* calFromCarb - The calories from carbs
  182. //*
  183. //************************************************************************
  184. double getCalFromCarb() const {
  185. return calFromCarb;
  186. }
  187.  
  188. //************************************************************************
  189. //* Function name: getCalFromFat
  190. //*
  191. //* This function returns the calories from fat.
  192. //*
  193. //* Parameters:
  194. //*
  195. //* Returns:
  196. //*
  197. //* calFromFat - The calories from fat
  198. //*
  199. //************************************************************************
  200. double getCalFromFat() const {
  201. return calFromFat;
  202. }
  203.  
  204. //************************************************************************
  205. //* Function name: getCalFromProtein
  206. //*
  207. //* This function returns the calories from protein.
  208. //*
  209. //* Parameters:
  210. //*
  211. //* Returns:
  212. //*
  213. //* calFromFat - The calories from protein
  214. //*
  215. //************************************************************************
  216. double getCalFromProtein() const {
  217. return calfromProtein;
  218. }
  219.  
  220.  
  221. };
  222. //double getCaloriesPerServing() const;
  223.  
  224.  
  225.  
  226. #endif
  227.  
  228. #include <iostream>
  229. #include <iomanip>
  230. #include <string>
  231. #include "NutritionData.h"
  232. using namespace std;
  233. //double getCaloriesPerServing() const;
  234. void printNutritionData(const NutritionData& userData);
  235. int main() {
  236. NutritionData nutritionData[5]{
  237. {"Apples raw", 110, 50.6, 1.2, 1.0},
  238. {"Bananas", 225, 186, 6.2, 8.2},
  239. {"Bread pita whole wheat", 64, 134, 14, 22.6},
  240. {"Broccoli raw", 91, 21.9, 2.8, 6.3},
  241. {"Carrots raw", 128, 46.6, 2.6, 3.3},
  242. };
  243.  
  244. for (NutritionData spot : nutritionData) {
  245. printNutritionData(spot);
  246. cout << endl;
  247. }
  248. }
  249. void printNutritionData(const NutritionData& userData) {
  250. // Set up some formatting requirements.
  251. cout << fixed << setprecision(1);
  252. // Print out the title, then calls upon the accessor
  253. // functions in the NutritionData class to print
  254. cout << "Food Name: "
  255. << userData.getFoodName() << endl;
  256. cout << "Serving Size: "
  257. << userData.getServingSize()
  258. << " grams." << endl;
  259. cout << "Calories Per Serving: "
  260. // << userData.getCaloriesPerServing()
  261. << " grams." << endl;
  262. cout << "Calories From Carb: "
  263. << userData.getCalFromCarb()
  264. << " grams." << endl;
  265. cout << "Calories From Fat: "
  266. << userData.getCalFromFat()
  267. << " grams." << endl;
  268. cout << "Calories From Protein: "
  269. << userData.getCalFromProtein()
  270. << " grams." << endl;
  271. }
  272.  
  273. #include <string>
  274. #include "NutritionData.h"
  275. using namespace std;
  276. /*NutritionData::NutritionData(string fd, int ss,
  277. double cc, double cf, double cp)
  278. :foodName(fd),
  279. servingSize(ss),
  280. calFromCarb(cc),
  281. calFromFat(cf),
  282. calfromProtein(cp) {
  283.  
  284. }
  285. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement