Write a C/C+ program uses nested for loops to take input values for 3 two dimens
ID: 3933012 • Letter: W
Question
Write a C/C+ program uses nested for loops to take input values for 3 two dimensional (n x m) arrays, you can name the arrays VOLTS(N1l.l.CURRENT[N][M], PHASE[N][M].Then calculate the product of these arrays by using a fourth array Watts(NI[M), where Watts[N][M] = V[N][M]* cos(x*PHASE[N][M]) Then you can calculate a fifth array called VARS[N][M] = V[N][M]*CURRENT[N][M]) Finally compute the electric bill with a sixth array BILL[N][M] by using the following formula: BILL[N][M] = rate* squareroot ((Watts[N][M]* WATTS[N][M]) +(VARS[N][M] * VARS(N][M1])) Where x is the conversion factor to convert from degrees to radians. (x = 0.0174) Use nested for loops with integers N and M as indexes to input the array values and to calculate output results. Also use for loops with display statements to print out the elements in array Watts, VARS and BILL. After writing your code, test with the following values: VOLTS = (220, 120; 460, 330} CURRENT = [35, 28; 42, 22) PHASE() = {20, 30; 35, 45) Rate = 0.175Explanation / Answer
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define x 0.0174
int main(){
const int N = 2;
const int M = 2;
double VOLTS[N][M];
double CURRENT[N][M];
double PHASE[N][M];
double WATTS[N][M];
double VARS[N][M];
double BILLS[N][M];
//take in input volts
cout << "Enter " << N*M << " values of VOLTS: "<< endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cin >> VOLTS[i][j];
}}
//take in input current
cout << "Enter " << N*M << " values of CURRENT: "<< endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cin >> CURRENT[i][j];
}}
//take in input phase
cout << "Enter " << N*M << " values of PHASE: "<< endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cin >> PHASE[i][j];
}}
double rate = 0.0;
cout << "Enter rate: ";
cin >> rate;
cout << "WATTS: " << endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
WATTS[i][j] = VOLTS[i][j]*CURRENT[i][j]*cos( x*PHASE[N][M] );
cout << WATTS[i][j] << " ";
}
cout << endl;
}
cout << "VARS: " << endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
VARS[i][j] = VOLTS[i][j]*CURRENT[i][j]*sin( x*PHASE[N][M] );
cout << VARS[i][j] << " ";
}
cout << endl;
}
cout << "BILLS: " << endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
BILLS[i][j] = rate*sqrt( WATTS[i][j]*WATTS[i][j] + VARS[i][j]*VARS[i][j] );
cout << BILLS[i][j] << " ";
}
cout << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.