1. Enter the program at the bottom into your C++ IDE (codeblocks or other) 2. Ru
ID: 2246751 • Letter: 1
Question
1. Enter the program at the bottom into your C++ IDE (codeblocks or other)
2. Run it and figure out what it does
3. Modify the program to plot the curve y = abs(4x3 x4{"version":"1.1","math":"<math xmlns="http://www.w3.org/1998/Math/MathML"><mn>4</mn><msup><mi>x</mi><mn>3</mn></msup><mo> </mo><mo>-</mo><mo> </mo><msup><mi>x</mi><mn>4</mn></msup></math>"} )but choose a range that will display properly in the width of your console window (try some sample values to find an acceptable range. You may also adjust the scale factor.
4. Here is a simple RC circuit. The switch is closed at time t=0 when the voltage V across the capacitor is given by the equationV = E[1 etRC]{"version":"1.1","math":"<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>V</mi><mo> </mo><mo>=</mo><mo> </mo><mi>E</mi><mfenced open="[" close="]"><mrow><mn>1</mn><mo> </mo><mo>-</mo><mo> </mo><msup><mi>e</mi><mrow><mo>-</mo><mfrac><mi>t</mi><mrow><mi>R</mi><mi>C</mi></mrow></mfrac></mrow></msup></mrow></mfenced></math>"}
where E is the voltage of the battery, R is the circuit resistance, C is the value of the capacitor and t is in seconds. Assuming that E=50, R=4000, and C=0.005, modify the program to plot the voltage across the capacitor from t=0 to t=30, in increments of 1 second
5. Demonstrate programs from step 3 and step 4
6. Extra Credit - automatically determine a good scale_factor and range that will generate a good display in a typical console window.
-------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cstdlib>
using namespace std;
int main() {
int x,y;
int scale_factor=1;
char label[]=" y axis";
char axis[]="+------------------------------------------------------>";
cout << label << endl;
cout << axis << endl;
for (x=1; x <= 15; x++) {
y = (pow((x-8),2.0) + 3) / scale_factor;
// y = abs( (int) (4*pow((x),2.0) - pow((x),4.0)))/10;
char line[y];
line[y-1] = 0;
for (int pos=0;pos < y-2;pos++) {
line[pos]=' ';
}
line[y-2] = '*';
cout << setw(2) << x-8 << " " << line << endl;
}
return 0;
}
Explanation / Answer
Question 3
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cstdlib>
using namespace std;
int main() {
int x,y;
int scale_factor=1;
char label[]=" y axis";
char axis[]="+------------------------------------------------------>";
cout << label << endl;
cout << axis << endl;
for (x=1; x <= 15; x++) {
y = abs((4*pow((x),3.0) - pow((x),4.0)))/12;
char line[y];
line[y-1] = 0;
for (int pos=0;pos < y-2;pos++) {
line[pos]=' ';
}
line[y-2] = '*';
cout << setw(2) << x-8 << " " << line << endl;
}
return 0;
}
Question 4
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cstdlib>
using namespace std;
int main() {
int x,y,t;
int scale_factor=1;
char label[]=" y axis";
char axis[]="+------------------------------------------------------>";
cout << label << endl;
cout << axis << endl;
for (x=0; x <= 30; x++)
{
// V = E[1 etRC]
y = abs((int)50*(1-t*4000*0.005));
t=t+1;
char line[y];
line[y-1] = 0;
for (int pos=0;pos < y-2;pos++) {
line[pos]=' ';
}
line[y-2] = '*';
cout << setw(2) << x-8 << " " << line << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.