Write a program that calculates voltage from current and resistance values. Writ
ID: 3765561 • Letter: W
Question
Write a program that calculates voltage from current and resistance values.
Write the calcVolts() function (prototype, header, body) using pointers.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int max_num = 10;
int k;
double current[max_num], resistance[max_num], calc_volts[max_num];
for (k = 0; k < max_num; k++ )
{
cout << "Please Enter the ten values given for resistance:";
cin >> current[k];
cout << "Now enter ten values for the resistance: ";
cin >> resistance[k];
}
for (k = 0; k < max_num; k++ )
{
calc_volts[k] = current[k] * resistance[k];
}
cout << " Current Resistance Volts" << endl;
for (k = 0; k< max_num; k++ )
{
cout << setw(7) << current[k] << setw(11) << resistance[k]
<< setw(11) << calc_volts[k] << endl;
}
}
Explanation / Answer
#include<iostream>
#include<array>
#include<stdio.h>
using namespace std;
void calcVolts(float*, float*, float*);
int main()
{
array<float, 10> voltage;
float cur[5]{10.62, 14.89, 13.21, 16.55, 18.62 };
float res[5]{ 15.3,3.0, 5.4, 2.9, 4.8};
printf("Current x Resistance = Voltage ");
calcVolts(cur,res,voltage);
}
void calcVolts(float *cu,float *re,float *vo)
{
for (int i=0; i!=5; ++i)
{
vo[i]=cu[i]*re[i];
printf("%4f %8f %13f ", cu[i], re[i], vo[i]);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.