Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program name: Lab3a
- //
- // Description: This program prints macro nutrional data.
- //
- // What's on your mind about this lab? This exercise gives me an
- // opportunity to learn how to use classes.
- //
- // Author: Aaron Rosales
- //
- // Date: 02/19/2020
- //
- // IDE Used: visual studio 2019
- //
- // Note: DO NOT remove these include statements.#include <string>
- #include <string>
- #ifndef NUTRITIONDATA_H
- #define NUTRITIONDATA_H
- using namespace std;
- class NutritionData {
- private:
- // The name of the food.
- string foodName;
- // The size of the serving.
- int servingSize;
- // The calories from the carbs.
- double calFromCarb;
- // The calories from the fat.
- double calFromFat;
- // The calories from the protein.
- double calfromProtein;
- public:
- // Initializes the constuctor in list syntax form.
- NutritionData(string fd = "", int ss = 0,
- double cc = 0.0, double cf = 0.0, double cp = 0.0)
- :foodName(fd),
- servingSize(ss),
- calFromCarb(cc),
- calFromFat(cf),
- calfromProtein(cp) {
- }
- /*NutritionData(string fd, int ss,
- double cc, double cf, double cp) {
- }
- */
- //************************************************************************
- //* Function name: setFoodName
- //*
- //* This function sets the food name.
- //*
- //* Parameters:
- //* userFoodName - a value that passes the food name into the function
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void setFoodName(string userFoodName) {
- foodName = userFoodName;
- }
- //************************************************************************
- //* Function name: setServingSize
- //*
- //* This function sets the serving size data.
- //*
- //* Parameters:
- //* size - a value that passes the food size into the function
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void setServingSize(int size) {
- servingSize = size;
- }
- //************************************************************************
- //* Function name: setCalFromCarb
- //*
- //* This function sets the calories from carbs.
- //*
- //* Parameters:
- //* carbMacro - a value that passes the macro
- //* nutitional information of carbs into the function
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void setCalFromCarb(double carbMacro) {
- calFromCarb = carbMacro;
- }
- //************************************************************************
- //* Function name: setCalFromFat
- //*
- //* This function sets the calories from fats.
- //*
- //* Parameters:
- //* fatMacro - a value that passes the macro
- //* nutitional information of fat into the function
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void setCalFromFat(double fatMacro) {
- calFromFat = fatMacro;
- }
- //************************************************************************
- //* Function name: setCalFromProtein
- //*
- //* This function sets the calories from protein.
- //*
- //* Parameters:
- //* fatMacro - a value that passes the macro
- //* nutitional information of protein into the function
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void setCalFromProtein(double bodyBuildersBestFriend) {
- calfromProtein = bodyBuildersBestFriend;
- }
- //************************************************************************
- //* Function name: getFoodName
- //*
- //* This function returns the food name.
- //*
- //* Parameters:
- //*
- //* Returns:
- //*
- //* foodName - The food name
- //*
- //************************************************************************
- string getFoodName() const {
- return foodName;
- }
- //************************************************************************
- //* Function name: getServingSize
- //*
- //* This function returns the serving size.
- //*
- //* Parameters:
- //*
- //* Returns:
- //*
- //* servingSize - The serving size
- //*
- //************************************************************************
- int getServingSize() const {
- return servingSize;
- }
- //************************************************************************
- //* Function name: getCalFromCarb
- //*
- //* This function returns the calories from carbs.
- //*
- //* Parameters:
- //*
- //* Returns:
- //*
- //* calFromCarb - The calories from carbs
- //*
- //************************************************************************
- double getCalFromCarb() const {
- return calFromCarb;
- }
- //************************************************************************
- //* Function name: getCalFromFat
- //*
- //* This function returns the calories from fat.
- //*
- //* Parameters:
- //*
- //* Returns:
- //*
- //* calFromFat - The calories from fat
- //*
- //************************************************************************
- double getCalFromFat() const {
- return calFromFat;
- }
- //************************************************************************
- //* Function name: getCalFromProtein
- //*
- //* This function returns the calories from protein.
- //*
- //* Parameters:
- //*
- //* Returns:
- //*
- //* calFromFat - The calories from protein
- //*
- //************************************************************************
- double getCalFromProtein() const {
- return calfromProtein;
- }
- };
- //double getCaloriesPerServing() const;
- #endif
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include "NutritionData.h"
- using namespace std;
- //double getCaloriesPerServing() const;
- void printNutritionData(const NutritionData& userData);
- int main() {
- NutritionData nutritionData[5]{
- {"Apples raw", 110, 50.6, 1.2, 1.0},
- {"Bananas", 225, 186, 6.2, 8.2},
- {"Bread pita whole wheat", 64, 134, 14, 22.6},
- {"Broccoli raw", 91, 21.9, 2.8, 6.3},
- {"Carrots raw", 128, 46.6, 2.6, 3.3},
- };
- for (NutritionData spot : nutritionData) {
- printNutritionData(spot);
- cout << endl;
- }
- }
- void printNutritionData(const NutritionData& userData) {
- // Set up some formatting requirements.
- cout << fixed << setprecision(1);
- // Print out the title, then calls upon the accessor
- // functions in the NutritionData class to print
- cout << "Food Name: "
- << userData.getFoodName() << endl;
- cout << "Serving Size: "
- << userData.getServingSize()
- << " grams." << endl;
- cout << "Calories Per Serving: "
- // << userData.getCaloriesPerServing()
- << " grams." << endl;
- cout << "Calories From Carb: "
- << userData.getCalFromCarb()
- << " grams." << endl;
- cout << "Calories From Fat: "
- << userData.getCalFromFat()
- << " grams." << endl;
- cout << "Calories From Protein: "
- << userData.getCalFromProtein()
- << " grams." << endl;
- }
- #include <string>
- #include "NutritionData.h"
- using namespace std;
- /*NutritionData::NutritionData(string fd, int ss,
- double cc, double cf, double cp)
- :foodName(fd),
- servingSize(ss),
- calFromCarb(cc),
- calFromFat(cf),
- calfromProtein(cp) {
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement