I really need help with this Assignment Please in C programm
I really need help with this Assignment Please in C programming not C++ or C#, just C. Thank you!
Hello , Choose please one of the following program types:
The assignment is to write a menu driven program that manages a small business inventory, collection or list. You pick the topic. The focus of your program 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 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: 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 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.
Solution
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXIMUM_ENTRIES 50
typedef struct{
char prod_name[20];
char brand[20];
int prod_id;
int stock;
double price;
double avginventory;
} purse;
void initializeEntries(purse list[],int *size)
{
strcpy(list[0].prod_name,\"Goodday cashew\");
strcpy(list[0].brand,\"Goodday\");
list[0].prod_id=100;
list[0].stock=101;
list[0].price=500;
list[0].avginventory=200.2;
strcpy(list[1].prod_name,\"Goodday butter\");
strcpy(list[1].brand,\"Goodday\");
list[1].prod_id=101;
list[1].stock=101;
list[1].price=300;
list[1].avginventory=200.2;
strcpy(list[2].prod_name,\"Salt&Pepper\");
strcpy(list[2].brand,\"Goodday\");
list[2].prod_id=102;
list[2].stock=101;
list[2].price=325;
list[2].avginventory=200.2;
strcpy(list[3].prod_name,\"BadamwithPista\");
strcpy(list[3].brand,\"Goodday\");
list[3].prod_id=103;
list[3].stock=101;
list[3].price=365;
list[3].avginventory=200.2;
strcpy(list[4].prod_name,\"Sweet&Salt\");
strcpy(list[4].brand,\"Goodday\");
list[4].prod_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 on of 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(\"Which option you want to select: \");
scanf(\" %c\",&sel);
return sel;
}
void addEntry(purse list[],int *size)
{
printf(\"\ Enter name : \");
scanf(\"%s\",list[*size].prod_name);
printf(\"\ Enter brand : \");
scanf(\"%s\",list[*size].brand);
printf(\"\ Enter id : \");
scanf(\"%d\",&list[*size].prod_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, prod_id;
printf(\"List of ID #\'s:\ \");
for(i=0;i<*size;i++)
printf(\"%d \",list[i].prod_id);
printf(\"\ Please enter the I.D.: \");
scanf(\"%d\",&prod_id);
for(i=0;i<*size;i++)
{
if(list[i].prod_id == prod_id)
{
strcpy(list[i].brand,list[*size-1].brand);
strcpy(list[i].prod_name,list[*size-1].prod_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].prod_name);
printf(\"I.D.#: %d\ \",list[i].prod_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].prod_name);
fprintf(f,\"I.D.#: %d\ \",list[i].prod_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,prod_id;
double price_up;
printf(\"List of ID #\'s:\ \");
for(i=0;i<*size;i++)
printf(\"%d \",list[i].prod_id);
printf(\"\ Please enter the I.D.: \");
scanf(\"%d\",&prod_id);
for(i=0;i<*size;i++)
{
if(list[i].prod_id==prod_id)
{
printf(\"---Catalog Entry %d---\ \",i+1);
printf(\"BRAND: %s\ \",list[i].brand);
printf(\"NAME: %s\ \",list[i].prod_name);
printf(\"I.D.#: %d\ \",list[i].prod_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 Biscuits.\ \");
printf(\"To get you started, 5 brands of biscuits 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 Option\ \");
}
return 0;
}




