Question

C Program Assignment: 2-Add comments to your program to full document it by describing the most...

C Program Assignment:

2-Add comments to your program to full document it by describing the most important processes.

3-Your variables names should be very friendly. This means that the names should have meaning related to what they are storing. Example: Instead of naming the variable that stores the hours worked for an employee in a variable called ‘x’ you should name it HoursWorked.

5-Submit your .c program (note that I only need your source code and not all files that are normally part of your project folder)

6-Your program MUST be very modular: use of different sections for different processes (i.e. declarations, input, calculations, output) and functions are covered.

7-Your output MUST friendly (using labels for all info accordingly) and do display all input and calculated fields.

8-you must use arrays and pointers to arrays each time you need to store a value in an array, retrieve a value from an array or process any array in any way including passing a reference of an array to a function or returning a reference to an array from a function.

Problem’s specification: The FEPA (Fictious Environmental Protection Agency), is tasking you for coding an application that monitors the ph of a series of lakes in Florida.

All data are to be stored in 3 arrays with 100 empty entries.

Your input consists of the following: -the ID of the lake (coded as 111, 222, 333, ….etc) -the ph of the lake (acidity value) (value between 0 and 14..must be validated) -the temperature of the lake for this time of the year.

What to do? -Code a menu in a separate function: MENU --------- -1-Add a lake -2-Display a lake -3-Quit -If user select 1 from the MENU, call a function you must code that prompts the user to enter information for a given lake.

-If user select 2 from the MENU, call a function that search for a lake in the array bi ID and if found call a function that determines the acidity of the lake and store the related value in a separate array (to be declared and in parallel with the other arrays) then,

-Call a function that displays a report about this lake (ID, ph, temp, and acidity) A lake is deemed acidic if its ph is between 0 and 7, neutral if it is 7, and basic if it is between

-code a function that print a report showing: Lake name, lake ph, lake temperature, and the status of the lake (acidic, neutral, or basic)

-Code a function/routine that after the user complete the input of all available lakes, displays the lake info. That is the most acidic. Also, display how many lakes the user input for this study.

-Required: your program must prompt the user to input a new lake or quit and must validate the user answer.

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

#pragma warning(disable : 4996)
# include <stdio.h>

// function prototypes
//***********************************************
// shows menu option to user for selection
//***********************************************
void displayMenu();

//***********************************************
// ask user for selecting a opton from 1 to 3
// coontinue asking user untill a valid
// option is selected
// returns the selected option
//***********************************************
int getUserOption();

//***********************************************
// takes input from user and arrays and integer
// as size of arrays as parameters to store data
// adds a lake information from user and
// stores it to given arrays
//***********************************************
void addALake(int* id, float* ph, int* temprature, int size);

//***********************************************
// takes lake data as input parameters and
// prints lake report
//***********************************************
void printLakeReport(int id, float ph, int temprature);

//***********************************************
// takes arrays with lake data and integer as
// size of arrays as parameters
// prints total number of lacks and most acidic
// lack data from the arrays
//***********************************************
void displayMostAcidicLake(int* id, float* ph, int* temprature, int size);

// main function to run program
int main() {
   // create arrays to store data
   // maximum entries is 100
   int MAX_ENTRY = 100;
   int* lake_id = (int*)malloc(sizeof(int) * MAX_ENTRY);
   float* lake_ph = (float*)malloc(sizeof(float) * MAX_ENTRY);
   int* lake_temprature = (int*)malloc(sizeof(int) * MAX_ENTRY);
   int number_of_entries = 0;

   // loop till user enters quit or number of entriess are at maximum
   while (number_of_entries < MAX_ENTRY) {
       // show menu for user interaction
       displayMenu();
       // get user option
       int option = getUserOption();
       // check user option
       if (option == 1) {
           addALake(lake_id, lake_ph, lake_temprature, number_of_entries);
           number_of_entries++;
       }
       else if (option == 2) {
           // ask user for lack id to search
           printf("Enter lake ID: ");
           int id;
           scanf("%d", &id);
           int lake_index = -1; // index of lake with given id
           // check if lake with given id exist
           for (int i = 0; i < number_of_entries; i++) {
               if (lake_id[i] == id) {
                   lake_index = i;
               }
           }
           // print lake report if found
           if (lake_index > -1) {
               printLakeReport(lake_id[lake_index], lake_ph[lake_index], lake_temprature[lake_index]);
           }
           else {
               printf("Lake with given ID does not exist in data!\n");
           }
       }
       else {
           // user selected quit
           break;
       }
   }
   // print most acidic lake
   displayMostAcidicLake(lake_id, lake_ph, lake_temprature, number_of_entries);
   // free memory
   free(lake_id);
   free(lake_ph);
   free(lake_temprature);

   return 0;
}

