Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

declares three one-dimensional arrays named volts, current, and resistance in ma

ID: 3529564 • Letter: D

Question

declares three one-dimensional arrays named volts, current, and resistance in main() and be capable of holding 10 double-precision numbers. The numbers to store in current are 10 random numbers The numbers to store in resistance are other 10 random number. program should pass these three arrays to a function named calc_volts(), which should calculate elements in the volts array as the product of the corresponding elements in the current and resistance arrays (volts[1] = current[1] * resistance[1]). the values in the array should be displayed from within main()

Explanation / Answer

#include<iostream>

#include<ctime>

#include<cstdlib>

using namespace std;


void fillArr(double arr[],int size);

void calc_volts(double volts[], double current[],double resistance[], int size);


int main(){

int SIZE =10;

srand((unsigned int)time(NULL));

double volts[SIZE],current[SIZE], resistance[SIZE];


fillArr(current,SIZE);// get random number for current

fillArr(resistance,SIZE);// get random number for resistance

calc_volts(volts,current,resistance,SIZE);//calculate volts


cout<<"# I R Volts ";

for(int i=0;i<SIZE;i++){

cout<<i+1<<" "<<current[i]<<" "<<resistance[i]<<" "<<volts[i]<<endl;

}

cin.get();

return 0;

}


void fillArr(double arr[],int size){

for(int i=0;i<size;i++){

arr[i]=rand()1;//0-100 , change this range if you like

}

return;

}


void calc_volts(double volts[], double current[],double resistance[], int size){

for(int i=0;i<size;i++){

volts[i]=current[i]*resistance[i];

}

return;

}