Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Daily Calorie Reportprogram that receives several food items and their calorie numbers and when they were consumed. There are four options for the time of

Daily Calorie Reportprogram that receives several food items and their calorie numbers and when they were consumed.

There are four options for the time of the food consumption:

Mealtime and their code

WhenCodeBreakfast1Lunch2Dinner3Snack4

The program should report the list of the Items as follows and at the end of the report it should print the total daily Calorie consumption:

Report sample

+----------------------------------------------------+ | Daily Calorie Consumption | +--------------------------------+------+------------+ | Food name | Cals | When | +--------------------------------+------+------------+ | Cheerios Cereal with 2% milk.. | 170 | Breakfast | | Tim Hortons Medium coffee doub | 230 | Breakfast | | Cheeseburger.................. | 303 | Lunch | | French Fries.................. | 312 | Lunch | | Pepsi......................... | 150 | Lunch | | Apple......................... | 52 | Snack | | Bread and Cheese.............. | 195 | Dinner | | Garden Salad with Dressing.... | 220 | Dinner | | Red Wine...................... | 85 | Dinner | +--------------------------------+------+------------+ | Total Calories for today: 1717 | | +----------------------------------------------------+ 

implementation

Code your implementation in two modules:

Food Module

The Food class should at least hold the following information:

  • Food name; up to 30 characters
  • Calorie number; valid between 0 and 3000 calories (including 3000).
  • Time of consumption; values 1, 2, 3 or 4 (seeMeal time and their code)

Displaying a food item

A food item should be displayed as shown in theReport Sample

If the Food item holds invalid information all the data are replaced with "x":

| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | 

Your food module should not unnecessarily expose any method or attribute; "Only make thingspublicif needed".

CalorieList Module

The CalorieList class should dynamically hold series of Food items and display them in a report.

Following are the mandatory public member functions:

 // sets the CalorieList to accept the "size" number of Food Items.  // This function is called to prepare the CalorieList for accepting food items void init(int size); // Adds Food Items using their Name, Calorie count and time of consumption up to  // the number set in the init() function, returns true if successful. bool add(const char* item_name, int calories, int when); // Displays the report with food information and the total calorie consumed in the day // as shown in the report sample void display()const; // Releases all the memory used. After this function init() can be called for another // report; void deallocate(); 

The tester program

Here is a sample of the main program using theCalorieListClass and its execution result:

// Workshop 3:  // Version: 0.9 // Date: 2021/1/31 // Author: Fardad Soleimanloo // Description: // This file tests the DIY section of your workshop // Do not modify this code when submitting ///////////////////////////////////////////// #define _CRT_SECURE_NO_WARNINGS #include  #include  #include "CalorieList.h" using namespace sdds; using namespace std; const int c_breakfast = 1; const int c_lunch = 2; const int c_dinner = 3; const int c_snack = 4; void testDMA(CalorieList& CL); int main() { CalorieList CL; CL.init(5); CL.add("Cheerios Cereal with 2% milk", 170, c_breakfast); CL.display(); CL.add(nullptr, 100, c_breakfast); CL.add("Cheeseburger", 303, c_lunch); CL.add("Pepsi", 150, 0); CL.add("Apple", 52, c_snack); CL.display(); CL.deallocate(); CL.init(9); CL.add("Cheerios Cereal with 2% milk", 170, c_breakfast); CL.add("Tim Hortons Medium coffee double double", 230, c_breakfast); CL.add("Cheeseburger", 303, c_lunch); CL.add("French Fries", 312, c_lunch); CL.add("Pepsi", 150, c_lunch); CL.add("Apple", 52, c_snack); CL.add("Bread and Cheese", 195, c_dinner); CL.add("Garden Salad with Dressing", 220, c_dinner); if (!CL.add("Red Wine", 85, c_dinner)) { cout << "This should not be printed!" << endl; } if (CL.add("This should not be added", 100, c_dinner)) { cout << "This should not be printed!" << endl; } CL.display(); CL.deallocate(); //testDMA(CL); // uncommnet to test DMA return 0; } void testDMA(CalorieList& CL) { CL.init(1000); for (int i = 0; i < 1000; i++) { CL.add("Tim Hortons Medium coffee double double", 230, c_breakfast); } CL.display(); CL.deallocate(); } 

The tester program output

+----------------------------------------------------+ | Invalid Calorie Consumption list | +--------------------------------+------+------------+ | Food name | Cals | When | +--------------------------------+------+------------+ | Cheerios Cereal with 2% milk.. | 170 | Breakfast | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | +--------------------------------+------+------------+ | Invalid Calorie Consumption list | +----------------------------------------------------+ +----------------------------------------------------+ | Invalid Calorie Consumption list | +--------------------------------+------+------------+ | Food name | Cals | When | +--------------------------------+------+------------+ | Cheerios Cereal with 2% milk.. | 170 | Breakfast | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | | Cheeseburger.................. | 303 | Lunch | | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxx | xxxxxxxxxx | | Apple......................... | 52 | Snack | +--------------------------------+------+------------+ | Invalid Calorie Consumption list | +----------------------------------------------------+ +----------------------------------------------------+ | Daily Calorie Consumption | +--------------------------------+------+------------+ | Food name | Cals | When | +--------------------------------+------+------------+ | Cheerios Cereal with 2% milk.. | 170 | Breakfast | | Tim Hortons Medium coffee doub | 230 | Breakfast | | Cheeseburger.................. | 303 | Lunch | | French Fries.................. | 312 | Lunch | | Pepsi......................... | 150 | Lunch | | Apple......................... | 52 | Snack | | Bread and Cheese.............. | 195 | Dinner | | Garden Salad with Dressing.... | 220 | Dinner | | Red Wine...................... | 85 | Dinner | +--------------------------------+------+------------+ | Total Calories for today: 1717 | | +----------------------------------------------------+ 

Files to submit:

calListTester.cpp CalorieList.cpp CalorieList.h Food.cpp Food.h cstring.cpp cstring.h 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions