Can you please write me a C++ program in Codeblocks for this problem? thanks. El
ID: 3873635 • Letter: C
Question
Can you please write me a C++ program in Codeblocks for this problem? thanks.
Electrical eng.) a. An electrical manufacturer tests five generators by measuring their output voltages at three different ti generator's test results, and then computes and displays the average voltage for each generator. Assume the following generator test results: 3. ( 1st generator: 122.5 122.7 123.0 2nd generator: 120.2 127.0 125.1 3rd generator: 121.7 124.9 126.0 4th generator: 122.9 123.8 126.7 5th generator: 121.5 124.7 122.6 b. Modify the program written for Exercise 3a to calculate and display the average voltage for all the generators. (Hint: Use a second variable to store the total of all the generator's voltages.)Explanation / Answer
3a) C++ code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int g = 1;
double Average[5] ;
while(g<=5)
{
double t1,t2,t3;
cout << "Generator " << g << ": ";
cin >> t1; cin >> t2; cin >> t3;
Average[g-1] = (t1 + t2 + t3)/3;
g++;
}
for (int i = 0; i < 5; ++i)
{
cout << "Average of Readings for Generator " << (i+1) << " = " << Average[i] << endl;
}
return 0;
}
3b) C++ code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int g = 1;
double Average[5] ;
while(g<=5)
{
double t1,t2,t3;
cout << "Generator " << g << ": ";
cin >> t1; cin >> t2; cin >> t3;
Average[g-1] = (t1 + t2 + t3)/3;
g++;
}
double summ = 0;
for (int i = 0; i < 5; ++i)
{
cout << "Average of Readings for Generator " << (i+1) << " = " << Average[i] << endl;
summ = summ + Average[i];
}
cout << "Average voltage for all Generators = " << summ/5 << endl;
return 0;
}
Sample Output:
Generator 1: 122.5 122.7 123.0
Generator 2: 120.2 127.0 125.1
Generator 3: 121.7 124.9 126.0
Generator 4: 122.9 123.8 126.7
Generator 5: 121.5 124.7 122.6
Average of Readings for Generator 1 = 122.733
Average of Readings for Generator 2 = 124.1
Average of Readings for Generator 3 = 124.2
Average of Readings for Generator 4 = 124.467
Average of Readings for Generator 5 = 122.933
Average voltage for all Generators = 123.687
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.