Student Mark List Preparation
#include<stdio.h>
FILE *fp;
struct stud
{
int sid;
int sm[5];
int tot;
float avg;
int cls;
char pf;
};
void cal(struct stud s[],int);
void print(struct stud s[],int);
int main()
{
struct stud s[10];
int i,j,n;
printf("Enter the no.of students:");
scanf("%d",&n);
//s=(struct stud*)malloc(sizeof(struct stud)*n);
for(i=0;i<n;i++)
{
printf("Enter the student id:");
scanf("%d",&s[i].sid);
printf("enter 5 marks:");
for(j=0;j<5;j++)
scanf("%d",&s[i].sm[j]);
}
cal(s,n);
return 0;
}
void cal(struct stud s[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(s[i].sm[0]>50 && s[i].sm[1]>50 && s[i].sm[2]>50 && s[i].sm[3]>50 && s[i].sm[4]>50)
s[i].pf='p';
else
s[i].pf='f';
if(s[i].pf=='p')
{
s[i].tot=(s[i].sm[0]+s[i].sm[1]+s[i].sm[2]+s[i].sm[3]+s[i].sm[4]);
s[i].avg=(s[i].tot)/5;
if(s[i].avg>70)
s[i].cls=1;
else if(s[i].avg>60 && s[i].avg<70)
s[i].cls=2;
else //(s[i].avg>50 && s[i].avg<60)
s[i].cls=3;
}
else
{
printf("FAIL");
}
}
print(s,n);
return;
}
void print(struct stud s[],int n)
{
int i,j;
fp =fopen("marklist.txt","w+");
for(i=0;i<n;i++)
{
fprintf(fp,"%d ",s[i].sid);
for(j=0;j<5;j++)
{
fprintf(fp,"%d ",s[i].sm[j]);
}
fprintf(fp,"%d ",s[i].tot);
fprintf(fp,"%f ",s[i].avg);
fprintf(fp,"%d ",s[i].cls);
fprintf(fp,"\n");
}
fclose(fp);
fp=fopen("marklist.txt","r");
printf("SID C COA DS RDBMS JAVA TOTAL AVG CLASS \n");
for(i=1;i<=n;i++)
{
j=0;
fscanf(fp,"%d %d %d %d %d %d %d %f %d",&s[i].sid,&s[i].sm[j],&s[i].sm[j+1],&s[i].sm[j+2],&s[i].sm[j+3],&s[i].sm[j+4],&s[i].tot,&s[i].avg,&s[i].cls);
printf("%d %d %d %d %d %d %d %f %d\n",s[i].sid,s[i].sm[j],s[i].sm[j+1],s[i].sm[j+2],s[i].sm[j+3],s[i].sm[4],s[i].tot,s[i].avg,s[i].cls);
}
fclose(fp);
return;
}
#include<stdio.h>
FILE *fp;
struct stud
{
int sid;
int sm[5];
int tot;
float avg;
int cls;
char pf;
};
void cal(struct stud s[],int);
void print(struct stud s[],int);
int main()
{
struct stud s[10];
int i,j,n;
printf("Enter the no.of students:");
scanf("%d",&n);
//s=(struct stud*)malloc(sizeof(struct stud)*n);
for(i=0;i<n;i++)
{
printf("Enter the student id:");
scanf("%d",&s[i].sid);
printf("enter 5 marks:");
for(j=0;j<5;j++)
scanf("%d",&s[i].sm[j]);
}
cal(s,n);
return 0;
}
void cal(struct stud s[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(s[i].sm[0]>50 && s[i].sm[1]>50 && s[i].sm[2]>50 && s[i].sm[3]>50 && s[i].sm[4]>50)
s[i].pf='p';
else
s[i].pf='f';
if(s[i].pf=='p')
{
s[i].tot=(s[i].sm[0]+s[i].sm[1]+s[i].sm[2]+s[i].sm[3]+s[i].sm[4]);
s[i].avg=(s[i].tot)/5;
if(s[i].avg>70)
s[i].cls=1;
else if(s[i].avg>60 && s[i].avg<70)
s[i].cls=2;
else //(s[i].avg>50 && s[i].avg<60)
s[i].cls=3;
}
else
{
printf("FAIL");
}
}
print(s,n);
return;
}
void print(struct stud s[],int n)
{
int i,j;
fp =fopen("marklist.txt","w+");
for(i=0;i<n;i++)
{
fprintf(fp,"%d ",s[i].sid);
for(j=0;j<5;j++)
{
fprintf(fp,"%d ",s[i].sm[j]);
}
fprintf(fp,"%d ",s[i].tot);
fprintf(fp,"%f ",s[i].avg);
fprintf(fp,"%d ",s[i].cls);
fprintf(fp,"\n");
}
fclose(fp);
fp=fopen("marklist.txt","r");
printf("SID C COA DS RDBMS JAVA TOTAL AVG CLASS \n");
for(i=1;i<=n;i++)
{
j=0;
fscanf(fp,"%d %d %d %d %d %d %d %f %d",&s[i].sid,&s[i].sm[j],&s[i].sm[j+1],&s[i].sm[j+2],&s[i].sm[j+3],&s[i].sm[j+4],&s[i].tot,&s[i].avg,&s[i].cls);
printf("%d %d %d %d %d %d %d %f %d\n",s[i].sid,s[i].sm[j],s[i].sm[j+1],s[i].sm[j+2],s[i].sm[j+3],s[i].sm[4],s[i].tot,s[i].avg,s[i].cls);
}
fclose(fp);
return;
}
No comments:
Post a Comment