Create array of structure for students to store 40 student details. The
student structure should contain studid , studname, mark1, mark2
and mark3. Compute grade based on subject mark, The criteria for
grade is sample for mark1
< 50 grade = ‘F’
50 to 59 grade = ‘D’
60 to 69 grade = ’C’
70 to 79 grade = ‘B’
80 to 89 grade = ‘A’
90 to 100 grade = ‘S’
These grade has to be computed for 40 students and the entire array
of structure is copies to the file T1.Txt using fwrite() command. and
the content from the file T1.txt is read using fread() and all student
information’s are displayed in the system.
#include<stdio.h>
#include<string.h>
struct Student{
int studid;
char studname[50];
int mark1;
int mark2;
int mark3;
};
char grading(int mark){
char grade;
if(mark<50){
grade = 'F';
}
else if(mark >=50 && mark <= 59){
grade = 'D';
}
else if(mark >=60 && mark <= 69){
grade = 'C';
}
else if(mark >=70 && mark <= 79){
grade = 'B';
}
else if(mark >=80 && mark <= 89){
grade = 'A';
}
else if(mark >=90 && mark <= 99){
grade = 'S';
}
return grade;
}
int main(){
FILE *file;
file= fopen ("T1.Txt ", "w");
int i,n;
struct Student stu[3];
printf("Enter the details for 5 students\n");
for(i=0; i<3; i++){
printf("Enter the student id for student:\t%d\n",(i+1));
scanf("%d",&stu[i].studid);
// fwrite(&stu[i].studid, 10, sizeof(struct Student), file);
printf("Enter the name for student:\t%d\n",(i+1));
scanf("%s",&stu[i].studname);
printf("Enter the mark1 for student:\t%d\n",(i+1));
scanf("%d",&stu[i].mark1);
printf("Enter the mark 2 for student:\t%d\n",(i+1));
scanf("%d",&stu[i].mark2);
printf("Enter the mark 3 for student:\t%d\n",(i+1));
scanf("%d",&stu[i].mark3);
}
for( n=0; n<3; n++){
printf("\nStudent Id:%d, Student Name:%s, mark 1:%d, Grade:%c Mark 2: %d, Grade:%c Mark 3: %d Grade:%c",stu[n].studid,
stu[n].studname, stu[n].mark1, grading(stu[n].mark1), stu[n].mark2, grading(stu[n].mark2),
stu[n].mark3, grading(stu[n].mark3));
}
}
Comments
Leave a comment