Answer to Question #15124 in C++ for Zac

Question #15124
Write a C++ program with a nested loop structure that displays the sinusoidal curve
f(α)=35sin(α) in ‘*’ for f(α) ≥ 0 and in ‘o’ for f(α) < 0 as shown in Fig. 1. The curve
starts at α=0, and the sampling step-size of the curve is 0.1π. You program should plot
at least a full cycle (0 ≤ α ≤ 2π)
1
Expert's answer
2012-10-01T10:14:46-0400
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

double f(double a) {
return 35 * sin(a * M_PI / 180);
}

int main() {
cout.setf(ios::fixed);
cout.precision(4);
for (double a = 0; a <= 360; a += 18) {
& double y = f(a);
& cout << setw(8) << y << setw(8) << ((y >= 0) ? "*" : "o") << endl;
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS