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
leva [86]
3 years ago
15

Write a program that opens a text le called quiz.txt for reading. This le contains a single line with a student's rst name then

one space, then the student's last name, then one space, then some number of quiz scores that, if they exists, are separated by one space. The student will have between zero and ten scores (inclusive), and each score is an integer between 0 and 100 (inclusive). The le may or may not end with a new line character. Your program will read the data from this le and write its output to a second le. The data in the output le (named average.txt) will contain the student's quiz scores followed by the average of the student's quiz scores. The output le must be formatted as described below. 1. Each quiz score should be listed in a right-justied column that is 4 characters wide. Note that if a student has fewer than 10 scores (they have missed one or more of the quizzes), your program will need to display the missing score(s) using 0 for each one. 2. The average should appear in its own column that is 10 characters wide. Note that if a student has fewer than 10 scores, the average is still the sum of the quiz scores divided by 10. 3. The average should be computed with an accuracy of two decimal places.
Computers and Technology
1 answer:
musickatia [10]3 years ago
7 0

Answer:

See explaination for code

Explanation:

Program code:

#include<stdio.h>

#include<stdlib.h>

//definition of the function readFile()

//reads the data from the input file

void readFile(FILE *input, char firstName[], char lastName[], int scores[])

{

int i;

//Initializes the quiz scores to zero

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

scores[i] = 0;

//Read the first name then last name

fscanf(input, "%s %s", firstName, lastName);

//Read the 10 Quiz scores

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

fscanf(input, "%d", &scores[i]);

}

//definition of the function writeFile()

//write the data into the output file

void writeFile(FILE *output, char firstName[], char lastName[], int scores[])

{

int c, sum = 0;

float average;

int len1 = strlen(lastName);

int j = 0;

char name[20];

//assign the lastName to name array

for (j = 0; j < len1; ++j)

{

name[j] = lastName[j];

}

name[j] = ',';

j++;

//append the space after the comma in name array.

name[j] = ' ';

j++;

int k = 0;

//find the length of the firstName

len1 = strlen(firstName);

//append the firstName after the space in name array.

for (k = 0; k < len1; ++k, j++)

{

name[j] = firstName[k];

}

//assign the last character of name is null

name[j] = '\0';

//Writes Last name then first name with specified size and alignment

fprintf(output, "%-20s", name);

//Writes the 10 quiz scores with specified size

//and alignment and calculates the sum

for (c = 0; c < 10; c++)

{

fprintf(output, "%4d", scores[c]);

sum += scores[c];

}

//Calculates the average

average = (float)sum / 10;

//Writes the average

fprintf(output, "%10.2f", average);

//Writes the next line

fprintf(output, "\n");

}

//definition of the function copyIntoInputFile()

//copies the data from input file to output file

void copyIntoInputFile(FILE *from, FILE *to)

{

char data[130];

while (fgets(data, 130, from))

{

fprintf(to, "%s", data);

}

}

int main()

{

//open the input file in read mode

FILE *input = fopen("quiz.txt", "r");

//open the output file in write mode

FILE *output = fopen("average.txt", "w+");

//declare the variables

char scoresHeading[][4] = { "1", "2" , "3", "4", "5", "6", "7","8","9","10" };

char firstName[20], lastName[20];

int quiz[10], average, c = 0;

//Checks whether the file can able to open or not

if (input == NULL)

{

printf("Unable to open the file.\n");

return 0;

}

else

{

//print the heading the output file

fprintf(output, "%-20s", "Name");

for (int i = 0; i < 10; ++i)

{

//print the grades a right justified column that is 4 characters wide.

fprintf(output, "%4s", scoresHeading[i]);

}

//print average right justified column that is 10 characters wide

fprintf(output, "%10s\n", "Average");

//read the file

while (!feof(input))

{

//call the method readFile to read the file

readFile(input, firstName, lastName, quiz);

//call the method writeFile to write

writeFile(output, firstName, lastName, quiz);

}

}

//Close both the files

fclose(input);

fclose(output);

//open the files

input = fopen("average.txt", "r");

output = fopen("quiz.txt", "w+");

//call the function copyIntoInputFile

copyIntoInputFile(input, output);

return 0;

}

You might be interested in
Human systems integration (hsi), a supportability issue that every program should consider, addresses such factors as accessibil
Tju [1.3M]

I guess the word in the blank is Standardization.

Human systems integration (HSI), a supportability issue that every program should consider, addresses such factors as accessibility, visibility, testability, and Standardization.


6 0
3 years ago
Read the following example cover letter:
enot [183]

Answer:

All should be added.

Explanation:

All of these are important to your cover letter to make it seem professional.

Hope this helped

3 0
4 years ago
Read 2 more answers
Who was responsible for the development of the rocket motor?
kiruha [24]

Answer: Robert H. Goddard

Explanation: he developed and flew the first liquid-propellant rocket

6 0
3 years ago
Read 2 more answers
Jensen is a senior developer for Hackers R'Us, a company that helps secure management information systems. Jensen's new task is
Harlamova29_29 [7]

Answer:

b. white-hat hacker

Explanation:

A White-hat Hacker, also known as an Ethical Hacker is an information security specialist, known for performing penetration testing and checks in search for information and communications system's vulnerabilities on demand for his/her clients.

These efforts are meant to find security risks before someone else does, who could cause any kind of damage to the systems or unauthorized access to sensitive information

6 0
3 years ago
Calculate the data rate capacity for a 2400 baud signal where there are M=8 levels per symbol. a. 2400 bps b. 4800 bps c. 7200 b
zimovet [89]

Answer:

C. 7200 bps.

Explanation:

In networking, transmission lines or connectors and ports operates at a specific speed based on the port type and the cable or medium of transmission.

Baud rate is a concept in digital information technology that defines the rate of symbol per channel during transmission. The bit or data rate is the number of bits transfered in a link per second.

The relationship between baud rate and bit rate is;

Bit rate = baud rate x number of symbol bit level

To get the bit rate of a 2400 baud signal with symbol level = 8 = 2^3

Bit rate = 2400 x 3. = 7200 bps.

7 0
3 years ago
Other questions:
  • The __________ vulnerability assessment is a process designed to find and document selected vulnerabilities that are likely to b
    15·1 answer
  • 0001 0000 1100 0011 (unsigned, that is, interpreted as b2u)i.8 bit truncated value:ii.does the value change when truncated to 8
    7·1 answer
  • Create a function named first_a that uses a list comprehension. The function will take a single integer parameter n. Find every
    13·1 answer
  • Write a function in Java to implement the following logic:
    13·1 answer
  • Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "
    14·1 answer
  • Write a method named removeRange that accepts an ArrayList of integers and two integer values min and max as parameters and remo
    10·1 answer
  • How do I get the bot token for discord? (scripting etc)
    5·1 answer
  • If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook? (6 points)
    14·1 answer
  • Describe your ideas for a keyboarding game that would help someone improve their skills.
    6·1 answer
  • The ______ engine compares your entry against its database and returns a list of hits or sites that contain the keywords. (hint:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!