1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marta_Voda [28]
4 years ago
8

Write a program in C which will open a text file (Scores.txt) containing section number and total scores of students of CSCI1320

. You need to create the file Scores.txt using any text editor like Notepad etc and make sure the file is in the same directory of your c program. Your program needs to open the file and based on section number, compute the average score for each section. Finally, you need to print section number along with average score and find the section with the highest average score. Consider there are only 3 sections for the course CSCI1320. [Note: use have to use pointers and user-defined functions wherever necessary. You need to demonstrate both pass-by value and pass-by-reference in this program]
Computers and Technology
1 answer:
Westkost [7]4 years ago
6 0

Answer:

See explaination

Explanation:

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

int main()

{

FILE *fp;

char section[10][2], score[10][10],buf[10][4], buf1[4];

int i=0, j = 0, k = 0, l = 0, c1 = 0, c2 = 0, c3 = 0, sec;

float avg1 = 0 ,avg2 = 0, avg3 = 0 ,avg[3] ,max;

fp = fopen("scores.dat","r");

/* read data from scores.dat file and store into buf */

while(fscanf(fp, "%s", buf[i++])!=EOF);

/* separate scores and sections */

for(j=1; j<i; j++){

if(j%2!=0){

strcpy(section[k++], buf[j-1]);

}

else{

strcpy(score[l++], buf[j-1]);

}

}

/* calculate avgerage */

for(i=0;i<7;i++){

if(strcmp(section[i], "1")){

avg1 = avg1 + atof(score[i]);

c1++;

}

if(strcmp(section[i], "2")){

avg2 = avg2 + atof(score[i]);

c2++;

}

if(strcmp(section[i], "1")){

avg3 = avg3 + atof(score[i]);

c3++;

}

}

avg[0] = avg1/c1;

avg[1] = avg2/c2;

avg[2] = avg3/c3;

max = avg[0];

for(i=0;i<3; i++)

if(avg[i] > max){

max = avg[i];

sec = i;

}

printf("Sectrion 1 Avg: %f\nSection 2 Avg: %f\nSection 3 Avg: %f\nHighest Avg by:Section %s\n",avg[0],avg[1],avg[2],section[sec]);

}

You might be interested in
How many grams are in 100 pounds?
stepan [7]

Answer:

45359.2 grams are in 100 pounds

Explanation:

Hope this helped, Have a Wonderful Day!!

3 0
3 years ago
Read 2 more answers
Jayden wants to take a current theme but just change a little bit of it. Complete the steps to help Jayden.
Georgia [21]

Answer:

Go to the  

✔ Page Layout

tab on the ribbon and the  

✔ Themes

group.

Click Themes and select one.

Go into the workbook, make the changes, and return to the Themes gallery.

Select  

✔ Save Current Theme

to save the changes.

Explanation:

yup

4 0
3 years ago
What do you mean by an algorithm?<br>​
Over [174]
A program that can be used in many scenarios
8 0
3 years ago
Can someone elaborate on how a PAT should be done?<br>Topic on fake news​
Galina-37 [17]

PAT? explain more i could help

7 0
3 years ago
A single-user database system automatically ensures ____ of the database, because only one transaction is executed at a time.
natta225 [31]
<span>serializability and isolation is the answer.</span>
4 0
3 years ago
Other questions:
  • What are preconceptions?
    9·2 answers
  • Why is it important to match the latencies fo the older modules to the newer modules?
    14·1 answer
  • Ex. Q about the crazy effects of complements/substitutes on a wide range of goods:
    7·1 answer
  • Which html attributes are required in the image () element - check as many as apply
    9·1 answer
  • Which of the following is FALSE? Select one: a. The fast-paced and collaboration-based business environment makes email less use
    10·1 answer
  • We want to use image processing to detect cats in images, how do you do it? Please write down the steps.
    9·1 answer
  • Do you all like IXL?
    8·1 answer
  • 6.6 lesson practice edhesive quiz
    12·1 answer
  • Which of the following is NOT a media file? *<br> .wav<br> .mp4<br> .exe
    10·1 answer
  • Whats worth more in adopt me- A Mega Owl or a Mega Frost Dragon?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!