Question

(30 pts) Show the function avgStudents which functionally returns the average number of students enrolled in universities of

Must be coded in C.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer..

main.c #include<stdio.h> #include<string.h> 3 typedef struct char szCode[71; char szName [501: char szState[31; int iStudentC27 int main() 28 29 30 31 32 University unilistM[1000]-( PURDUE, purdue university, IN,38000), {UTSA, University Of

Here is the OUTPUT:input The average of enrolled students in University of Texas are: 0.528409 . . .Program finished with exit code 0 Press ENTE

Here is the Code:

#include<stdio.h>
#include<string.h>
typedef struct
{
   char szCode[7];
   char szName[50];
   char szState[3];
   int iStudentCnt;
}University;
float avgStudents(University uniListM[1000],int tot,char str[100])
{
int i,count=0;
int no_of_students=0; //for total no_of_students in all universities
for(i=0;i<tot;i++)
{
  
no_of_students+=uniListM[i].iStudentCnt; //count the no_of_students
if(strcmp(uniListM[i].szState,str)==0) //if university is TX then add students.
{
//printf("%s ",uniListM[i].szState);
count+=uniListM[i].iStudentCnt;
}
}
float avg=(float)count/no_of_students; //calculating avg
return avg; //return the avg value
}
int main()
{
   University uniListM[1000]={
   {"PURDUE","purdue university","IN",38000},
   {"UTSA","University Of Texas at San Antonio","TX",30000},
   {"LSU","Lousiana State University","LA",25000},
   {"IU","Indian University","IN",20000},
   {"UT","University Of Texas at Austin","TX",35000},
   {"UTA","University Of Texas at Arlingtoin","TX",28000}
   };
  
   int iUnivCnt=6;

  
   printf("The average of enrolled students in University of Texas are : %f ",avgStudents(uniListM,6,"TX"));
   //here we use %f because avg is float value
}

If you have any doubts please COMMENT...

If you understand the answer please give THUMBS UP....

Add a comment
Know the answer?
Add Answer to:
Must be coded in C. (30 pts) Show the function avgStudents which functionally returns the average...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C++program to analyze a small subset of the data that has been collected. See...

    write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the...

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT