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

  Smallest sequence of numbers in the array

Write a function called sum_smallest_sequence() that accepts an array of  signed  integers and the  number  of items in the array as arguments, and returns the sum of the smallest sequence of numbers in the array.

  Iterative programming problem solving approaches

Write a recursive function void reverse ( ) that reverse a sentence

  Time conversion

Write a C++ program that takes an Eastern standard time in hours, minutes, and seconds,and prints it out in Central time, Mountain time, or Pacific time.

  Program to declare array alpha of components of type int

Write C++ statements to do the following: Declare an array alpha of 15 components of the type int. Output the value of the tenth component of the array alpha.

  Write a program that will be used to gather statistical data

Write a program that will be used to gather statistical data about the number of movies

  Problems on oops

Problems on OOPS

  Write c program to find smallest-largest values

Write a program c that will find the smallest, largest and average values in a collection of N numbers.Get the value of N before scanning each value in the collection of N numbers.

  Ruby implement primitive types

How does Ruby implement primitive types, such as those for integer and floating-point data?  3-What is the single most important practical difference between Smalltalk and C++?

  Write a function that takes an integer array

1. Write a function that takes an integer array and the array's size as parameters. The function will check if the array is sorted. If it is, it will return a 1. If it is not sorted it will return 0. The function should not  sort the array.

  Wrtie a function called gen_rand_double_array

Wrtie a function called gen_rand_double_array that generates 900 samples of size 22500 random numbers from U(10, 12). For each of these 900 samples, write a main funciton that calculates the mean and finds the simulated probability that the mean is b..

  Build a traffic light system - microcontroller system

Build the whole system with 3 RAG units and three puffin crossing units and build a team to work on this mini-project, be careful in selecting your team member.

  Implementation of data member counter of type int

Write the implementation (.cpp file) of Counter class. Here is the full specification of the class: A data member counter of type int.

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