atistics and1 or 2 dimensioned vectors (Add ONU 7) write a C++ program that crea
ID: 3807348 • Letter: A
Question
atistics and1 or 2 dimensioned vectors (Add ONU 7) write a C++ program that creates the following eight two dimensional random number vectors (a) the voltage vector v contains nx m voltages 100 and 1000 volts, (where n between Mrows, maN columns) (b) the current vector I00 contains nxm Amps, currents between 10 and 50 (c) the phase vector PH00 contains nxm phase angles between o and 45 degrees (Note the degrees must be converted into radians before using any formulas) (d) The power vector (units of Watts) is given by POD V00 IDO. (PHOO'MLPI/180); cos (e) The reaction vector units of VARs) is given by Q00 VOD 100 sin(PH00 M P/180 The Bill vector units of dollars) is given by Cin» rate Bill00 rate VDO IDI where rate is the cost of electricity per kilowatt hour (see instructor for rate )entered by user (g) Finally, the user will enter a desired power factor see instructor for this value); and your program will calculate the shunt capacitor required to create the new desired power factor, and the corresponding reduced power bill. Cin>> PF; New bill 00 sqrt(po (Q00- POD tan(acos PF) (anD-P00 tanlacos(PF) Note you will need a double for loop to carry out the above calculations Your program should print out the original values of P00 c00, Int seed time(NULL); srand(seed);Explanation / Answer
Here is the code for you:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cmath>
#define SIZE 10
using namespace std;
void generateRandoms(int array[][SIZE], int rows, int cols, int low, int high)
{
for(int i = 0; i < rows; i++)
for(int j = 0; j < cols; j++)
array[i][j] = rand() % (high - low + 1) + low;
}
void printArray(double array[][SIZE], int rows, int cols)
{
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
cout << fixed << setprecision(3) << array[i][j] << " ";
cout << endl;
}
}
int main()
{
int voltage[SIZE][SIZE], phase[SIZE][SIZE], current[SIZE][SIZE];
double power[SIZE][SIZE], reaction[SIZE][SIZE], bill[SIZE][SIZE];
double shuntCapacitor[SIZE][SIZE], newBill[SIZE][SIZE];
double rate, powerFactor;
srand(time(NULL));
//a. The voltage vector contains n x m voltages between 100 and 1000 volts.
generateRandoms(voltage, SIZE, SIZE, 100, 1000);
//b. The current vector contains n x m currents between 10 and 50 Amps.
generateRandoms(current, SIZE, SIZE, 10, 50);
//c. The phase vector contains n x m phase angles between 0 and 45 degrees.
generateRandoms(phase, SIZE, SIZE, 0, 45);
//d. The power vector (units in Watts) calculated.
for(int i = 0; i < SIZE; i++)
for(int j = 0; j < SIZE; j++)
power[i][j] = voltage[i][j] * cos(phase[i][j] * M_PI / 180);
//e. The reaction vector (units in VARs) calculated.
for(int i = 0; i < SIZE; i++)
for(int j = 0; j < SIZE; j++)
reaction[i][j] = voltage[i][j] * current[i][j] * sin(phase[i][j] * M_PI / 180);
//f. The bill vector (units in dollars) calculated.
cout << "Enter the cost of electricity per killowatt hour: ";
cin >> rate;
for(int i = 0; i < SIZE; i++)
for(int j = 0; j < SIZE; j++)
bill[i][j] = rate * voltage[i][j] * current[i][j];
//g. The shunt capacitor required to create new desired power factor. calculated.
cout << "Enter the power factor: ";
cin >> powerFactor;
for(int i = 0; i < SIZE; i++)
for(int j = 0; j < SIZE; j++)
{
shuntCapacitor[i][j] = (reaction[i][j] - power[i][j] * tan(acos(powerFactor))) / (377 * pow(voltage[i][j], 2));
newBill[i][j] = sqrt(pow(power[i][j], 2) + (reaction[i][j] - power[i][j] * tan(acos(powerFactor))) * (reaction[i][j] - power[i][j] * tan(acos(powerFactor))));
}
cout << "The power vector is: " << endl;
printArray(power, SIZE, SIZE);
cout << endl << endl << "The reaction vector is: " << endl;
printArray(reaction, SIZE, SIZE);
cout << endl << endl << "The bill vector is: " << endl;
printArray(bill, SIZE, SIZE);
cout << endl << endl << "The shunt capacitor vector is: " << endl;
printArray(shuntCapacitor, SIZE, SIZE);
cout << endl << endl << "The new bill vector is: " << endl;
printArray(newBill, SIZE, SIZE);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.