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

C PROGRAM HELP! With this assignment you will start to learn how to write a prac

ID: 3764033 • Letter: C

Question

C PROGRAM HELP!

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.

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:

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.

Instructions:

You should useat 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 records. 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 variables (20 point penalty)

You should use a #define to set the upper bound of the list to 50 entries.

Your code should be well designed, well commented and written with good style.

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 records. 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 variables (20 point penalty)

You should use a #define to set the upper bound of the list to 50 entries.

Your code should be well designed, well commented and written with good style.

Explanation / Answer

#include<stdio.h>
struct student
{
int regno;
char name[30];
float grades;
}stud;

void insert()
{
FILE *fp;
fp=fopen("Record","a");
printf("Enter the regno :");
scanf("%d",&stud.regno);
printf("Enter the Name :");
scanf("%s"&stud.name);
printf("Enter the grades :");
scanf("%f",&stud.grades);
fwrite(&stud,sizeof(stud),1,fp);
fclose(fp);
}

void disp()
{
FILE *fp1;
fp1=fopen("Record","r");
printf(" Roll Number name Grades ");
while(fread(&stud,sizeof(stud),1,fp1));
printf("%d %s %.2f ",stud.regno,stud.name,stud.grades);
fclose(fp1);
}

void search()
{
FILE *fp2;
int r,s,avl;
printf(" Enter the Register no you want to search :");
scanf("%d",&r);
avl=avlregno(r);
if(avl==0)
printf("Roll No %d is not avilable in the file ");
else
{
fp2=fopen("Record","r");
while(fread(&stud,sizeof(stud),1,fp2))
{
s=stud.regno;
if(a==r)
{
printf(" Roll no = %d",stud.regno);
printf(" Name = %s"stud.name);
printf(" Grades = %.2f",stud.grades);
}
}
fclose(fp2);
}
}

void deletef()
{
FILE *fp;
FILE *fpt;
int r,s;
printf("Enter the Register no you want to delete :");
scanf("%d",&r);
if(avlregno(r)==0)
printf("Register no %d is not available in the file ");
else
{
fpo=fopen("Record","r");
fpt=fopen("TempFile","w");
while(fread(&stud,sizeof(stud),1,fpo))
{
a=stud.regno;
if(s!=r)
fwrite(&stud,sizeof(stud),1,fpt);
}
fclose(fpo);
fclose(fpt);
fpo=fopen("Record","w");
fpt=fopen("TempFile","r");
while(fread(&)stud,sizeof(stud),1,fpt)
fwrite(&stud,sizeof(stud),1,fpo);
printf(" RECORD DELETE ");
}
fclose(fpo);
fclose(fpt);
}

void update()
{
int avl;
FILE *fpt;
FILE *fpo;
int s,r,ch;
printf("enter Register number to update");
scanf("%d",&r);
avl=avlregno(r);
if(avl==0)
{
printf("roll number %d is not Available in the file",r);
}
else
{
fpo=fopen("Record","r");
fpt=fopen("TempFile","w");
while(fread(&stud,sizeof(stud),1,fpo))
{
s=stud.regno;
if(s!=r)
fwrite(&stud,sizeof(stud),1,fpt);
else
{
printf(" 1_UPDATE THE NAME OF REGISTER NUMBER %d",r);
printf(" 1_UPDATE THE GRADE OF REGISTER NUMBER %d",r);
printf(" 1_UPDATE BOTH NAME AND GRADE OF ROLL NUMBER %d",r);
PRINTF("NN eNTER YOUR CHOICE");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter Name : ");
scanf("%d",stud.name);
` break;
case 2:
printf("Enter Grades : ");
scanf("%d",&stud.grades);
break;
case 3:
printf("Enter Name and Grades: ");
scanf("%d",stud.name,&stud.grades );
break;
default:
printf("Invalid Selection");
break;
}
fwrite(&stud,sizeof(stud),1,fpt);
}
}
fclose(fpo);
fclose(fpt);
fpo=fopen("Record","w");
fpt=fopen("TempFile","r");
while(fread(&stud,sizeof(stud),1,fpt))
{
fwrite(&stud,sizeof(stud),1,fpo);
}
fclose(fpo);
fclose(fpt);
printf("RECORD UPDATED");
}
}

void sort()
{
int a[20],count=0,i,j,t,c;
FILE *fpo;
fpo=fopen("Record","r");
while(fread(&stud,sizeof(stud),1,fpo))
{
a[count]=stud.regno;
count++;
}
c=count;
for(i=0;i<count-1;i++)
{
for(j=i+1;j<count;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("Roll no. Name Grad ");
count=c;
for(i=0;i<count;i++)
{
rewind(fpo);
while(fread(&stud,sizeof(stud),1,fpo))
{
if(a[i]==stud.regno)
printf(" %d %s %2f",stud.name,stud.grades);
}

int avLregno(int rno)
{
FILE *fp;
int c=0;
fp=fopen("Record","r");
while(!feof(fp))
{
fread(& NAME :shahul regno:46 stud,sizeof(stud),1,fp);
if(rno==stud.regno)
{
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}

int empty()
{
int c=0;
FILE *fp;
fp=fopen("Record","r");
while(fread(&stud,sizeof(stud),1,fp))
c=1;
fclose(fp);
return c;
}

{
int c,emp,empty();
do
{
printf(" ---Select your choice--------- ");
printf(" 1. INSERT 2.DISPLAY 3. SEARCH");
printf(" 4. DELETE 5.UPDATE 6.SORT");
printf(" 7. EXIT");
printf(" ------------------------------------------ ");
printf(" Enter your choice:"0;
scanf("%d",&c);
printf(" ");
switch(c)
{
case 1:
insert();
break;
case 2
emp=empty();
if(emp==0)
printf(" The file is EMPTY ");
else
disp();
break;
case 3:
search();
break;
case 4:
delete();
break;
case 5:
update();
break;
case 6:
emp=empty();
ifemp==0()
printf(" The file is EMPTY ");
else
sort();
break;
case 7:
exit(0);
default:
printf(" Your choice is wrong Please try again... ");
break;

}
}while(c!=7);
}