you write this code for me in c ++ language? #include int main() { /* to have both the files */ FILE *g1; FILE *g2; /* ooening both the files in read mode */ g1=fopen("group1.txt","r"); g2=fopen("group2.txt","r"); char c[10][10]; char c1[10][10]; int cc=0,cc1=0; int num1[10][20],num2[10][20];
Can you write this code for me in c ++ language?
#include <stdio.h>
int main()
{
/* to have both the files */
FILE *g1;
FILE *g2;
/* ooening both the files in read mode */
g1=fopen("group1.txt","r");
g2=fopen("group2.txt","r");
char c[10][10];
char c1[10][10];
int cc=0,cc1=0;
int num1[10][20],num2[10][20];
/* getting the first string */
fscanf(g1,"%s",c[cc]);
float sum1[10],sum2[10];
/* to store the sum of score of each subject */
for(int i=0;i<5;i++)
{
sum1[i]=0;
sum2[i]=0;
}
int p1=0,p2=0;
/* processing the data in the first file */
while(1)
{
int num1;
fscanf(g1,"%d",&num1);
p1++;
if(num1==-999)
{
p1--;
sum1[cc]=sum1[cc]/p1;
cc++;
if(cc==5)
break;
fscanf(g1,"%s",c[cc]);
p1=0;
continue;
}
sum1[cc]+=num1;
}
fscanf(g2,"%s",c1[cc1]);
/* processing the data in the second file */
while(1)
{
int num2;
fscanf(g2,"%d",&num2);
p2++;
if(num2==-999)
{
p2--;
sum2[cc1]=sum2[cc1]/p2;
cc1++;
if(cc1==5)
break;
fscanf(g2,"%s",c1[cc1]);
p2=0;
continue;
}
sum2[cc1]+=num2;
}
/* printing the result in the proper format */
printf("Course Course 0 10 20 30 40 50");
printf(" 60 70 80 90 100\n");
printf("ID Average ");
printf("|....|....|....|....|....|....|....|....|....");
printf("|....|\n");
for(int i=0;i<5;i++)
{
printf("%s %.2f ",c[i],sum1[i]);
int p1=sum1[i]/2;
int p2=sum2[i]/2;
for(int i=0;i<(p1);i++)
printf("*");
printf("\n");
printf(" %.2f ",sum2[i]);
for(int i=0;i<(p2);i++)
printf("#");
printf("\n\n");
}
}
Step by step
Solved in 2 steps