Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
4
Indexable
Never


Here is the Solution for sub-question (i)...Please give an UPVOTE and for any queries do comment. Please DON'T give DISLIKE without any clarifications.

i)

C Code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>

void main()
{
FILE *fp1,*fp2;
char name[10],opt;
char id[10];
int t1,t2,t3;
int hw1,hw2,hw3,hw4;
int prj;
float p;
char grade[4];
struct st
{
char stname[10];
char regdno[10];
float marks;
char g[4];
};
struct st s[50];
struct st tmp;
int i,j,n;

fp1=fopen("stu1.dat","r");
fp2=fopen("stu2.dat","w");

printf("name id t1 t2 t3 hw1 hw2 hw3 hw4 prj percentage grade\n");
fscanf(fp1,"%s%s%d%d%d%d%d%d%d",name,id,&t1,&t2,&t3,&hw1,&hw2,&hw3,&hw4,&prj);
i=0;
while(!feof(fp1))
{

p=t1*0.2 + t2*0.2 + t3*0.2 + hw1*0.1 * hw2 *0.1 + hw3*0.1 * hw4 *0.1+prj*0.3;

if (p>90)
strcpy(grade,"A");
else
if (p>80)
strcpy(grade,"A-");
else
if (p>70)
strcpy(grade,"B");
else
if (p>60)
strcpy(grade,"B-");
else
if (p>50)
strcpy(grade,"C");
else
strcpy(grade,"C-");


strcpy(s[i].stname,name);
strcpy(s[i].regdno,id);
s[i].marks=p;
strcpy(s[i].g,grade);
i++;


printf("%s %s %d %d %d %d %d %d %d %f %s\n",name,id,t1,t2,t3,hw1,hw2,hw3,hw4,prj,p,grade);
fprintf(fp2,"%s %s %d %d %d %d %d %d %d %f %s\n",name,id,t1,t2,t3,hw1,hw2,hw3,hw4,prj,p,grade);
fscanf(fp1,"%s%s%d%d%d%d%d%d%d",name,id,&t1,&t2,&t3,&hw1,&hw2,&hw3,&hw4,&prj);
}

fclose(fp1);
fclose(fp2);

n=i;

for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(s[j].marks<s[j+1].marks)
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
printf("Final result \n");
printf("------------------------ \n");
printf("name ID Marks Grade \n");
printf("------------------------ \n");
for(i=0;i<n-1;i++)
printf("%s %s %5.2f %s\n",s[i].stname,s[i].regdno,s[i].marks,s[i].g);


getch();
}