c program. It must be determined whether the beach is to be closed or not. Right after the average has been output, you will need an if statement to decide whether the beach is to be closed or not. If the average is below 3500 print out the beach number and a short message that the beach is safe; if greater than or equal to 3500 print out the beach number and a short message that the beach is closed.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

c program. It must be determined whether the beach is to be closed or not. Right after the average has been output, you will need an if statement to decide whether the beach is to be closed or not. If the average is below 3500 print out the beach number and a short message that the beach is safe; if greater than or equal to 3500 print out the beach number and a short message that the beach is closed.

  1. , add a report to count the total number of beaches in the file and how many are open, and how many are closed.

//include the required header file.

#include "stdio.h"

//Define the main function.

int main(void)

{

    //Declare the variable.

    int b_num, num_samples, num_orgs_per_100;

    char c = 'a';

   

    //Create a file pointer.

    FILE *in_file;

    //Open the file in read mode.

    in_file = fopen("inp.txt", "r");

   

    //Check if the file exists.

    if (in_file == NULL)

        printf("Error opening the file.\n");

   

    //Read the data from the file.

    else

    {

      //Get the beach number and number of

      //samples from the file.

      fscanf(in_file, "%d", &b_num);

      fscanf(in_file, "%d", &num_samples);

     

      //Check for end of file and beach

      //number value and dispaly the samples.

      while(!feof(in_file))

      {

        printf("\nb_num = %d, num_samples = %d",

                b_num,num_samples);

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

        {

           fscanf(in_file, "%d", &num_orgs_per_100);

          //Display the input number.

          printf("\nSample value %d: %d",i+1,

                  num_orgs_per_100);

        }

       

        //Read the newline, number of samples and b_num for

        //next record

        fscanf(in_file, "%c", &c);

        printf("\n");

        fscanf(in_file, "%d", &b_num);

        fscanf(in_file, "%d", &num_samples);

      }}

   

    //Close the file.

    fclose(in_file);

  

    return 0;

}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education