This is like previously asked questions, but the instructor has added extra requirements and a template to utilize. The Corner Grocer needs a program that analyzes the text records they generate. These records list items purchased in chronological order from the time the store opens to the time it closes. They need to know how often items are purchased so they can create the most effective layout for their customers. The program that the Corner Grocer is asking you to create should address the following functional requirements: Menu Options One: Prompt a user to input the item to look for. Return a numeric value for the frequency of the word. Two: Print the list with numbers that represent the frequency of all items purchased. The screen output should include every item (represented by a word) paired with the number of times that item appears in the input file, CS210_Project_Three_Input_File.txt. IE, the file might read: Potatoes 4 Pumpkins 5 Onions 3 Three: Print the same frequency information for all items in the form of a histogram. Then print the name, followed by asterisks or another special character to represent the numeric amount. The number of asterisks should equal the frequency read from the CS210_Project_Three_Input_File.txt file. IE::  Potatoes **** Pumpkins ***** Onions *** Four: Exit the program. Data File Creation: Create a data file, with the naming convention frequency.dat, for backing up your accumulated data. The frequency.dat file should include every item (represented by a word) paired with the number of times that item appears in the input file. This output file is created at the beginning of the program without user intervention and is for backup purposes.  Documentation: Describe your code’s design and functionality. Include screenshots to support your description.  Implementation Guidelines For this assignment, your implementation plan must include at least one class with public and private sections.  For this assignment, we recommend using Maps however, you can choose a different implementation option. Apply industry standard best practices such as in-line comments and appropriate naming conventions. This includes the following: Inserting in-line comments to denote your changes and briefly describe the functionality of the code, using appropriate variable, parameter, and other naming conventions throughout Optional Challenge: User Input Validation Use input validation and error handling to anticipate, detect, and respond to run-time and user errors (ie: ensure there's an option on your menu to exit the program). Instructor details w/ template: Keep in mind you need a class. The requirements that I have is it must encapsulate the Grocery data (name and quantity). Having a class that performs the logic and flow of the program is insufficient. It’s not necessary as it would not be reusable in a different application. The GroceryItem class could be reused in any type of application, if it does not perform any cout/cin operations (which it shouldn't). Project mentions using a map where the item name is the key and the quantity is the value. That does not lend itself to using a class as there is nothing to encapsulate. I chose a set implementation, which prevents having duplicate entries. You could use a vector implementation (at a slight deduction). The vector does not prevent having duplicate entries. You should read the input text file for each of the menu operations that do not exit. Assume that the input text file can be dynamically updated somewhere else...our role is to provide reports based on the current values in the input text file.   GroceryItem.h class GroceryItem { Public: GroceryItem(std::string& name); GroceryItem(std::string& name); std::string getName() const; int getQuantity() const;  void addItem(); void removeItem(); bool operator<(const GroceryItem& other) const; private: std::string name; int quantity; }; GroceryItem.cpp The following is used for std::set operations bool GroceryItem::operator<(const GroceryItem& other) const return name.compare(other.getName()) < 0; } Source.cpp //create method to read the inventory.txt file and returns a set of GroceryItem //Read the name from the file //Create GroceryItem pointer //use set find method //If in set already //copy off existing name //copy off existing quantity //Erase existing item from set //Reassign GroceryItem point to one with the existing name and quantity //Call addItem //Insert into the set //Free the pointer! //Backup the accumulated date to frequency.txt Declaring a set: set items; The following checks if an item is already in a set auto existingItem = items.find(*item); if (existingItem != items.end()) { //Remember existingItem is a pointer to a GroceryItem } Source.cpp (main method) //Loop until user selects exit from menu //validate input //Handle the 4 options (use the method that reads inventory.txt file each time) //search for item //Display all frequencies //Print histogram //Exit The following loops through a set For (GroceryItem item: items) { }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is like previously asked questions, but the instructor has added extra requirements and a template to utilize.

The Corner Grocer needs a program that analyzes the text records they generate. These records list items purchased in chronological order from the time the store opens to the time it closes. They need to know how often items are purchased so they can create the most effective layout for their customers.

