Using visual studio and the program code below, modify the program code so the o
ID: 3856302 • Letter: U
Question
Using visual studio and the program code below, modify the program code so the out put will display a graph line using the information given to you below:
When the switch shown in Figure 7.14 is closed at time t = 0, the voltage, V, across the capacitor, C, is given by this formula:
V = E(1 - e-t/RC)
E is the voltage of the battery.
R is the resistance in the circuit.
C is the value of the capacitance.
e is Euler's number (2.71828 . . .).
t is the time in seconds
Assuming E = 50, R = 4000, and C = 0.005, modify Program 7.13 to plot the voltage across the capacitor from t = 0 to t = 60 in increments of 2 seconds.
Program7.13
#include
#include
using namespace std;
int main()
{
const int MAXPOINTS = 100;
int i, npts, nval[MAXPOINTS];
double x, fval, ymin, ymax, width, sval[MAXPOINTS];
char label[] = " y axis";
char axis[] = "+---------------------------------------------------->";
char line[] = "| ";
ymax = 1.0e-5;
ymin = 1.0e5;
width = 53;
// load the data to be plotted and find the max and min values
i = 1;
for(x = -5.0; x <= 5.0; x += 0.5)
{
sval[i] = pow(x,3.0);
if (sval[i] > ymax) ymax = sval[i];
if (sval[i] < ymin) ymin = sval[i];
i++;
if (i >= MAXPOINTS) break; // don't exceed the maximum points
}
npts = i - 1;
// scale all the y values
for (i=1; i <= npts; i++)
{
fval = (sval[i] - ymin)/(ymax - ymin) * (width - 1) + 1;
nval[i] = fval + 0.5; // convert to an integer value
}
// produce the plot
cout << "Minimum y value: " << ymin << endl;
cout << "Maximum y value: " << ymax << endl;
cout << label << endl;
cout << axis << endl;
for (i = 1; i <= npts; i++)
{
line[(nval[i] + 2)] = '*'; // set character to an asterisk
cout << line << endl; // output the line
line[(nval[i] + 2)] = ' '; // reset character to a blank
}
return 0;
}
Switch E Figure 7.14 a simple RC circuitExplanation / Answer
using namespace std;
int main()
{
const int MAXPOINTS = 100;
int i, npts, nval[MAXPOINTS];
double x, fval, ymin, ymax, width, sval[MAXPOINTS];
char label[] = " y axis";
char axis[] = "+---------------------------------------------------->";
char line[] = "| ";
ymax = 1.0e-5;
ymin = 1.0e5;
width = 53;
// load the data to be plotted and find the max and min values
i = 1;
for(x = -5.0; x <= 5.0; x += 0.5)
{
sval[i] = pow(x,3.0);
if (sval[i] > ymax) ymax = sval[i];
if (sval[i] < ymin) ymin = sval[i];
i++;
if (i >= MAXPOINTS) break; // don't exceed the maximum points
}
npts = i - 1;
// scale all the y values
for (i=1; i <= npts; i++)
{
fval = (sval[i] - ymin)/(ymax - ymin) * (width - 1) + 1;
nval[i] = fval + 0.5; // convert to an integer value
}
// produce the plot
cout << "Minimum y value: " << ymin << endl;
cout << "Maximum y value: " << ymax << endl;
cout << label << endl;
cout << axis << endl;
for (i = 1; i <= npts; i++)
{
line[(nval[i] + 2)] = '*'; // set character to an asterisk
cout << line << endl; // output the line
line[(nval[i] + 2)] = ' '; // reset character to a blank
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.