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

With this assignment you will start to learn how to write a practical menu drive

ID: 3767542 • Letter: W

Question

With this assignment you will start to learn how to

write a practical menu driven program that manages

a list of data. You will use an array of structs to

organize the data and you will save the informatio

n in a

text file.

The assignment is to write a menu driven program th

at manages a small business inventory, collection

or list. You pick the topic!!! The focus of your pr

ogram is up to you.

The Menu commands must include:

P....Display all records (on the screen/monitor

)

S....Create a current report (save it to a file

)

A....Add a new entry

D....Delete an item from the list (inventory)

C....Clear all records

Q...Quit

You must add (1) additional menu option that you ch

oose.

It may be a menu option that allows the

inventory to be modified. i.e. add inventory quanti

ties, change price/cost, change dates, etc.

You will use structs and an array to organize the d

ata in the program. Your struct must contain at

least the following kinds of information:

o

Minimum of 2 strings (character arrays)

Suggestions include: item name, manufacturer, etc

o

Minimum of 2 integers – 1 must be product id

Product id, qty in stock

o

Minimum of 2 double values

Suggestions include: cost, price, average inventory

:

When you add new item the program will ask the user

for each of the fields on a separate line.

When you delete an item from inventory the program

will ask you for the integer id of the entry to

be deleted, locate the entry in the array and remov

e all of the data for that entry. – The list does n

ot

need to be sorted – to remove an entry, you may mov

e the last item in the list to the location of the

deleted entry

When you display the records on the screen, all of

the information stored for each entry will be

labeled and displayed.

Creating a current inventory report copies the curr

ent entries in the array to an output file. This mu

st

include labeling all of the information so that it

is clear what information is being provided.

Clearing the records deletes all of the information

in the array.

COP2220 – Assignment 4

Instructions:

You should use

at least 8 user-defined functions

(plus main) to appropriately break the problem up

into smaller pieces.

Your program must start up with at least 5 valid re

cords. These records must be “hard coded” in

your program file. (This can be done in one of your

user-defined functions)

You should use function prototypes and NO global va

riables.

This is the sample output:

Sample output:

Hello and welcome. This program helps you create an

inventory for skate shoes.

To get you started, 5 shoes have already been enter

ed.

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q - QUIT

What would you like to do: p

---Catalog Entry 1---

BRAND: Vans

MODEL: Janowski

I.D.#: 101

QTY: 45

COST: $30.00

PRICE: $65.99

---Catalog Entry 2---

BRAND: Vans

MODEL: Authentic

COP2220 – Assignment 4

I.D.#: 102

QTY: 3

COST: $30.00

PRICE: $65.99

---Catalog Entry 3---

BRAND: Vans

MODEL: Era

I.D.#: 103

QTY: 14

COST: $20.00

PRICE: $35.99

---Catalog Entry 4---

BRAND: Nike

MODEL: Koston

I.D.#: 104

QTY: 61

COST: $40.00

PRICE: $85.99

---Catalog Entry 5---

BRAND: DC

MODEL: Nyjah

I.D.#: 105

QTY: 6

COST: $40.00

PRICE: $85.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: a

Enter Brand: Vans

Enter Model: HalfCab

Enter ID: 241

Enter quantity: 200

Enter cost: 65.00

Enter Price: 139.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q - QUIT

What would you like to do: p

---Catalog Entry 1---

BRAND: Vans

MODEL: Janowski

I.D.#: 101

QTY: 45

COP2220 – Assignment 4

COST: $30.00

PRICE: $65.99

---Catalog Entry 2---

BRAND: Vans

MODEL: Authentic

I.D.#: 102

QTY: 3

COST: $30.00

PRICE: $65.99

---Catalog Entry 3---

BRAND: Vans

MODEL: Era

I.D.#: 103

QTY: 14

COST: $20.00

PRICE: $35.99

---Catalog Entry 4---

BRAND: Nike

MODEL: Koston

I.D.#: 104

QTY: 61

COST: $40.00

PRICE: $85.99

---Catalog Entry 5---

BRAND: DC

MODEL: Nyjah

I.D.#: 105

QTY: 6

COST: $40.00

PRICE: $85.99

---Catalog Entry 6---

BRAND: Vans

MODEL: HalfCab

I.D.#: 241

QTY: 200

COST: $65.00

PRICE: $139.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: d

List of ID #'s:

101, 102, 103, 104, 105, 241,

Please enter the I.D.: 102

***************************************

Please select from the options below:

A - ADD a new entry

COP2220 – Assignment 4

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: p

