Class Design Within the backend server, we’ll have multiple classes to organize our code.  All the class descriptions are listed below.  FoodWastageRecord NOTE: You need to design this class.   It represents each food wastage entry recorded by the user through the form on the webpage (frontend).   If you notice the form on the webpage, you’ll see that each FoodWastageRecord will have the following as the data members aka member variables. Date (as string) Meal (as string) Food name (as string) Quantity in ounces (as double) Wastage reason (as string) Disposal mechanism (as string) Cost (as double) Each member variable comes with its accessor/mutator functions.   FoodWastageReport NOTE: You need to design this class.   It represents the report generated on the basis of the records entered by the user. This class will be constructed with all the records entered by the user as a parameter. It will then apply the logic to go over all the records and compute the following: Names of most commonly wasted foods Most costly waste producing meals Total cost of food wasted Most common reasons of food wastage Most common mechanisms of food disposal Suggested strategies to reduce food waste   Your class should have getter functions to retrieve each of the above.   FoodWastageTracker NOTE: You need to design this class.   It’ll hold all the FoodWastageRecord objects in memory (notice the has-a relationship between the FoodWastageTracker class and FoodWastageRecord class in the diagram above).   It’ll allow the user to Add a FoodWastageRecord to the list of records in memory. IT SHOULD NOT add duplicate records. Return true if the record was added successfully, else return false. Delete a FoodWastageRecord from memory. Return true if the record was actually deleted. Return false if the record to be deleted wasn’t found. [NOTE: This is an extra credit requirement.]  Get all FoodWastageRecord objects from memory Generate and return the FoodWastageReport   All four of these will be the member functions of your class. FoodWastageTrackerBackend   The top level class in the backend server is the FoodWastageTrackerBackend class. Most of the implementation of this class has already been provided to you as part of the starter code. Think of this class as an adapter between the frontend and the code that you are going to write. It encapsulates all the complexity around interacting with the frontend, reading food wastage records from the JSON file and writing food wastage records to the JSON file.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

Class Design

Within the backend server, we’ll have multiple classes to organize our code. 

All the class descriptions are listed below. 

FoodWastageRecord

NOTE: You need to design this class.

 

It represents each food wastage entry recorded by the user through the form on the webpage (frontend).

 

If you notice the form on the webpage, you’ll see that each FoodWastageRecord will have the following as the data members aka member variables.

  • Date (as string)
  • Meal (as string)
  • Food name (as string)
  • Quantity in ounces (as double)
  • Wastage reason (as string)
  • Disposal mechanism (as string)
  • Cost (as double)

Each member variable comes with its accessor/mutator functions.

 

FoodWastageReport

NOTE: You need to design this class.

 

It represents the report generated on the basis of the records entered by the user. This class will be constructed with all the records entered by the user as a parameter. It will then apply the logic to go over all the records and compute the following:

  • Names of most commonly wasted foods
  • Most costly waste producing meals
  • Total cost of food wasted
  • Most common reasons of food wastage
  • Most common mechanisms of food disposal
  • Suggested strategies to reduce food waste

 

Your class should have getter functions to retrieve each of the above.

 

FoodWastageTracker

NOTE: You need to design this class.

 

It’ll hold all the FoodWastageRecord objects in memory (notice the has-a relationship between the FoodWastageTracker class and FoodWastageRecord class in the diagram above).

 

It’ll allow the user to

  • Add a FoodWastageRecord to the list of records in memory. IT SHOULD NOT add duplicate records. Return true if the record was added successfully, else return false.
  • Delete a FoodWastageRecord from memory. Return true if the record was actually deleted. Return false if the record to be deleted wasn’t found. [NOTE: This is an extra credit requirement.] 
  • Get all FoodWastageRecord objects from memory
  • Generate and return the FoodWastageReport

 

All four of these will be the member functions of your class.

FoodWastageTrackerBackend

 

The top level class in the backend server is the FoodWastageTrackerBackend class. Most of the implementation of this class has already been provided to you as part of the starter code. Think of this class as an adapter between the frontend and the code that you are going to write. It encapsulates all the complexity around interacting with the frontend, reading food wastage records from the JSON file and writing food wastage records to the JSON file.

