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

INTRODUCTION The goal of this assignment is to enable students to practice progr

ID: 3534157 • Letter: I

Question

INTRODUCTION

The goal of this assignment is to enable students to practice programming using arrays and functions in C++. In particular, the program has three parallel arrays that are passed as parameters to functions. The data in the arrays comes from a file and keyboard input. PROBLEM

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.

PROGRAMMING STYLE REQUIREMENTS

Your program will have five functions namely main(), readInventory(), inputNewProducts(), sortInventory(), and printReport().

main()

Your main function will declare the three arrays and a variable to keep track of how many products are in the inventory. Please choose a reasonable size such as 100 for the arrays. A call to the readInventory() function will be made passing the three arrays and a

reference parameter of number_of_products. The user will then be asked if there are new products. If the reply is

Explanation / Answer

#include<iostream.h>

struct info

{

int no;

char name[30];

float price;

}m;

int num[20];

char n[20][30];

float p;


void readinventary();

void newinventary();

void sort();

void printreport();

void main()

{

int ch=1;

while(ch!=0)

{

cout<<"enter your option 1.readinventary.ne entry 3.sort printinfo";

cin>>ch;

switch()

{

case 1:

readinventary();

break;

case 2:

newentry();

break;

case 3:

sort();

break;

case 4:

printreport();

break;

default:

cout<<"enter correct option";

}

}

}


void readinventary()

{

fstream file;

file.open("inventaory.txt");

int i=0;

while(file!=eof)

{

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

num[i]=m.no;

n[i]=m.name;

p[i]=m.price;

}

}


void newentry()

{

cout<<"enter new no name and price";

info mem;

cin>>mem.no>>mem.name>>mem.price";

file.write((*ch)&mem,sizeof(mem));

}


void sort()

{

int i;

info a;

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

{

if(num[i]>num[i+1)

{

a.no=num[i];

num[i]=num[i+1];

num[i+1]=a.no;

a.name=n[i];

n[i]=n[i+1];

n[i+1]=a.name;

a.price=p[i];

p[i]=p[i+1];

p[i+1]=a.price;

}

}

}


void printreport()

{

int i;

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

{

cout<<"stock no "<<num[i]<<" Name "<<n[i]<<" price "<<p[i];

}

}


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