Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make sure your code can be compiled with no error prior submission. Codes which

ID: 3694616 • Letter: M

Question

Make sure your code can be compiled with no error prior submission. Codes which cannot be compiled will get 0 points. Write down a C program to collect the student's information and compute the average score of the class. The program should have following: Use structure for student's information. Structure should have the fields: student name, student id, student age and student score. Use pointers and dynamic memory allocation to allocate the space for the number of students entered by user. Write a function that should compute the average of the students score. Write down a C program that should copy the contents of an input file to a new file.

Explanation / Answer

problem 1

#include<stdio.h>
#include<conio.h>
   struct stdinfo
   {
       char name[20];
       int stdid, age, score;
   };

float cal_av(struct stdinfo b[], int n)
{
   int i,sum=0;
   float av;

   for(i=0;i<n;i++)
   {
       sum=sum+b[i].score;
   }
   av=sum/n;
   return av;
}


void main()
{

   struct stdinfo a[3];
   int i;
   float av;
   clrscr();
   for(i=0;i<3;i++)
   {
       printf("Enter name");
       scanf("%s",a[i].name);

       printf("Enter id");
       scanf("%d",&a[i].stdid);

       printf("Enter age");
       scanf("%d",&a[i].age);

       printf("Enter score");
       scanf("%d",&a[i].score);
   }

   av=cal_av(a,3);
   printf("Average of scores is %f",av);
   getch();
}

Problem 2

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

void main()
{
FILE *fp1, *fp2;
char ch;
clrscr();

fp1 = fopen("Sample.txt", "r");
fp2 = fopen("Output.txt", "w");

while (1)
{
ch = fgetc(fp1);

if (ch == EOF)
break;
else
putc(ch, fp2);
}

printf("File copied Successfully!");
fclose(fp1);
fclose(fp2);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote