Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The owner of a small grocery store wants to computerize inventory records. You a

ID: 3535166 • Letter: T

Question

The owner of a small grocery store wants to computerize inventory records. You are requested to

write a program that will maintain a file called inventory.dat that will have product name,

number in stock, and selling price on separate lines. Here is an example of what contents of the

file can look like:

Milk

145 1.10

Peanuts

324 4.00

Ice cream

75 5.55

Bar soap

1000 0.27

Laundry Detergent

200 5.15

Dishwashing Liquid

150 2.99

Sugar

600 1.35

Rice

40 1.65

Orange Juice

65 2.91

Paper Towels

350 2.65

Coffee

300 6.00

Canned Beans

2300 0.36

Your program will first read the file so that the first column (product names) goes into an array

of type string, the second column (number in stock) goes into an array of type integer, and the

third column (selling price) goes into an array of type float.

The program will then ask the user if there are new products to be added to the file. The new

products will be read from the keyboard and written to the file.

Next, the program will sort the product names in alphabetical order while maintaining the correct

numbers in stock and selling prices. In other words, sort the three arrays together.

Finally, a four column display of the contents of the arrays will be displayed with the final

column containing calculated values of number_in_stock*selling_price.

Explanation / Answer

#include<iostream.h>

#include<conio.h>

struct info

{

char name[40];

int num;

float price;

};

void main()

{

fstream file;

file.open("inventary.dat");

info a;

char name[30][40];

int n[30];

float p[40];

for(int i=0;(file!=eof);i++) // data get store in different array...

{

a=file.read((*ch)&a,sizeof(a));

name[i]=a.name;

n[i]-a.num;

p[i]=a.price;

}


//new entry;

cout<<"enter name price and quantity of a item ";

cin>>name[i]>>p[i]>>n[i];

char temp[40];

int t;

float t1;

for(int j=0;j<i+1;j++)

{

temp=name[j];

t=n[j];

t1=p[j];

for(int k=j;k<i;k++)

{

if(temp>name[k]) //sorting is done by ASCII value of character...

{

temp=name[k];

t1=p[k];

t=n[k];

name[j]=name[k];

name[k]=temp;

p[j]=p[k];

p[k]=t1;

n[j]=n[k];

n[k]=t;

}

}

}

cout<<"sorted entryies are......";

for(j=0;j<i;j++)

{

cout<<"name "<<name[j]<<" stock "<<n[i]<<" price is "<<p[j]<<" ";

}

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote