The assignment is to write a menu driven program that manages a small business i
ID: 3568456 • Letter: T
Question
The assignment is to write a menu driven program that manages a small business inventory, collection or list.
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 choose. It may be a menu option that allows the inventory to be modified. i.e. add inventory quantities, change price/cost, change dates, etc.
Explanation / Answer
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef struct inv
{
char style[50];
char brand[25];
int productid;
int quantity;
double cost;
double price;
}soccerBootRus;
//This program is going to be a soccer cleat store. It is going to display all sorts of boots
//available for sale. You will be able to change their quantity, price, and add a new item.
void SetUp(soccerBootRus L[]);
//sets up the 5 entries
void Display(soccerBootRus L[], int num);
//displays inventory
void Save(soccerBootRus L[],int num);
//saves the catalog
void Create(soccerBootRus L[], int *num);
//adds a new catalog
int FindIt(soccerBootRus L[], int *num);
//finds the record you are looking for
void Delete(soccerBootRus L[], int *numentries, int loc);
//deletes an item
void ClearIt(int *num);
//clears entry
void Quit();
//quits program
void Instructions();
//displays instructions
int Edit(soccerBootRus *inventory, int index, soccerBootRus entry);
//edits inventory
void Menu();
int main()
{
int num=5, delNum, editNum;
char choice=' ';
soccerBootRus list[1000];
SetUp(list);
Instructions();
while(1)
{
Menu(&choice);
switch(choice)
{
case 'p':
printf("Data: ----> ");
Display(list, num);
break;
case 's':
Save(list, num);
printf(" Saved successfully ");
break;
case 'a':
Create(list, &num);
break;
case 'd':
printf(" Enter number to delete: ");
scanf("%d", &delNum);
Delete(list, &num, delNum);
break;
case 'c':
ClearIt(&num);
break;
case 'u':
printf(" Enter location to update: ");
scanf("%d", &editNum);
if(editNum <= num)
{
soccerBootRus entry = list[editNum-1];
printf(" Enter new price: ");
scanf(" %lf", &entry.price);
if(Edit(list, editNum, entry))
{
printf(" Edit successfull !! ");
}
else
printf(" Edit un-successfull !! ");
}
else
{
printf("Invalid location to update!!! ");
}
break;
case 'q':
printf(" You will be exited now !! ");
return 0;
default:
printf("did not work ");
break;
}
}
return 0;
}
int Edit(soccerBootRus *inventory, int index, soccerBootRus entry)
{
inventory[index-1] = entry;
return 1;
}
void ClearIt(int *num)
{
*num = 0;
printf(" Data cleared successfully !!! ");
}
void Delete(soccerBootRus L[], int *numentries, int loc)
{
if(loc <= *numentries)
{
int i;
for(i=loc-1; i<(*numentries-1); i++)
{
L[i] = L[i+1];
}
*numentries = *numentries - 1;
printf(" Deleted successfully !! ");
}
else
{
printf("Sorry location invalid !! ");
}
}
void Instructions()
{
printf("Hello and welcome. This program will allow you to create and edit a inventory of soccer shoes ");
printf("To get you started, 5 shoes have already been entered ");
return;
}
void SetUp(soccerBootRus L[])
{
strcpy(L[0].style,"Mercurial Vapor");
strcpy(L[0].brand, "Nike");
L[0].productid=101;
L[0].quantity=10;
L[0].cost=189.95;
L[0].price=145.95;
strcpy(L[1].style,"Magista");
strcpy(L[1].brand, "Nike");
L[1].productid=102;
L[1].quantity=15;
L[1].cost=225.95;
L[1].price=175.95;
strcpy(L[2].style,"Mercurial Superfly");
strcpy(L[2].brand, "Nike");
L[2].productid=103;
L[2].quantity=5;
L[2].cost=245.95;
L[2].price=199.95;
strcpy(L[3].style,"Copa Mundial");
strcpy(L[3].brand, "Adidas");
L[3].productid=201;
L[3].quantity=20;
L[3].cost=134.95;
L[3].price=99.95;
strcpy(L[4].style,"F50");
strcpy(L[4].brand, "Adidas");
L[4].productid=202;
L[4].quantity=18;
L[4].cost=179.95;
L[4].price=155.95;
return;
}
void Menu(char *choice)
{
printf("******************************************* ");
printf("Please select from the options below: ");
printf("P - Display all records ");
printf("S - Create a current report ");
printf("A - Add a new entry ");
printf("D - Delete an item from the list ");
printf("C - Clear all records ");
printf("U - Update the price ");
printf("Q - Quit ");
printf("What would you like to do? ");
scanf(" %c", choice);
}
void Display(soccerBootRus L[], int num)
{
if(num ==0)
{
printf("Sorry No data !! ");
return;
}
int k=1;
int i;
for(i=0; i<num; i++)
{
printf("----Catalog Entry %d---- ", k++);
printf("Style: %s ", L[i].style);
printf("Brand: %s ", L[i].brand);
printf("ID: %d ", L[i].productid);
printf("Cost: %.2f ", L[i].cost);
printf("Price: %.2f ", L[i].price);
}
}
void Create(soccerBootRus L[], int *num)
{
printf(" Enter new data: ");
printf(" Enter Style: ");
scanf(" %s", L[*num].style);
printf("Enter Brand: ");
scanf(" %s", L[*num].brand);
printf("Enter ID: ");
scanf(" %d", &L[*num].productid);
printf("Enter Cost: ");
scanf(" %lf", &L[*num].cost);
printf("enter double: ");
scanf(" %lf", &L[*num].price);
*num+=1;
printf(" Data entered successfully! ");
}
void Save(soccerBootRus L[],int num)
{
int i;
FILE *ptr;
ptr=fopen("file.txt","w");
for(i=0;i<num;i++)
{
fprintf(ptr,"Style: %s ", L[i].style);
fprintf(ptr,"Brand: %s ", L[i].brand);
fprintf(ptr,"ID: %d ", L[i].productid);
fprintf(ptr,"Cost: %f ", L[i].cost);
fprintf(ptr,"Price: %f ", L[i].price);
} fclose(ptr);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.