Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can You please check this code i can't delete information student.somthing error with this and can't find a bug in this code. please our deadline

Can You please check this code i can't delete information student.somthing error with this and can't find a bug in this code. please our deadline is today so please help us.
#include
#include
#include
struct students{
char name[100];
char sex[100];
char id[100];
char age[100];
char grade[100];
int i;
char score[100];
char tel[100];
float math;
float physic;
float computer;
float khlanguage;
float history;
float sum;
float avg;
float mix;
};
struct students pd[100];
int i,n;
char filename[50];
void add(char filename[] ){
FILE*fa;
printf(" \tEnter user name: ");
scanf("%s",&pd[n].name);
printf("\tEnter id: ");
scanf("%s",&pd[n].id);
printf("\tEnter sex:");
scanf("%s",&pd[n].sex);
printf("\tEnter Student age: ");
scanf("%s",&pd[n].age);
printf("\tEnter user grade: ");
scanf("%s",&pd[n].grade);
printf("\tEnter telephone (+885): ");
scanf("%s",&pd[n].tel);
i++;
fa = fopen("student22.txt","a");
fprintf(fa,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
fprintf(fa," " );
fclose(fa);
}
//function to search information of students by id
void search(char filename[]){
char id[100];
FILE*fs;
int flag=0;
fs = fopen("student22.txt","r");
printf("\t-------------------------------------------------------------------- ");
printf(" \tSEARCH ID:"); scanf("%s",id);
printf("\t-------------------------------------------------------------------- ");
printf("\tName\tid\tsex\tage\tgrade\ttelephone ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(fs,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
i++;
if(strcmp(pd[n].id,id)==0){
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
flag=1;
}
}
if(flag==0){
printf("\t*****NOT FOUND*****");
}
fclose(fs);
}
// function for display all students information
void disply_information(char filename)
{
FILE*fd;
int i;
fd=fopen("student22.txt","r");
printf("\t-------------------------------------------------------------------- ");
printf("\tName\tid\tsex\tage\tgrade\ttelephone ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(fd,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
i++;
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel);
printf("\t-------------------------------------------------------------------- ");
}
fclose(fd);
}
// function for delete students informations
void dalete(char filename){
FILE*f1 ;
int id[100],f=0,j;
int flag=0;
f1=fopen("student22.txt","r");
printf("\tEnter ID :");scanf("%s",id);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
if(strcmp(pd[n].id,id)==0){
flag=1;
strcpy(pd[n].id,pd[n+1].id);
strcpy(pd[n].name, pd[n+1].name);
strcpy(pd[n].sex,pd[n+1].sex);
strcpy(pd[n].age,pd[n+1].age);
strcpy(pd[n].grade,pd[n+1].grade);
strcpy(pd[n].tel,pd[n+1].tel);
printf(" \t\t---<<<<*** DALETE IS DONE ***>>>>--- ");
}
}if(flag==0){
printf(" \t\t<<<<<*** Student not Found ***>>>>>> ");
}
fclose(f1);
}
// functions for add score students information
void add_score(char filename)
{
int k;
char id[100];
FILE*fs,*f1;
f1= fopen("student22.txt","r");
fs=fopen("score22.txt","a");
int status=0;
printf("\tmath\tphysic\tcomputer\tkh\thistory\t ");
printf("\t-------------------------------------------------------------------- ");
printf("\tEnter id: ");scanf("%s",id);
while(fscanf(f1,"\t%s\t%s\t%s\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex,pd[n].age,pd[n].grade,pd[n].tel)!=EOF){
if(strcmp(pd[i].id,id)==0){
status=1;
printf(" \tEnter the math score: ");
scanf("%f",&pd[i].math);
printf("\tEnter the physic score: ");
scanf("%f",&pd[i].physic);
printf("\tEnter the computer score: ");
scanf("%f",&pd[i].computer);
printf("\tEnter the khmerlanguage score: ");
scanf("%f",&pd[i].khlanguage);
printf("\tEnter the history score: ");
scanf("%f",&pd[i].history);
pd[i].sum=pd[i].math + pd[i].physic + pd[i].computer + pd[i].khlanguage + pd[i].history;
pd[i].avg=pd[i].sum/5;
printf("\t*****UPDATE IS DONE***** ");
fprintf(fs," \t%s\t%s\t%2.f\t%2.f\t%2.f\t\t%2.f\t%2.f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history);
fprintf(fs," The Score of all subject: %f",pd[i].sum);
fprintf(fs," The Average is : %f",pd[i].avg);
break;
}
}
if (status==0)
{
printf("\t*****NOT FOUND*****");
}
fclose(f1);
fclose(fs);
}
// update students informations
void update_students_information()
{
char id[100];
int status=0;
printf("\tName\tid\tsex\tage\tgrade\ttelephone ");
printf("\t-------------------------------------------------------------------- ");
printf("\tEnter id: ");scanf("%s",id);
for(int i=0 ;i
{
if(strcmp(pd[i].id,id)==0)
{
status=1;
printf(" \tNew user name: "); scanf("%s",&pd[i].name);
printf("\tNew id: "); scanf("%s",&pd[i].id);
printf("\tNew sex:"); scanf("%s",pd[i].sex);
printf("\tNew Student age: "); scanf("%s",&pd[i].age);
printf("\tNew user grade: "); scanf("%s",&pd[i].grade);
printf("\tNew telephone (+885): "); scanf("%s",&pd[i].tel);
printf("\t*****UPDATE IS DONE***** ");
break;
}
}
if (status==0)
{
printf("\t*****NOT FOUND*****");
}
}
void up_score()
{
char id[100];
int status=0;
printf("\tmath\tphysic\tcomputer\tkh\thistory\t ");
printf("\t-------------------------------------------------------------------- ");
printf("\tEnter id: ");scanf("%s",id);
for(int i=0 ;i
{
if(strcmp(pd[i].id,id)==0)
{
status=1;
printf(" \tEnter the math score: ");
scanf("%f",&pd[i].math);
printf("\tEnter the physic score: ");
scanf("%f",&pd[i].physic);
printf("\tEnter the computer score: ");
scanf("%f",&pd[i].computer);
printf("\tEnter the khmerlanguage score: ");
scanf("%f",&pd[i].khlanguage);
printf("\tEnter the history score: ");
scanf("%f",&pd[i].history);
pd[i].sum=pd[i].math + pd[i].physic + pd[i].computer + pd[i].khlanguage + pd[i].history;
pd[i].avg=pd[i].sum/5;
printf("\t*****UPDATE IS DONE***** ");
break;
}
}
if (status==0)
{
printf("\t*****NOT FOUND*****");
}
}
// function for display score students information
void display_scorc_studentd(){
FILE*f;
f=fopen("score22.txt","r");
printf("\tid\tname\tmath\tphysic\tcomputer\tkh\thistory\t ");
printf("\t-------------------------------------------------------------------- ");
while(fscanf(f," \t%s\t%s\t%2.f\t%2.f\t%2.f\t\t%2.f\t%2.f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history)!=EOF){
if(pd[i].id==0)
{
printf("hi");
}
else
{
printf(" \t%s\t%s\t%2.f\t%2.f\t%2.f\t\t%2.f\t%2.f ",pd[i].id,pd[i].name,pd[i].math,pd[i].physic,pd[i].computer,pd[i].khlanguage,pd[i].history);
printf(" The Score of all subject: %f",pd[i].sum);
printf(" The Average is : %f",pd[i].avg);
}
}
fclose(f);
}
// function search male/female students informations
void m_or_f()
{
char sex[100];
int flag=0;
printf(" \tSEARCH SEX(m/f):"); scanf("%s",sex);
printf("\tName\tid\tsex\tage\tgrade\ttelephone ");
printf("\t-------------------------------------------------------------------- ");
for(int i=0;i< n;i++){
if(strcmp(pd[i].sex,sex)==0){
flag=1;
printf("\t%s\t%s\t%s\t%s\t%s\t%s ",pd[i].name,pd[i].id,pd[i].sex,pd[i].age,pd[i].grade,pd[i].tel);
}
}
if(flag==0){
printf("\t*****NOT FOUND*****");
}
}
// function for display score from big to small
void mix()
{
printf("\tID\tName\tSex\tAvg ");
printf("\t-------------------------------------------------------------------- ");
for(int k=pd[k].avg ;k>=0 ;k--)
{
{
printf("\t%s\t%s\t%s\t%f " ,pd[k].id,pd[k].name,pd[k].sex,pd[k].avg);
}
}
}
//void file_students()
//{
// FILE *file;
// file = fopen("students_note.txt","r");
// while (fscanf(file,"\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex)!=EOF)
// {
// n++;
// }
//}
void fil()
{
FILE *file;
file = fopen("students_note.txt","w");
// for (int i=1 ; i< n ;i++)
// {
// if(strcmp(pd[i].id,"")==0)
// {
//
// fprintf(file,"%s",pd[i].id);
// }
// else{
// fprintf(file,"\t%s\t%s\t%s ",pd[n].name,pd[n].id,pd[n].sex);
// }
//
//}
}
void loading()
{
int i,j;
printf("Loading........");
for (i=1 ; i<= 20; i++)
{
for(j=0; j<=100000000; j++);
printf("%c",177);
}
}
// for call function use in main()
int main(){
system("color B0");
// file_students();
int choice;
loading();
printf(" ");
printf("\t\t\t\t\t======================================================================================================================== ");
printf("\t\t\t\t\t**************************************| WELCOME |**************************** ");
printf("\t\t\t\t\t**************************************| Project in c program < students record system > |**************************** ");
printf("\t\t\t\t\t======================================| |============================ ");
printf("\t\t\t\t\t======================================================================================================================== ");
printf(" ------------------------------------------------------------------------------------------------------ ");
printf(" |1) add students information. | 2)search information by id. | ");
printf(" |----------------------------------------------------------------------------------------------------| ");
printf(" |3) display all students information. | 4) update students information. | ");
printf(" | ---------------------------------------------------------------------------------------------------| ");
printf(" |5) for delete students informations. | 6) search male/female students informations. | ");
printf(" |----------------------------------------------------------------------------------------------------| ");
printf(" |7) add score student. | 8) display student score. | ");
printf(" |----------------------------------------------------------------------------------------------------| ");
printf(" |9) update score students. | 10) display score from big to small. | ");
printf(" |----------------------------------------------------------------------------------------------------| ");
printf(" |11) Exit the program. | | ");
printf(" |----------------------------------------------------------------------------------------------------|");
while (1){
printf(" ");
printf(" \t\tchoses option [1-11]: "); scanf("%d",&choice);
if(choice==1){
add ("student22.txt");
}
else if(choice==2){
search ("student22.txt");
}
else if(choice==3)
{
disply_information("student22.txt");
}
else if (choice==4)
{
update_students_information();
}
else if (choice==5)
{
dalete("student22.txt");
}
else if (choice==6)
{
m_or_f();
}
else if (choice==7)
{
add_score("student22.txt");
}
else if (choice==8)
{
display_scorc_studentd();
}
else if (choice == 9)
{
up_score();
}
else if(choice == 10)
{
mix();
}
else if (choice==11)
{
fil();
printf("***** exit program*******");
break ;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions