Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need flowchart for this code #include #include #include struct student { int rollno; char name[20]; int phy_m,chem_m,math_m,eng_m,cs_m; float per; char grade; int st; }; FILE
need flowchart for this code
#include
#include
#include
struct student
{
int rollno;
char name[20];
int phy_m,chem_m,math_m,eng_m,cs_m;
float per;
char grade;
int st;
};
FILE *fptr;
void display()
{
struct student st;
int n;
int flag=0;
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Student Report ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
fptr=fopen("students.txt","r");
while(fread(&st,sizeof(struct student),1,fptr))
{
if(st.rollno==n)
{
printf(" Roll number of student : %d",st.rollno);
printf(" Name of student : %s",st.name);
printf(" Marks in Chemistry : %d",st.chem_m);
printf(" Marks in Physics : %d",st.phy_m);
printf(" Marks in English: %d",st.eng_m);
printf(" Marks in Maths : %d",st.math_m);
printf(" Marks in Computer Science : %d",st.cs_m);
printf(" Percentage : %.1f",st.per);
printf(" Grade : %c",st.grade);
flag=1;
}
}
fclose(fptr);
if(flag==0){
printf(" Record does not exist !");
}
else
{
printf(" Records Displayed");
}
getch();
}
void class_result()
{
struct student st;
char ch;
system("cls");
fptr=fopen("students.txt","r");
if(fptr==NULL)
{
printf(" No Record Found!");
printf(" Create Records First !");
getch();
}
else
{
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Class Result ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
while(fread(&st,sizeof(struct student),1,fptr))
{
printf(" %d\t %s\t\t %d\t %d\t %d\t %d\t %d\t %.1f\t \t %c",st.rollno,st.name,st.phy_m,st.chem_m,st.math_m,st.eng_m,st.cs_m,st.per,st.grade);
}
printf(" ============================================================================= ");
printf(" All records displayed..");
fclose(fptr);
getch();
}
}
void result()
{
int ans,rno;
char ch;
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Result Menu ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" [1]--> Result");
printf(" [2]--> Report Card");
printf(" [3]--> Main Menu ");
printf(" Select an Option: ");
ch=getche();
//scanf("%d",&ans);
switch(ch)
{
case '1' : {
class_result();
break;
}
case '2' :
{
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Student Report ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" Enter the roll number : ");
scanf("%d",&rno);
display(rno);
break;
}
case '3':
break;
default: printf("\a");
}
}
void write()
{
system("cls");
struct student st;
fptr=fopen("students.txt","a+");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Adding New Student ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" Please enter the following details ");
printf(" Enter the Roll number of student: ");
scanf("%d",&st.rollno);
fflush(stdin);
printf("Enter the Name of student: ");
gets(st.name);
printf("Enter the marks obtained in Chemistry out of 100 : ");
scanf("%d",&st.chem_m);
printf("Enter the marks obtained in English out of 100 : ");
scanf("%d",&st.eng_m);
printf("Enter the marks obtained in Physics out of 100 : ");
scanf("%d",&st.phy_m);
printf("Enter the marks obtained in Maths out of 100 : ");
scanf("%d",&st.math_m);
printf("Enter the marks obtained in Computer Science out of 100 : ");
scanf("%d",&st.cs_m);
st.per=(st.phy_m+st.chem_m+st.math_m+st.eng_m+st.cs_m)/5.0;
if(st.per>=80)
st.grade='A';
else if(st.per>=60)
st.grade='B';
else if(st.per>=50)
st.grade='C';
else if(st.per>=40)
st.grade='D';
else
st.grade='F';
// fprintf(fptr," Roll Number : %d Student Name: %s Physics Marks: %d Chemistry Marks: %d Math Marks: %d English Marks: %d Computer Science Marks: %d Percenatge: %.1f Student Grade: %c ",st.rollno,st.name,st.phy_m,st.chem_m,st.math_m,st.eng_m,st.cs_m,st.per,st.grade);
// fwrite(&st,sizeof(st),1,fptr);
fwrite (&st, sizeof(struct student), 1, fptr);
if(fwrite != 0)
printf(" Student record created ");
else
printf(" Error in writing file ! ");
fclose(fptr);
getch();
}
void display_all()
{
struct student st;
system("cls");
printf("-------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" View All Records ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
fptr=fopen("students.txt","r");
if (fptr == NULL)
{
fprintf(stderr, " Cannot open file ");
getch();
system("cls");
return;
}
while(fread(&st,sizeof(struct student),1,fptr))
{
printf(" Roll Number of Student : %d",st.rollno);
printf(" Name of student : %s",st.name);
printf(" Marks Obtained in Maths : %d",st.math_m);
printf(" Marks Obtained in Chemistry : %d",st.chem_m);
printf(" Marks Obtained in Physics: %d",st.phy_m);
printf(" Marks Obtained in English : %d",st.eng_m);
printf(" Marks Obtained in Computer Science : %d",st.cs_m);
printf(" Percentage is : %.2f",st.per);
printf(" Grade is : %c",st.grade);
printf(" ============================================================================ ");
}
fclose(fptr);
printf(" All Records Displayed!");
getch();
system("cls");
}
void modify_student()
{
int no,found=0;
struct student st;
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Updating Record ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" Please Enter the roll number of student to modify record: ");
scanf("%d",&no);
fptr=fopen("students.txt","r+"); //rb+ or ab+
while((fread(&st,sizeof(struct student),1,fptr))>0 && found==0)
{
if(st.rollno==no)
{
printf(" Roll number of student : %d",st.rollno);
printf(" Name of student : %s",st.name);
printf(" Marks Obtained in Physics : %d",st.phy_m);
printf(" Marks Obtained in Chemistry : %d",st.chem_m);
printf(" Marks Obtained in Maths : %d",st.math_m);
printf(" Marks Obtained in English : %d",st.eng_m);
printf(" Marks Obtained in Computer Science : %d",st.cs_m);
printf(" Percentage : %.2f",st.per);
printf(" Grade : %c",st.grade);
printf(" Please enter the fresh details of student ");
printf(" Enter the Roll number of student: ");
scanf("%d",&st.rollno);
fflush(stdin);
printf(" Enter the Name of student: ");
gets(st.name);
printf(" Enter the marks obtained in Physics out of 100 : ");
scanf("%d",&st.phy_m);
printf(" Enter the marks obtained in Chemistry out of 100 : ");
scanf("%d",&st.chem_m);
printf(" Enter the marks obtained in Maths out of 100 : ");
scanf("%d",&st.math_m);
printf(" Enter the marks obtained in English out of 100 : ");
scanf("%d",&st.eng_m);
printf(" Enter the marks obtained in Computer Science out of 100 : ");
scanf("%d",&st.cs_m);
st.per=(st.phy_m+st.chem_m+st.math_m+st.eng_m+st.cs_m)/5.0;
if(st.per>=80)
st.grade='A';
else if(st.per>=60)
st.grade='B';
else if(st.per>=50)
st.grade='C';
else if(st.per>=40)
st.grade='D';
else
st.grade='F';
fseek(fptr,-(long)sizeof(struct student),1);
//fprintf(fptr," Roll Number : %d Student Name: %s Physics Marks: %d Chemistry Marks: %d Math Marks: %d English Marks: %d Computer Science Marks: %d Percenatge: %.1f Student Grade: %c ",st.rollno,st.name,st.phy_m,st.chem_m,st.math_m,st.eng_m,st.cs_m,st.per,st.grade);
fwrite(&st,sizeof(struct student),1,fptr);
found=1;
}
}
fclose(fptr);
if(found==0){
printf(" Record not found ! Press and Key to Go back !");
}
else
{
printf(" Records Updated, Press and key to go back ");
}
getch();
}
void delete_all()
{
int no;
FILE *fptr2;
struct student st;
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Deleting Record ");
printf(" -------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Please Enter The roll number of Student You Want To Delete: ");
scanf("%d",&no);
fptr=fopen("students.txt","r");
fptr2=fopen("Temp.txt","a+");
rewind(fptr);
while(fread(&st,sizeof(struct student),1,fptr))
{
if(st.rollno!=no)
{
//fprintf(fptr," Roll Number : %d Student Name: %s Physics Marks: %d Chemistry Marks: %d Math Marks: %d English Marks: %d Computer Science Marks: %d Percenatge: %.1f Student Grade: %c ",st.rollno,st.name,st.phy_m,st.chem_m,st.math_m,st.eng_m,st.cs_m,st.per,st.grade);
fwrite(&st,sizeof(struct student),1,fptr2);
}
}
fclose(fptr2);
fclose(fptr);
remove("students.txt");
rename("Temp.txt","students.txt");
printf(" Record Deleted");
getch();
}
void entry_menu()
{
char ch2;
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Entry Menu ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" [1]--> Create Record");
printf(" [2]--> View all Records");
printf(" [3]--> Search Record");
printf(" [4]--> Update Record");
printf(" [5]--> Delete Record");
printf(" [6]--> Main Menu ");
ch2=getche();
switch(ch2)
{
case '1':
{
write();
break;
}
case '2': {
display_all();
break;
}
case '3':
{
int num;
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Search Record ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" Please Enter The roll number of student to search: ");
scanf("%d",&num);
display(num);
break;
}
case '4':
{
modify_student();
break;
}
case '5': {
delete_all();
break;
}
case '6': break;
default:
{
printf("\a");
entry_menu();
}
}
}
void intro()
{
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" School Result Management System ");
printf(" -------------------------------------------------------------------------------");
printf(" ");
printf(" MADE BY : SOHA MEHFOOZ ");
printf(" ");
printf(" -------------------------------------------------------------------------------");
printf(" Press Any Key To Continue !");
getch();
}
int main()
{
intro();
int ch;
do
{
system("cls");
printf("---------------------------------------------------------------------------------");
printf(" -------------------------------------------------------------------------------");
printf(" Main Menu ");
printf(" -------------------------------------------------------------------------------");
printf(" ------------------------------------------------------------------------------- ");
printf(" [1]--> Result Menu");
printf(" [2]--> Create Record");
printf(" [3]--> Exit ");
ch=getche();
switch(ch)
{
case '1':
result();
break;
case '2':
entry_menu();
break;
case '3':
printf(" ----------------------------Good-=-Bye------------------------------------- ");
exit(0);
default :
printf("\a");
}
}
while(ch!='3');
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started