---Catalog Entry 1---

BRAND: Vans

MODEL: Janowski

I.D.#: 101

QTY: 45

COST: $30.00

PRICE: $65.99

---Catalog Entry 2---

BRAND: Vans

MODEL: HalfCab

I.D.#: 241

QTY: 200

COST: $65.00

PRICE: $139.99

---Catalog Entry 3---

BRAND: Vans

MODEL: Era

I.D.#: 103

QTY: 14

COST: $20.00

PRICE: $35.99

---Catalog Entry 4---

BRAND: Nike

MODEL: Koston

I.D.#: 104

QTY: 61

COST: $40.00

PRICE: $85.99

---Catalog Entry 5---

BRAND: DC

MODEL: Nyjah

I.D.#: 105

QTY: 6

COST: $40.00

PRICE: $85.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: u

List of ID #'s:

COP2220 – Assignment 4

101, 241, 103, 104, 105,

Please enter the I.D.: 104

---Catalog Entry 4---

BRAND: Nike

MODEL: Koston

I.D.#: 104

QTY: 61

COST: $40.00

PRICE: $85.99

Please enter the updated price: 75.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: p

---Catalog Entry 1---

BRAND: Vans

MODEL: Janowski

I.D.#: 101

QTY: 45

COST: $30.00

PRICE: $65.99

---Catalog Entry 2---

BRAND: Vans

MODEL: HalfCab

I.D.#: 241

QTY: 200

COST: $65.00

PRICE: $139.99

---Catalog Entry 3---

BRAND: Vans

MODEL: Era

I.D.#: 103

QTY: 14

COST: $20.00

PRICE: $35.99

---Catalog Entry 4---

BRAND: Nike

MODEL: Koston

I.D.#: 104

QTY: 61

COST: $40.00

PRICE: $75.99

---Catalog Entry 5---

BRAND: DC

MODEL: Nyjah

I.D.#: 105

QTY: 6

COP2220 – Assignment 4

COST: $40.00

PRICE: $85.99

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q - QUIT

What would you like to do: c

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: p

*****Catalog is empty*****

***************************************

Please select from the options below:

A - ADD a new entry

D - DELETE an entry

P - PRINT entire catalog

S - SAVE the current catalog

C - CLEAR the entire catalog

U - UPDATE the price

Q – QUIT

What would you like to do: q

Goodbye.

Press any key to continue

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_ENTRIES 50

typedef struct{
    char name[20];
    char brand[20];
    int id;
    int stock;
    double price;
    double avginventory;
    } purse;

void initializeEntries(purse list[],int *size)
{
     strcpy(list[0].name,"Flemming_Tote");
     strcpy(list[0].brand,"Tori_Burch");
     list[0].id=100;
     list[0].stock=101;
     list[0].price=500;
     list[0].avginventory=200.2;
    
     strcpy(list[1].name,"Marion_Crossbody");
     strcpy(list[1].brand,"Tori_Burch");
     list[1].id=101;
     list[1].stock=101;
     list[1].price=300;
     list[1].avginventory=200.2;
    
     strcpy(list[2].name,"Adalyn_Clutch");
     strcpy(list[2].brand,"Tori_Burch");
     list[2].id=102;
     list[2].stock=101;
     list[2].price=325;
     list[2].avginventory=200.2;
    
     strcpy(list[3].name,"Robinson_Bag");
     strcpy(list[3].brand,"Tori_Burch");
     list[3].id=103;
     list[3].stock=101;
     list[3].price=365;
     list[3].avginventory=200.2;
    
     strcpy(list[4].name,"Elise_Satchel");
     strcpy(list[4].brand,"Tori_Burch");
     list[4].id=104;
     list[4].stock=101;
     list[4].price=595;
     list[4].avginventory=200.2;
    
     *size=5;                          
     return;
}   
char menu(){
     char sel;
     printf(" *************************************** ");
     printf("Please select from the options below: ");
     printf("A - ADD a new entry ");
     printf("D - DELETE an entry ");
     printf("P - PRINT entire catalog ");
     printf("S - SAVE the current catalog ");
     printf("C - CLEAR the entire catalog ");
     printf("U - UPDATE the price ");
     printf("Q - QUIT ");
     printf("What would you like to do: ");
     scanf(" %c",&sel);
     return sel;
}

