Data from the file grocery.dat

Assignment Help C/C++ Programming
Reference no: EM13161475

You will create a GroceryItem class that contains the following data: item_name, item_price, quantity_on_hand, and qty_purchased. The GroceryItemclass will contain the following methods:

  • GroceryItem(): The default constructor.
  • set_item_name(): Assigns a value to the data member item_name.
  • set_item_price(): Assigns a value to the data member item_price.
  • set_qty_on_hand(): Assigns a value to the data member quantity_on_hand.
  • set_qty_purchased(): Sets qty_purchased to zero before a customer begins shopping.
  • get_item_name(): Returns the value of the data member item_name.
  • get_item_price(): Returns the value of the data member item_price.
  • get_qty_on_hand(): Returns the value of the data member quantity_on_hand.
  • get_qty_purchased(): Returns the value of the data member qty_purchased.

Write a C++ program that creates an array of 10 GroceryItem objects. Read the data from the file Grocery.dat and assign values to the 10 GroceryItem objects. Next display these items to allow a customer to select grocery items from the list and indicate the quantity of that item he or she would like to order. When the customer finishes shopping, the program should display the items and quantities he or she has chosen, then calculate the total bill. The program should also simulate delivering the order with a cout statement that announces the customer's total bill and tells the customer that the order will be delivered by the end of the day.

this is grocery.dat

Grocery.dat File

Raisin Bran 3.49 300 Milk 1.49 200 White Bread 2.49 50 Butter 2.49 100 Grape Jelly 1.09 50 Peanut Butter 2.49 45 Tomato Soup .49 200 Cherry Yogurt .69 250 Vanilla Yogurt .69 200 Rye Bread 1.49 55

then do this

In part II, you will create all necessary constructors for the GroceryItem class by using default function arguments, if appropriate. In addition, you should change the implementation of the item_name to use dynamically allocated memory instead of an array of characters. Make sure that you write a destructor for this class, as you are now using dynamically allocated memory. You should also overload the comparison operators (>, <, = =, !=, >=, and <=) so that you can sort the customer's order alphabetically by item_name.In addition, you will need to overload the assignment operator (=).

Read the data from the file Grocery.dat and assign values to the 10 GroceryItem objects. Next display these items to allow a customer to select grocery items from the list and indicate the quantity of that item he or she would like to order. When the customer finishes shopping, the program should display the items and quantities he or she has chosen, sorted by item_name. then calculate the total bill. The program should also simulate delivering the order with a cout statement that announces the customer's total bill and tells the customer "your order is on its way."

then do this

In Part III, you will create a second class named Customer that will keep track of each customer's name, address, and total bill. Write the methods for the Customerclass, including a method named pick_one().Pass aGroceryItemobject to the pick_one() method so that you can add its price to the Customerobject's total bill. TheGroceryItem class should grant friendship to the Customerclass. Use constants, constant methods, and inline functions where appropriate.

Simulate a customer shopping by picking items from the array of Grocery objects and then calculating a total bill.

When you finish, you should have the main program (i.e. the driver) and the class files as grocery.h, grocery.cpp, customer.h and customer.cpp.

I have the first two. I only need part 3.

#include <string>

using namespace std;

class GroceryItem{

string item_name;

float item_price;

int quantity_on_hand;

int qty_purchased;

int selected;

public:

GroceryItem(void){selected = 0;}

~GroceryItem(void) {}

void set_selected() { this->selected = 1; }

void set_item_name(string name) { this->item_name = name; }

void set_item_price(float price) { this->item_price = price; }

void set_qty_on_hand(int qty) { this->quantity_on_hand = qty; }

void set_qty_purchased(int purchased) {this->qty_purchased = purchased; }

int is_selected() { return selected; }

string get_item_name() { return item_name; }

float get_item_price() { return item_price; }

int get_qty_on_hand() { return quantity_on_hand; }

int get_qty_purchased() { return qty_purchased; }

};

#include <iostream>

#include <fstream>

using namespace std;

int main(){

GroceryItem items[10];

ifstream file ("Grocery.dat");

string line;

if(!file.is_open()) {

cerr << "Unable to open the file" << endl;

return -1;

}

int i = 0;

string item_name;

float item_price;

int quantity_on_hand;

int qty_purchased;

while(!file.eof()){

file >> item_name >> item_price >> quantity_on_hand >> qty_purchased;

items[i].set_item_name(item_name);

items[i].set_item_price(item_price);

items[i].set_qty_on_hand(quantity_on_hand);

items[i].set_qty_purchased(qty_purchased);

i++;

}

file.close();

cout << "Items available : quantity" << endl;

cout << "--------------------------------" << endl;

for(int i=0; i<10; i++)

cout << i << ". " << items[i].get_item_name() << " : " << items[i].get_qty_on_hand() << endl;

char c;

float bill = 0;

while(true) {

cout << "Buy items (Y/N): ";

cin >> c;

if(c != 'Y' && c!= 'y') break;

int id, quantity;

cout << "Enter item id: "; cin >> id;

cout << "Enter item quantity: "; cin >> quantity;

items[id].set_qty_purchased(quantity);

items[id].set_qty_on_hand(items[i].get_qty_on_hand() - quantity);

items[id].set_selected();

bill += items[id].get_item_price() * (float) quantity;

}

cout << "Selected items:" << endl;

cout << "---------------------------------" << endl;

for(int i=0; i<10; i++)

if(items[i].is_selected())

cout << i << ". " << items[i].get_item_name() << " : " << items[i].get_qty_purchased() << endl;

cout << "Total bill: " << bill << endl;

cout << "The order will be deliverd in one day." << endl;

return 0;

}

Reference no: EM13161475

Questions Cloud

Binary tree, print right view of it : Given a Binary Tree, print Right view of it. Right view of a Binary Tree is set of nodes visible when tree is visited from Right side.
Write an lc-3 machine language program : Write an LC-3 machine language program starting at location x3000 which divides the number in memory location x4000 by the number in memory location x4001 and stores the quotient at x5000 and the remainder at x5001.
Starting with toluene as the only organic starting material : starting with toluene as the only organic starting material and utilizing an organocopper coupling method
Why the alimentary cannalis able to digest starch : why the alimentary cannalis able to digest starch present in cereals and tuber but unable to digest cellulose found in vegetable?
Data from the file grocery.dat : Read the data from the file Grocery.dat and assign values to the 10  GroceryItem  objects. Next display these items to allow a customer to select grocery items from the list and indicate the quantity of that item he or she would like to order. When t..
Which of the following is result of biological magnification : which of the following is the result of biological magnification?
Explain transferred to the organic layer : Compare the amount of A extracted by two extractions using 50 mL of diethyl ether each to the amount extracted by a single 100 mL extraction of the ether. Which is more efficient?
Write out the payoff matrix : If boyh bid the same amount, the $100 is split evenly between them. assume that eac of them has only two $1 bills on hand, leaving three possible bids: $0, $1,or$2 Write out the payoff matrix for this game and then find it's Nash equilibrum
Course scholarly paper on consumer behavior : Assignment: BUS511 (2010E) Course Scholarly Paper, Write 1500 words about consumer behavior of assignment. Writing assignments Course Scholarly Paper not less than 1500 words (excluding the title page, bibliography and appendices).

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd