Question

//*we need to do it with C programming *// ENGR 200 P5: CARNOT EFFICIENCY OF POWER...

//*we need to do it with C programming *//

ENGR 200 P5: CARNOT EFFICIENCY OF POWER PLANTS (if statements, loops) DUE: . U.S. Central Time POINTS: 55 INTRODUCTION: In thermodynamics, energy can be neither created nor destroyed (1st law): it is either converted to usable work or lost as waste heat. The second law of thermodynamics states that the total entropy (disorder) of a system will never decrease over time; that is, systems can only be at constant entropy or have increasing entropy. This may be restated by saying that there is an upper limit to the efficiency of the conversion of heat to work, as in a heat engine. From these principles of thermodynamics, it is clear that there is an upper limit to how efficient power generation can be at most power plants. Many power plants, including those fueled by fossil fuels, nuclear sources, geothermal sources, biomass, and solar thermal, operate by generating a source of heat (burning fossil fuels, reacting nuclear materials, using the sun’s rays, etc.), using this heat source to heat water to steam, and passing this steam through a turbine. When the turbine spins, power is generated. The maximum thermodynamic efficiency of a power plant is dictated by the temperatures of the hot reservoir (that is, the steam) and the cold reservoir (the cooling fluid in place). Ideally, the thermodynamic efficiency of the plant would be based on these temperatures, as in the Carnot cycle: η =1-T_C/T_H where η is the efficiency (unitless), TL is the temperature of the cold stream (either in Kelvin or in Rankine), and TH is the temperature of the hot stream, that is, the steam (either in Kelvin or in Rankine). You have a data file called power.txt which shows the temperatures in Kelvin of the steam (TH) and of the cooling fluid (TC) for several different power plants. This data file has a control number and is space delimited. ASSIGNMENT: Write a C program that calculates the Carnot efficiency of power plants with the provided TH and TC streams as shown in the power.txt file. The output should print as a table to the screen and to an output file called efficiency.txt. Use the “Code Sections.c” template on Blackboard to write your code. Your program output will look like the illustration shown below. Use your PC’s cursor to determine the horizontal and vertical spacing for the output format. OUTPUT FORMAT: ******************************************** POWER PLANT CARNOT EFFICIENCY STEAM TEMP COOLING TEMP EFFICIENCY xxx xxx x.xx . . . . . . . . . ******************************************** SUBMITTING ASSIGNMENTS: Once you have your program working, exit the C compiler that you are using. Make sure that your source program file name conforms to the following specifications: sn_pn_first_last where: sn is your section number (1, 2, 3, 4, 5, …) pn is the program number (1, 2, 3, 4, 5, …) first is your first name last is your last name An example for the fifth assignment would be 1_5_elmer_fudd. Submission: Submit your source program using the Assignments button in Blackboard. Remember to submit your C source program in standard ANSI C format only. No other format will be accepted. If you make changes to your program and need to resubmit, rename the file such as 1_5_elmer_fudd_2 or 1_5_elmer_fudd_3, etc. Then use the Assignments button in Blackboard to submit the new version. Only the most current submitted program version will be graded.

9
798.15 298.15
723.15 273.15
798.15 323.15
873.15 273.15
823.15 373.15
773.15 298.15
823.15 423.15
848.15 298.15
348.15 298.15
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <stdio.h>
#include <stdlib.h> // For exit(),atof() function
#include <string.h> //For strok()
int main()
{   //Pointer of type File: to communicate between program and file
    FILE* fp;
    //Char Array to store data read from file
    char line[255];
    //Array to store temperature_high,temperature_low values
    float T_C[100];
    float T_H[100];
    //To store efficiency
    float efficiency;
    //Opening Power.txt in read Mode
    fp = fopen("power.txt" , "r");
    //Check if power.txt file is available
    if(fp == NULL)
     {
       printf("Error Reading File power.txt!");
       exit(1);
     }
    //For increasing index of T_C, T_H array
    int i=0;
    //reading file line by line , till it gets to end
    while (fgets(line, sizeof(line), fp) != NULL)
    {   //Splitting line w.r.t " " a space
   //Storing data before in Val1
        const char* val1 = strtok(line, " ");
   //Stornig Data after space in val2
        const char* val2 = strtok(NULL, " ");
   //Converting them in Float and Storing them in respective array
   T_H[i]=atof(val1);
   T_C[i]=atof(val2);
   //incrementing i, to store data in next iteration at incremented index
   i++;
    }
    //Reading Done : Closing File handler
    fclose(fp);
    //openin efficiency.txt in write and binary mode
    fp = fopen("efficiency.txt","wb");
     if(fp == NULL)
     {
       printf("Error writing to file efficiency.txt !");
       exit(1);
     }
     printf("Efficiency :\n");
//Calculating Efficiency of each data and writing it back in efficiency.txt
    for (int j=0;j<i;j++)
    { //Calculating efficiency
   efficiency=((1-T_C[j])/(T_H[j]));
   printf("%f\n",efficiency);
   //Writing data in efficiency.txt
   fprintf(fp,"%f",efficiency);
   //Writing new line after writing data in efficiency.txt
   fprintf(fp,"%s","\n");
     }
//Writing Done : Closing File handler
   fclose(fp);
    return 0;
}

CONSOLE OUTPUT , OUTPUT FILE DATA, INPUT FILE DATA:

Add a comment
Know the answer?
Add Answer to:
//*we need to do it with C programming *// ENGR 200 P5: CARNOT EFFICIENCY OF POWER...
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
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