// function declaration

void displayMenu() {
   printf("\nMENU\n---------\n");
   printf("1) Add a lake\n");
   printf("2) Display a lake\n");
   printf("3) Quit\n");
}

int getUserOption() {
   printf("Select: ");
   int option;
   scanf("%d", &option);
   // check for valid option
   while (option < 1 || option > 3) {
       printf("Invalid opton!\n");
       printf("Enter integer from 1 to 3: ");
       scanf("%d", &option);
   }
   return option;
}

void addALake(int* id, float* ph, int* temprature, int size) {
   // take input from user
   printf("Enter id of lack: ");
   int lack_id;
   scanf("%d", &lack_id);
   // validate user input
   // check if lack with given id already exist
   for (int i = 0; i < size; i++) {
       if (id[i] == lack_id) {
           // print error
           printf("Lake with given ID already exist in database!\n");
           return;
       }
   }
   // take ph value for the lack
   printf("Enter ph value for the lack: ");
   float lack_ph;
   scanf("%f", &lack_ph);
   // validate user input
   if (lack_ph < 0 || lack_ph > 14) {
       printf("Invalid ph value!\n");
       return;
   }
   // take temprature of the lake
   printf("Enter temprature of the lack(in celcius): ");
   int lake_temprature;
   scanf("%d", &lake_temprature);
   // enter lake data into arrays
   id[size] = lack_id;
   ph[size] = lack_ph;
   temprature[size] = lake_temprature;
}

void printLakeReport(int id, float ph, int temprature) {
   printf("\nLake ID: %d\n", id);
   printf("Lake pH: %.1f\n", ph);
   printf("Lake Temprature: %d celcius\n", temprature);
   printf("Lake Status: ");
   // print lake status based on ph value
   if (ph == 7) {
       printf("neutral\n");
   }
   else if (ph < 7) {
       printf("acidic\n");
   }
   else {
       printf("basic\n");
   }
}

void displayMostAcidicLake(int* id, float* ph, int* temprature, int size) {
   // print total number of lake
   printf("\nTotal lake entered: %d\n", size);
   // get index of most acidic lake
   int index = 0;
   // most acidic lake have lowest ph
   int lowest_ph = 14; // lowest ph found in array, initialize with highest ph value
   for (int i = 0; i < size; i++) {
       if (lowest_ph > ph[i]) {
           // reset index
           index = i;
           // reset lowest ph
           lowest_ph = ph[i];
       }
   }
   // display data for most acidic lake
   printf("Most acidic Lake: \n");
   printLakeReport(id[index], ph[index], temprature[index]);
}

let me know if you have any problem or doubt. thank you.

Add a comment
Know the answer?
Add Answer to:
C Program Assignment: 2-Add comments to your program to full document it by describing the most...
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
  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...

    PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program to hold information about the gemstones he has in his safe. Offer the jewelry designer the following menu that loops until he chooses option 4. 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit ------------------------------------- Gemstone data: ID number (int > 0, must be unique) Gem Name (string, length < 15)...

  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • The goal of this assignment is to give you some experience building a program that uses...

    The goal of this assignment is to give you some experience building a program that uses objects. You must work in teams of 2 to complete this assignment. You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to the user to allow the user to select a transaction like deposit, withdraw, transfer, create a bank account, and quit the program. The program should allow a user to...

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
ADVERTISEMENT