The program that the Corner Grocer is asking you to create should address the following functional requirements:

Menu Options

One:

  1. Prompt a user to input the item to look for.
  2. Return a numeric value for the frequency of the word.

Two:

  1. Print the list with numbers that represent the frequency of all items purchased.
    The screen output should include every item (represented by a word) paired with the number of times that item appears in the input file, CS210_Project_Three_Input_File.txt. IE, the file might read:

Potatoes 4
Pumpkins 5
Onions 3

Three:

  1. Print the same frequency information for all items in the form of a histogram.
  2. Then print the name, followed by asterisks or another special character to represent the numeric amount.
    The number of asterisks should equal the frequency read from the CS210_Project_Three_Input_File.txt file. IE:: 

Potatoes ****
Pumpkins *****
Onions ***

Four:

  1. Exit the program.

Data File Creation:
Create a data file, with the naming convention frequency.dat, for backing up your accumulated data. The frequency.dat file should include every item (represented by a word) paired with the number of times that item appears in the input file.

This output file is created at the beginning of the program without user intervention and is for backup purposes. 

Documentation:
Describe your code’s design and functionality. Include screenshots to support your description. 

Implementation Guidelines For this assignment, your implementation plan must include at least one class with public and private sections

  • For this assignment, we recommend using Maps however, you can choose a different implementation option.

Apply industry standard best practices such as in-line comments and appropriate naming conventions. This includes the following: Inserting in-line comments to denote your changes and briefly describe the functionality of the code, using appropriate variable, parameter, and other naming conventions throughout

Optional Challenge: User Input Validation
Use input validation and error handling to anticipate, detect, and respond to run-time and user errors (ie: ensure there's an option on your menu to exit the program).

Instructor details w/ template: Keep in mind you need a class. The requirements that I have is it must encapsulate the Grocery data (name and quantity). Having a class that performs the logic and flow of the program is insufficient. It’s not necessary as it would not be reusable in a different application. The GroceryItem class could be reused in any type of application, if it does not perform any cout/cin operations (which it shouldn't).

Project mentions using a map<string, int> where the item name is the key and the quantity is the value. That does not lend itself to using a class as there is nothing to encapsulate. I chose a set implementation, which prevents having duplicate entries. You could use a vector implementation (at a slight deduction). The vector does not prevent having duplicate entries.

You should read the input text file for each of the menu operations that do not exit. Assume that the input text file can be dynamically updated somewhere else...our role is to provide reports based on the current values in the input text file.

 

GroceryItem.h

class GroceryItem

{

Public:

GroceryItem(std::string& name);

GroceryItem(std::string& name);

std::string getName() const;

int getQuantity() const;

 void addItem();

void removeItem();

bool operator<(const GroceryItem& other) const;

private:

std::string name;

int quantity;

};

GroceryItem.cpp

The following is used for std::set operations

bool GroceryItem::operator<(const GroceryItem& other) const

return name.compare(other.getName()) < 0;

}

Source.cpp

//create method to read the inventory.txt file and returns a set of GroceryItem

//Read the name from the file

//Create GroceryItem pointer

//use set find method

//If in set already

//copy off existing name

//copy off existing quantity

//Erase existing item from set

//Reassign GroceryItem point to one with the existing name and quantity

//Call addItem

//Insert into the set

//Free the pointer!

//Backup the accumulated date to frequency.txt

Declaring a set:

set<GroceryItem> items;

The following checks if an item is already in a set

auto existingItem = items.find(*item);

if (existingItem != items.end()) {

//Remember existingItem is a pointer to a GroceryItem

}

Source.cpp (main method)

//Loop until user selects exit from menu

//validate input

//Handle the 4 options (use the method that reads inventory.txt file each time)

//search for item

//Display all frequencies

//Print histogram

//Exit

The following loops through a set

For (GroceryItem item: items) {

}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 9 images

Blurred answer
Knowledge Booster
Requirement Analysis
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education