Question: Write two programs which will work with a structure. a) The first program will use a structure to store the following inventory data in a

Write two programs which will work with a structure.

a) The first program will use a structure to store the following inventory data in a file:

Item Description

Quantity on Hand

Wholesale Cost

Retail Cost

Date Added to Inventory

The program will write five records to an output file for different items; the quantity, costs, and date for each item will be different from the other items.

b) The second program will read the file created by the first program using the same structure. The second program will calculate and display the following information:

total wholesale value of the inventory

total retail value of the inventory

total quantity of all items in the inventory

#include "stdafx.h" #include #include #include using namespace std;

const int DES = 20;

//declare variables void Add(); void Display(); void Edit();

struct Inventory { char item[DES]; int qty; int wcost; int rcost; char date[10]; };

//Main function int main() { int choice; do { cout << "MENU" << endl; cout << "1. Add Record: " << endl; cout << "2. Display Records: " << endl; cout << "Please enter your selection." << endl; cin >> choice;

switch (choice) { case 1: Add(); break; //Add record case 2: Display(); break; //Display record

default: cout << "Invalid Selection" << endl; } } while (choice <= 2);

system("PAUSE"); return 0; }

//Add funtion void Add() { fstream fout; const int size = 3; char ch; int i = 0; fout.open("Records.txt", ios::cout | ios:: app); Inventory inv;

//get data do { cout << "Enter item description: " << endl; cin.ignore(); cin.getline(inv.item, DES); cout << "Enter quantity: " << endl; cin >> inv.qty; cout << "Enter wholesale cost: " << endl; cin >> inv.wcost; cout << "Enter retail cost: " << endl; cin >> inv.rcost; cout << "Enter date: " << endl; cin.ignore(); cin.getline(inv.date, 10); //write record to file fout.write(reinterpret_cast(&inv), sizeof(inv)); cout << "Do you want to add another record? " << endl; cin >> ch; } while (ch == 'Y' && 1 < 3);

//close the file fout.close(); }

//"Display" function void Display() { fstream fout; fout.open("Records.txt", ios::in); Inventory inv; fout.read(reinterpret_cast (&inv), sizeof(inv)); while (!fout.eof()) {

cout << " Description\t: "; cout << inv.item; cout << " Quantity\t: "; cout << inv.qty; cout << " Wholesale Cost\t: "; cout << inv.wcost; cout << " Retail Cost\t: "; cout << inv.rcost; cout << " Date\t: "; cout << inv.date; fout.read(reinterpret_cast (&inv), sizeof(inv)); } //close the file fout.close(); }

ERRORS:

class "std::basic_ios>" has no member "cout"\ 'cout': is not a member of 'std::basic_ios>' binary '|': no operator found which takes a left-hand operand of type 'std::ostream' (or there is no acceptable conversion)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!