void addEntry(purse list[],int *size)
{
     printf(" Enter name : ");
     scanf("%s",list[*size].name);
     printf(" Enter brand : ");
     scanf("%s",list[*size].brand);
     printf(" Enter id : ");
     scanf("%d",&list[*size].id);
     printf(" Enter stock : ");
     scanf("%d",&list[*size].stock);
     printf(" Enter price : ");
     scanf("%lf",&list[*size].price);
     printf(" Enter average inventory : ");
     scanf("%lf",&list[*size].avginventory);
     (*size)++;
     return;   
}
void deleteEntry(purse list[],int *size)
{
     int i, id;
     printf("List of ID #'s: ");
     for(i=0;i<*size;i++)
     printf("%d ",list[i].id);
     printf(" Please enter the I.D.: ");
     scanf("%d",&id);
     for(i=0;i<*size;i++)
     {
          if(list[i].id == id)
          {
                strcpy(list[i].brand,list[*size-1].brand);
                strcpy(list[i].name,list[*size-1].name);
                list[i].id = list[*size-1].id;  
                list[i].stock = list[*size-1].stock;
                list[i].price = list[*size-1].price;
                list[i].avginventory = list[*size-1].avginventory;
                (*size)--;
                break;
          }
     }                  
     return;
}
void display(purse list[],int *size)
{    
     int i;
     if(*size==0)printf("*****Catalog is empty***** ");
     for(i=0;i<*size;i++)
     {
        printf("---Catalog Entry %d--- ",i+1);
        printf("BRAND: %s ",list[i].brand);
        printf("NAME: %s ",list[i].name);
        printf("I.D.#: %d ",list[i].id);
        printf("QTY:    %d ",list[i].stock);
        printf("PRICE:   $%.2lf ",list[i].price);
        printf("AVERAGE INVENTORY: $%,2lf ",list[i].avginventory);            
     }                  
     return;
}
void createReport(purse list[],int *size)
{
     FILE *f;
     int i;
     f=fopen("Records.txt","w");
     if (f == NULL)
     {
        printf("Error opening file! ");
        exit(1);
     }
     if(*size==0)
           fprintf(f,"*****Catalog is empty***** ");
     for(i=0;i<*size;i++)
     {                           
          fprintf(f, "---Catalog Entry %d--- ",i+1);
          fprintf(f,"BRAND: %s ",list[i].brand);
          fprintf(f,"NAME: %s ",list[i].name);
          fprintf(f,"I.D.#: %d ",list[i].id);
          fprintf(f,"QTY:    %d ",list[i].stock);
          fprintf(f,"PRICE:   $%.2lf ",list[i].price);
          fprintf(f,"AVERAGE INVENTORY: $%.2lf ",list[i].avginventory);       
     }
     fclose(f);  
     return;
}
void clearRecords(purse list[],int *size)
{   
     *size=0;
     return;
}
void update(purse list[],int *size)
{   
     int i,id;
     double price_up;
     printf("List of ID #'s: ");
     for(i=0;i<*size;i++)
     printf("%d ",list[i].id);
     printf(" Please enter the I.D.: ");
     scanf("%d",&id);
     for(i=0;i<*size;i++)
     {
           if(list[i].id==id)
           {
                printf("---Catalog Entry %d--- ",i+1);
                printf("BRAND: %s ",list[i].brand);
                printf("NAME: %s ",list[i].name);
                printf("I.D.#: %d ",list[i].id);
                printf("QTY:    %d ",list[i].stock);
                printf("PRICE:   $%.2lf ",list[i].price);
                printf("AVERAGE INVENTORY: $%.2lf ",list[i].avginventory);   
                printf("Please enter the updated price: ");
                scanf("%lf",&price_up);
                list[i].price = price_up;
                break;
           }
     }             
     return;    
}
int main(){   
    purse list[MAX_ENTRIES];
    int size=0;
    initializeEntries(list,&size);
    printf("Hello and welcome. This program helps you create an inventory for skate shoes. ");
    printf("To get you started, 5 shoes have already been entered. ");
    while(1){
        char sel=menu();
        if(sel=='A' || sel=='a'){
             addEntry(list,&size);
        }
        else if(sel=='D' || sel=='d'){
             deleteEntry(list,&size);
        }
        else if(sel=='P' || sel=='p'){
              display(list,&size);
        }
        else if(sel=='S' || sel=='s'){
             createReport(list,&size);
        }
        else if(sel=='C' || sel=='c'){
             clearRecords(list,&size);
        }
        else if(sel=='U' || sel=='u'){
             update(list,&size);
        }
        else if(sel=='Q' || sel=='q'){
            printf("Goodbye. ");
            break;
        }
        else printf("Enter a valid command ");
    }
    return 0;    
}

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