I'm currently trying to work on a modified problem from C++ Engineering and Science (Chapter 7.2, Problem 4e). I've compiled the project and tried to run it, only to get -858993460 as an output. I don't know if this is a technical problem with the program I'm using (visual studio) or if I just did the program incorrectly, but I've been having these issues since I've first downloaded visual studio, and IDK how to properly fix them. I'll provide the instructions below this (with the modifications in bold), as well as the code I have. All I ask is to get some pointers on how to fix the code. Declare and initialize an array named Resistances that holds the following values: 16, 27, 39, 56, 81. You must also create additional arrays named Current, Voltage, and Power, each with the same size as the Resistances array. Set up a for loop to allow the user to enter the ‘current’ values to be stored in the array named Current when the program is run. (This must be able to accept decimal numbers). You want your program to calculate the value of Voltage for each case with the formula:  Voltage = Resistance * Current. So you will need to set up a formula like: Voltage[i] = Resistance[i] * Current[i] as you cycle through each element in the array. Also find the power dissipated for each case using this formula: Power = Current^2 * Resistance. (So for this also you will need to write your formula for each element within your array ). Finally you should have the voltage and Power values calculated for each of the resistance values. Your output should be displayed as follows: Resistance         Current        Voltage         Power 16                       ______           ______        _____ 27                      ______           ______        ______ And so on   #include #include using namespace std; int main() { const int MAXELS = 5; int i, num, resistance[MAXELS] = { 16, 27, 39, 56, 81 }; num = resistance[0]; const int MAXNUMS = 5; int j, current[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { cout << " " << current[j]; cin >> current[j]; } const int MAXNUMS = 5; int j, double volts[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { volts[j] = current[j] * resistance[j]; cout << current[j] << '\t' << resistance[j] << '\t' << volts[j] << endl; } const int ARRAYSIZE = 5; int k, double power[ARRAYSIZE]; for (k = 0; k < MAXNUMS; k++) { power[k] = resistance[k] * pow(current[k], 2); cout << power[k] << endl; } return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I'm currently trying to work on a modified problem from C++ Engineering and Science (Chapter 7.2, Problem 4e). I've compiled the project and tried to run it, only to get -858993460 as an output. I don't know if this is a technical problem with the program I'm using (visual studio) or if I just did the program incorrectly, but I've been having these issues since I've first downloaded visual studio, and IDK how to properly fix them. I'll provide the instructions below this (with the modifications in bold), as well as the code I have. All I ask is to get some pointers on how to fix the code.

Declare and initialize an array named Resistances that holds the following values: 16, 27, 39, 56, 81. You must also create additional arrays named Current, Voltage, and Power, each with the same size as the Resistances array. Set up a for loop to allow the user to enter the ‘current’ values to be stored in the array named Current when the program is run. (This must be able to accept decimal numbers). You want your program to calculate the value of Voltage for each case with the formula:  Voltage = Resistance * Current. So you will need to set up a formula like: Voltage[i] = Resistance[i] * Current[i] as you cycle through each element in the array. Also find the power dissipated for each case using this formula: Power = Current^2 * Resistance. (So for this also you will need to write your formula for each element within your array ).

Finally you should have the voltage and Power values calculated for each of the resistance values. Your output should be displayed as follows:

Resistance         Current        Voltage         Power

16                       ______           ______        _____

27                      ______           ______        ______

And so on

 

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int MAXELS = 5;
int i, num, resistance[MAXELS] = { 16, 27, 39, 56, 81 };
num = resistance[0];

const int MAXNUMS = 5;
int j, current[MAXNUMS];
for (j = 0; j < MAXNUMS; j++)
{
cout << " " << current[j];
cin >> current[j];
}
const int MAXNUMS = 5;
int j, double volts[MAXNUMS];
for (j = 0; j < MAXNUMS; j++)
{
volts[j] = current[j] * resistance[j];
cout << current[j] << '\t' << resistance[j] << '\t' << volts[j] << endl;
}
const int ARRAYSIZE = 5;
int k, double power[ARRAYSIZE];
for (k = 0; k < MAXNUMS; k++)
{
power[k] = resistance[k] * pow(current[k], 2);
cout << power[k] << endl;
}
return 0;
}

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education