With this assignment you will start to learn how to write a practical menu drive
ID: 3692375 • 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 information in a text file.
Choose one of the following program types:
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.
You will use structs and an array to organize the data in the program. Your struct must contain at least the following kinds of information:
Minimum of 2 strings (character arrays)
Suggestions include: item name, manufacturer, etc
Minimum of 2 integers – 1 must be product id
Product id, qty in stock
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 remove all of the data for that entry. – The list does not need to be sorted – to remove an entry, you may move 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 current entries in the array to an output file. This must 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.
When you add new item the program will ask the user for each of the fields on a separate line.
When you delete a question from the list, the program will ask you for the question id of the entry to be deleted, locate the entry in the array and remove all of the data for that entry. – The list does not need to be sorted – to remove an entry, you may move the last item in the list to the location of the deleted entry
When you play the game, you must display the question, the possible answers and the point value. If the player answers correctly the point value will be added to the game total. If answered incorrectly, the correct answer will be displayed.
Creating a current report copies the current content of the question array to an output file. This must include labeling all of the information so that it is clear what information is being provided.
Clearing all questions deletes all of the information in the array.
Instructions:
You should use at least 10 user-defined functions (plus main) to appropriately break the problem up into smaller pieces.
Your program must start up with at least 5 valid records or questions. These records must be “hard coded” in your program file. (This can be done in one of your user-defined functions)
You need to begin the program with general instructions on your program, an outline of the data fields and the format needed to enter the data
You should use function prototypes and NO global variables.
You should use a #define to set the upper bound of the list to at least 50 entries.
Your code should be well designed, well commented and written with good style.
Other Important Hints and Reminders:
Start work on this as soon as possible.
You are expected to receive as much help as you need for the basic assignment.
It is your responsibility to request this help in the form of specific questions.
You may ask these questions during office hours or by sending them via email to me and the TA.
When you ask a question, it should be specific, and you should provide the current version of your program.
The current version of your program should be neatly formatted and commented. It should also be properly indented and use meaningful variable and function names. This will make it easier for anyone helping you to understand what you are trying to do.
Explanation / Answer
Ans;
#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.