write a C program that We have seen that a struct can contai

write a C program that:

We have seen that a struct can contain all the familiar variables - char, int, double. It can also contain arrays, strings (which are arrays of characters), and pointers. One struct can even contain another struct! (Sub-struct?) This second exercise will focus on using arrays as members within a struct. Our theme for a program to see how this works is a mini grade-book. Start by defining a struct template that has the following members: a student ID number, which is some integer between 1 and 10, an integer array -call it quizzes-that has 3 elements that will hold quiz scores with values between 5 and 10 a second integer array-perhaps called exams-that has 3 elements that will hold exam scores that range between 50 and 100. a third integer array-perhaps called homework-that has 3 elements and that hold homework scores between 25 and 50 and finally a single character that will hold the letter grade for the student Once the struct is defined, declare an array of 3 of these structs The declaration w ill probably look something like struct studentRecord studentArray[3]; where studentRecord is tag for the struct template defined above. (As always, you can come up with your own names for all of these items-it\'-s your choice.) Each student will have an id number-1, 2, or 3. Fill in the scores of the member arrays with random numbers. You can do this manually with scanf () or you can use a random number generator to fill these up. Calculate the overall average for each of the different types of scores-quizzes, exams, and homework For example, take all 9 quiz scores-3 from each of the 3 students-and compute the average. Print out the three average values. Compute a letter grade for each student. Each type of work is worth 33.33% of the total. Here is a sample calculation for a student whose quiz scores total 22, exam scores total 272, and homework scores total 133. total = 33.33*(22/30) + 33.33*(272/300) + 33.33*(133/150) = 84.2. Then the letter grade is based on the usual scale: 90 to 100 = A, 80 to 89.9 = B, 70 to 79 9 = C, 60 to 69.9 = D, below 59.9 = F (ouch!). Finally, print out each student\'-s scores and their letter grade. Parts 4, 5, and 6 can be done with functions. (As always, a modular approach is better.) But if you prefer, you can simply do everything inside of main.

Solution

/* C Program with Structers */
#include <stdio.h>
#include <string.h>
/* Struct Declaration */
struct Student {
int stuid;
int quizes[3];
int exams[3];
int homework[3];
char grade;
};

int main( )
{
   /* varibles Declaration */
struct Student Record[3] ;
int a,b,c,x,i,j;
int avg1=0,avg2=0,avg3=0,sum1=0,sum2=0,sum3=0;
float total,z=33.33;

/* Reading 3 students data */
for (i=0,j=1;i<3;i++,j++)
{
        Record[i].stuid=j;
    printf(\"Enter Student %d quiz marks\ \",j);                                              
    for(x=0;x<3;x++)                                                              
    scanf(\"%d\",&Record[i].quizes[x]);                                           //READING QUIZ MARKS THROUGH LOOP
    printf(\"Enter Student %d Exams marks\ \",j);
    for(x=0;x<3;x++)
    scanf(\"%d\",&Record[i].exams[x]);                                           //READING EXAM MARKS THROUGH LOOP
    printf(\"Enter Student %d Homework marks\ \",j);
    for(x=0;x<3;x++)
    scanf(\"%d\",&Record[i].homework[x]);                                           //READINGHOME WORK MARKS THROUGH LOOP
   
   
}

/* Display 3 students data */
for (i=0,j=1;i<3;i++,j++)
{
    avg1=0,avg2=0,avg3=0,sum1=0,sum2=0,sum3=0;
  
    printf(\" \ Student %d quiz marks\ \",Record[i].stuid);
    for(x=0;x<3;x++)
    {
        printf(\"%d\\t\",Record[i].quizes[x]);
        sum1=sum1+Record[i].quizes[x];                                   //sum of quize marks of individul student
       
   }
   avg1=sum1/3;                                                   //average of quiz marks
   printf(\"\\t avg1- %d Homework marks\\t\",avg1);

   
    printf(\"\ Student %d Exams marks\ \",j);
    for(x=0;x<3;x++)
    {
        printf(\"%d\\t\",Record[i].exams[x]);
        sum2=sum2+Record[i].exams[x];                                   //Sum of EXAMS marks of individul student
   }
    avg2=sum2/3;                                                       //average of EXAM marks
    printf(\"\\t avg2 - %d Homework marks\\t\",avg2);
    printf(\"\ Student %d Homework marks\ \",j);
    for(x=0;x<3;x++)
    {
        printf(\"%d\\t\",Record[i].homework[x]);
        sum3=sum3+Record[i].homework[x];
   }
    avg3=sum3/3;                                                       //average of HOME WORK marks
    printf(\"\\t avg3 - %d Homework marks\\t\",avg3);
   
    total=(avg1*33/100)+(avg2*33/100)+(avg3*33/100);       //FINDING TOATAL OF EACH STUDENT BASED ON GIVEN CONDITION
   printf(\"\\t Total - %f Homework marks\\t\",total);               //TOTAL COMPARISION WITH GRADING CONKDITONS                          
    if(total<=100 && total>=90)                                  
    Record[i].grade=\'A\';
    else if(total<=89.9 && total>=80)
    Record[i].grade=\'B\';
    else if(total<=79.9 && total>=70)
    Record[i].grade=\'C\';
    else if(total<=69.9 && total>=70)
    Record[i].grade=\'D\';
    else
    Record[i].grade=\'F\';
   
        printf(\"\\t Grade - %c\\t\",Record[i].grade);                   //DISPALY GRADE
}

  

return 0;
}

Output :

Enter Student 1 quiz marks
30
30
30
Enter Student 1 Exams marks
90
90
90
Enter Student 1 Homework marks
40
40
40
Enter Student 2 quiz marks
10
10
10
Enter Student 2 Exams marks
20
20
20
Enter Student 2 Homework marks
30
30
30
Enter Student 3 quiz marks
1
1
1
Enter Student 3 Exams marks
2
2
2
Enter Student 3 Homework marks
3
3
3

Student 1 quiz marks
30 30 30 avg1- 30 Homework marks
Student 1 Exams marks
90 90 90 avg2 - 90 Homework marks
Student 1 Homework marks
40 40 40 avg3 - 40 Homework marks Total - 51.000000 Homework marks Grade - F
Student 2 quiz marks
10 10 10 avg1- 10 Homework marks
Student 2 Exams marks
20 20 20 avg2 - 20 Homework marks
Student 2 Homework marks
30 30 30 avg3 - 30 Homework marks Total - 18.000000 Homework marks Grade - F
Student 3 quiz marks
1 1 1 avg1- 1 Homework marks
Student 3 Exams marks
2 2 2 avg2 - 2 Homework marks
Student 3 Homework marks
3 3 3 avg3 - 3 Homework marks Total - 0.000000 Homework marks Grade - F
--------------------------------

write a C program that: We have seen that a struct can contain all the familiar variables - char, int, double. It can also contain arrays, strings (which are ar
write a C program that: We have seen that a struct can contain all the familiar variables - char, int, double. It can also contain arrays, strings (which are ar
write a C program that: We have seen that a struct can contain all the familiar variables - char, int, double. It can also contain arrays, strings (which are ar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site