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

  Program to next the loops in either direction

You can write your program to next the loops in either direction, that is, process row-by-row or column-by-column. Explain which way you would choose to process the data.

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Implement method to advance any given date by one day

Write C++ implementation of this method. Create and specify any other methods that you require. Include comments which will be helpful to someone who will maintain implementation in the future.

  Program to compute surface area of sphere using function

Write down a program in C++ to compute surface area of sphere using a function. As sample run, write down the surface areas of spheres with radii.

  Program to compute gross wages for employee using array

Write program which uses the following arrays: payRate: array of seven floats to hold each employee's hourly pay rate. wages: array of seven floats to hold each employee's gross wages.

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  Include the iostream, fstream, string, and cctype libraries

1. Include the iostream, fstream, string, and cctype libraries in your program.

  Writing function that computes leap years

Write down function that computes leap years. Function prototype is as follows: Write function body which returns true if year is a leap year and false if year is not a leap year.

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  C programme to find the minimum and maximum value

write a c programme to find the minimum and maximum value each elements in each row ,to create table b,having 5 rows and 2 coloums,the first coloum of table b is the maximumvalue and thye second coloum is the maximum value in each row.

  Design class for textbook-data field for grade level of book

Design a class named TextBook that is child class of Book. Include new data field for grade level of book. Create a displayTextBookInfo () method so that you can accommodate new grade-level field.

  Develop a simple poker game

Develop a simple poker game

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