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

Please save in C. I use notepad++ and cygwin for my programming... You Solution

ID: 3530147 • Letter: P

Question

Please save in C. I use notepad++ and cygwin for my programming... You

Explanation / Answer

#include typedef struct INVENTORY{ int rn; char name[1000]; int q; float cost; struct INVENTORY* next; }inv; inv* I; int size=0; void printinv() { inv* temp = I; printf("Inventory: "); while(temp!=NULL) { printf("%d %s %d %f ",temp->rn,temp->name,temp->q,temp->cost); temp = temp->next; } } boolean addnew(char name[], int q, float cost) { inv* temp = I; while(temp->next != NULL) { temp = temp->next; } inv* node = (inv*)malloc(sizeof(inv)); node->rn = temp->rn+1; strcpy(node->name,name); node->q = q; node->cost=cost; node->next = NULL; temp->next = node; size++; return true; } boolean updateq(int q, int rn) { inv* temp = I; while(temp != NULL) { if(temp-> rn == rn) break; temp = temp->next; } if(temp==NULL) return false; temp -> q = q; return true; } boolean updatecost(float cost, int rn) { inv* temp = I; while(temp != NULL) { if(temp-> rn == rn) break; temp = temp->next; } if(temp==NULL) return false; temp -> cost = cost; return true; } int main() { printf("Enter the filename: "); char file[1000]; scanf("%s",file); FILE* fp = fopen(file,"r"); int cn,q; char name[1000]; float cost; while(1) { if(fscanf(fp,"%d",&cn) == EOF) break; fscanf(fp,"%s",name); fscanf(fp,"%d",q); fscanf(fp,"%f",cost); inv* node = (inv*)malloc(sizeof(inv)); node->rn = temp->rn+1; strcpy(node->name,name); node->q = q; node->cost=cost; node->next = NULL; I->next = node; size++; } fclose(fp); int choice; while(1) { printf("PRESS 1 for view Inventory "); printf("PRESS 2 to add a new Item "); printf("PRESS 3 to update quantity of an Item "); printf("PRESS 4 to update cost of an Item "); printf("PRESS 0 to EXIT "); printf("ENTER YOUR CHOICE ") scanf("%d",&choice); switch(choice) { fp = fopen(file,"w"); case 0: while(I!=NULL) { fprintf(fp,"%d %s %d %f ",I->cn,I->name,I->q,I->cost); I = I->next; } fclose(fp); return 1; case 1: printinv(); break; case 2: printf("Enter the name quantity and cost of this new item "); scanf("%s",name); scanf("%d",&q); scanf("%f",&cost); addnew(name,q,cost); break; case 3: printf("Enter the unique id and quantity of the item ") scanf("%d%d",&cn,&q); if(updateq(q,cn)) printf("Update Successful "); else printf("Update Failed "); break; case 4: printf("Enter the unique id and cost of the item ") scanf("%d%f",&cn,&cost); if(updatecost(cost,cn)) printf("Update Successful "); else printf("Update Failed "); break; default: printf("Please Enter a Valid Choice "); } } 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