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: 3764317 • 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>
#include <conio.h>

struct biodata{
int recno,age;
char name[20],gender;
float salary;
};


void main(){
void addData(void);
void delData(void);
void showAll(void);
void showRecord(void);
void alterData(void);

char choice;
clrscr();

while(1){
clrscr();
textcolor(BLACK);
cprintf(" B I O - D A T A ");
printf(" *****CHOOSE YOUR CHOICE***** ");
printf("1) ADD DATA ");
printf("2) DELETE DATA ");
printf("3) SHOW ALL ");
printf("4) SHOW RECORD ");
printf("5) ALTER DATA ");
printf("6) Exit ");
printf("Enter your choice : ");
fflush(stdin);
choice = getche();
switch(choice){
case'1' : // add data
addData();
break;
case'2' : // delete databreak;
case'3' : //call show all data
showAll();
break;
case'4' : // show record
showRecord();
break;
case'5' : // alter databreak;
case'6' :
case 27 : clrscr();
gotoxy(25,10);
_setcursortype(_NOCURSOR);
textcolor(LIGHTMAGENTA);
cprintf("THANKS ");
getch();
exit(1);
}
}

}


{
FILE *fp;
struct biodata obj;
fp = fopen("biodata.txt","a+t");
clrscr();
printf(" *****ADDING DATA***** ");
printf(" Enter Record No : ");
scanf("%d",&obj.recno);
printf("Enter Name : ");
fflush(stdin);
scanf("%s",obj.name);
printf("Enter age : ");
scanf("%d",&obj.age);
fflush(stdin);
printf("Enter gender : ");
scanf("%c",&obj.gender);
printf("Enter Salary : ");
scanf("%f",&obj.salary);
fscanf(stdin,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.gender,&obj.salary);
fprintf(fp,"%d %s %d %c %f",obj.recno,obj.name,obj.age,obj.gender,obj.salary);
fclose(fp);
}

void showRecord()
{
FILE *fp;
struct biodata obj;
int rec;
long pos;
fp = fopen("biodata.txt","r");
clrscr();
printf(" *****SHOWING SPECIFIC RECORD***** ");
printf(" Enter Record No : ");
scanf("%d",&rec);
pos = rec * sizeof(obj);
fseek(fp,pos,SEEK_SET);
if(feof(fp)==0)
printf(" NO DATA FOUND ");
else{
fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.gender,&obj.salary);
printf(" Record No : %d ",obj.recno);
printf(" Name : %s ",obj.name);
printf(" Age : %d ",obj.age);
printf(" Gender : %c ",obj.gender);
printf(" Salary : %f ",obj.salary);
}
getch();
fclose(fp);
}


void showAll(){
FILE *fp;
struct biodata obj;
int totrec,i;
fp = fopen("biodata.txt","r");
clrscr();
fseek(fp,0,SEEK_END);
totrec=ftell(fp)/sizeof(obj);
printf(" *****SHOWING ALL RECORD***** ");
printf(" Record_No Name Age Gender Salary ");
printf(" %d ",totrec);
for(i=1;i<=totrec;i++){
fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.gender,&obj.salary);
fprintf(stdout,"%-15d %-15s %-8d %-2c %10.2f ",obj.recno,obj.name,obj.age,obj.gender,obj.salary);
}
getch();
fclose(fp);
}