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π)

Expert's answer

#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;

}

#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;

}

## Comments

## Leave a comment