9
9
10
11
13
12
13
14
15 V class FoodWastageTrackerBackend {
public:
16
17
17
10
18
10
19
20
20
..
21
22
23
24
...
25
26
on
27
20
28
20
29
20
30
31
20
32
22
33
24
34
ar
35
36
27
37
38
39
40
// A class to represent the Food wastage tracker backend. This class receives
// and returns CROW framework compatible objects. So when you are implementing
// your own classes to represent concepts like food wastage record and food
// wastage report etc, you'll have to comvert those objects to/from CROW
// objects. Some helper functions have been provided in
// food_wastage_tracker_backend.cc to help you with that conversion.
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
FoodwastageTrackerBackend (const std::string &food_wastage_records_filepath)
: food_wastage_records_filepath_{food_wastage_records_filepath} {}
// Reads the food wastage records from the file at
//
food_wastage_records_filepath, and loads those in memory. If the file is
// empty, it is a no-op. Returns true if the file was read successfully, else
// returns false. NOTE: This function should be called right after the object
// instantiation.
// Example:
// FoodwastageTrackerBackend backend{"path/to/some_file_name.JSON");
//backend. LoadRecordsFromJsonFile();
bool LoadRecordsFrom]SONFile();
// Writes the food wastage records from the memory to a JSON file at path
// food_wastage_records_filepath_. Returns true if the file was written
// successfully, else returns false.
bool WriteRecords ToJSONFile() const;
// Add the given food wastage record (in the query_string) to the memory.
crow::json::wvalue AddRecord (const crow::query_string &query_string);
// Delete the given food wastage record (in the query_string) from the memory
crow::json::wvalue DeleteRecord (const crow::query_string &query_string);
// Returns all the food wastage records that are stored in the memory.
crow::json::wvalue GetRecords () const;
// Generate a report based on all the food wastage records in the memory.
crow::json::wvalue GetFoodWastageReport() const;
private:
// File path of the file that stores all the food wastage records in JSON
// format.
const std::string &food_wastage_records_filepath_;
// A top level class object to track the food wastage.
// TODO: Add a FoodwastageTracker object as a member here. Make sure you stick
// to the Google's style guide while naming your variable.
FoodwastageTracker food_wastage_tracker;
};
Transcribed Image Text:9 9 10 11 13 12 13 14 15 V class FoodWastageTrackerBackend { public: 16 17 17 10 18 10 19 20 20 .. 21 22 23 24 ... 25 26 on 27 20 28 20 29 20 30 31 20 32 22 33 24 34 ar 35 36 27 37 38 39 40 // A class to represent the Food wastage tracker backend. This class receives // and returns CROW framework compatible objects. So when you are implementing // your own classes to represent concepts like food wastage record and food // wastage report etc, you'll have to comvert those objects to/from CROW // objects. Some helper functions have been provided in // food_wastage_tracker_backend.cc to help you with that conversion. 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 FoodwastageTrackerBackend (const std::string &food_wastage_records_filepath) : food_wastage_records_filepath_{food_wastage_records_filepath} {} // Reads the food wastage records from the file at // food_wastage_records_filepath, and loads those in memory. If the file is // empty, it is a no-op. Returns true if the file was read successfully, else // returns false. NOTE: This function should be called right after the object // instantiation. // Example: // FoodwastageTrackerBackend backend{"path/to/some_file_name.JSON"); //backend. LoadRecordsFromJsonFile(); bool LoadRecordsFrom]SONFile(); // Writes the food wastage records from the memory to a JSON file at path // food_wastage_records_filepath_. Returns true if the file was written // successfully, else returns false. bool WriteRecords ToJSONFile() const; // Add the given food wastage record (in the query_string) to the memory. crow::json::wvalue AddRecord (const crow::query_string &query_string); // Delete the given food wastage record (in the query_string) from the memory crow::json::wvalue DeleteRecord (const crow::query_string &query_string); // Returns all the food wastage records that are stored in the memory. crow::json::wvalue GetRecords () const; // Generate a report based on all the food wastage records in the memory. crow::json::wvalue GetFoodWastageReport() const; private: // File path of the file that stores all the food wastage records in JSON // format. const std::string &food_wastage_records_filepath_; // A top level class object to track the food wastage. // TODO: Add a FoodwastageTracker object as a member here. Make sure you stick // to the Google's style guide while naming your variable. FoodwastageTracker food_wastage_tracker; };
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

in C++ please

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,