Question: I need help finding if I wrote this program correctly: 7. (Power generation) One major source of electricity is hydroelectric generation, in which flowing water
I need help finding if I wrote this program correctly: 7. (Power generation) One major source of electricity is hydroelectric generation, in which flowing water is redirected to turn a turbine generator. The power generated by this water flow is given by this formula: P\:=\: ho\times Q\times H\times g P = ? Q H g P\: P is the power generated by the water flow (watts = J/s = kg-m2/s2-1/s). ho ? is the water density (kg/m3). Q Q is the volume flow rate (m3/s). g g is the acceleration caused by gravity (9.81 m/s2). H H is the distance (in m) water falls on its way to the generator, known as the head. a. Using this formula, write a C++ function named powerGen() that accepts two double-precision arguments (one for the head distance and one for the water flow) and returns the power generated in watts. b. Include the function written for Exercise 7a in a working C++ program. Be sure to write the definition of this powerGen() function AFTER your main() function in the source code file and declare powerGen() using a function prototype BEFORE the header of your main() function. Verify that your program is working correctly by determining the watts generated by a head of 14 meters of water flowing at 20 m3/s. After verifying that your program is working correctly, use it to determine the watts generated by a head of 30 meters of water flowing at 20 m3/s. This is the code: #include "stdafx.h" #include using namespace std; double powerGen(double distance, double waterFlor); int main() { double distance = 14.0; double waterFlow = 20.0; cout << "The results for case 1" << endl; cout << "The power generated(in watts) is " << powerGen(distance, waterFlow); cout << "Expected Result = 2746800 : done manually" << endl; distance = 30.0; waterFlow = 20.0; cout << "The results for case 2"<
Here is the code:
#include "stdafx.h"
#include
using namespace std;
double powerGen(double distance, double waterFlor);
int main()
{
double distance = 14.0;
double waterFlow = 20.0;
cout << "The results for case 1" << endl;
cout << "The power generated(in watts) is " << powerGen(distance, waterFlow);
cout << "Expected Result = 2746800 : done manually" << endl;
distance = 30.0;
waterFlow = 20.0;
cout << "The results for case 2"< cout << "The power generated(in watts) is " << powerGen(distance, waterFlow); cout << "Expected Result = 5886000 : done manually" << endl; cin.get(); cin.ignore(); return 0; } double powerGen(double distance, double waterFlow) { double density = 100.0; double g = 9.81; double power = density*g*distance*waterFlow; return power; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
