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 <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- class NutritionData {
- private:
- string foodName;
- int servingSize;
- double calFromCarb;
- double calFromFat;
- double calfromProtein;
- public:
- NutritionData();
- // Gets the food name and sets it to a string.
- void setFoodName(string);
- // Gets the serving size and sets it to a int.
- void setServingSize(int);
- // Gets the calories from carbs and sets it to a double.
- void setCalFromCarb(double);
- // Gets the calories from fat and sets it to a double.
- void setCalFromFat(double);
- // Gets the calories from protein and sets it to a double.
- void setCalFromProtein(double);
- // Returns the food name.
- const string getFoodName();
- // Returns the serving size.
- const int getServingSize();
- // Returns the calories from carbs.
- const double getCalFromCarb();
- // Returns the calories from fat.
- const double getCalFromFat();
- // Returns the calories from protein.
- const double getCalFromProtein();
- // Returns the total calories per serving.
- const double getCaloriesPerServing();
- };
- NutritionData::NutritionData() {
- // Initializes all of variables that may be used in the class.
- string foodName = "";
- int servingSize = 0;
- double calFromCarb = 0.0;
- double calFromFat = 0.0;
- double calfromProtein = 0.0;
- }
- // Sets the food name.
- void NutritionData::setFoodName(string userFoodName) {
- foodName = userFoodName;
- }
- // Gets the serving size and sets it to an int.
- void NutritionData::setServingSize(int size) {
- servingSize = size;
- }
- // Gets the calories from carbs and sets it to a double.
- void NutritionData::setCalFromCarb(double carbMacro) {
- calFromCarb = carbMacro;
- }
- // Gets the calories from fat and sets it to a double.
- void NutritionData::setCalFromFat(double fatMacro) {
- calFromFat = fatMacro;
- }
- // Gets the calories from protein and sets it to a double.
- void NutritionData::setCalFromProtein(double bodyBuildersBestFriend) {
- calFromCarb = bodyBuildersBestFriend;
- }
- // Returns the food name.
- const string NutritionData::getFoodName() {
- return foodName;
- }
- // Returns the serving size.
- const int NutritionData::getServingSize() {
- return servingSize;
- }
- // Returns the calories from carbs.
- const double NutritionData::getCalFromCarb() {
- return calFromCarb;
- }
- // Returns the calories from fat.
- const double NutritionData::getCalFromFat() {
- return calFromFat;
- }
- // Returns the calories from protein.
- const double NutritionData::getCalFromProtein() {
- return calfromProtein;
- }
- // Returns the total calories per serving.
- const double NutritionData::getCaloriesPerServing() {
- return calFromCarb + calFromFat + calfromProtein;
- }
- // Prototype for a function that prints out the data.
- void printNutritionData(const NutritionData&);
- int main() {
- // Next 5 lines would be the "user" input.
- string foodName = "Bread pita whole wheat";
- int servingSize = 64;
- double calFromCarb = 134.0;
- double calFromFat = 14.0;
- double calfromProtein = 22.6;
- // Defines an instance of the class.
- NutritionData pita;
- // Calls upon the functions that set up the pita bread nutrition facts.
- pita.setFoodName(foodName);
- pita.setServingSize(servingSize);
- pita.setCalFromCarb(calFromCarb);
- pita.setCalFromFat(calFromFat);
- pita.setCalFromProtein(calfromProtein);
- // Calls upon the function to print out the data.
- printNutritionData(pita);
- return 0;
- }
- // Remove the function template below for the labs not requiring functions.
- //************************************************************************
- //* Function name: printNutritionData
- //*
- //* This function prints out the nutrion data.
- //*
- //* Parameters:
- //* printableData - is a pass through reference that accesses the data.
- //*
- //* Returns:
- //*
- //* void
- //*
- //************************************************************************
- void printNutritionData(const NutritionData& userData) {
- cout << fixed << setprecision(1);
- 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.getCalFromProtein()
- << " grams." << endl;
- cout << "Calories From Protein: "
- << userData.getCaloriesPerServing()
- << " grams." << endl;
- }
- /*
- Copy output of this program below this line.
- --------------------------------------------
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement