Question #14576

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 <math.h>

#include<iostream>

using namespace std;

int main()

{

& float a,b,c,d,x,pi=3.141592;

int i,j,k;

cout<<"The sin curve is plotted below:& \n\n";

cout<<"-35 & 0 & 35\n";

& cout<<"-------------------------------------------------------------------------->";

& for (i=0;i<22;i++){

x=35*sin(2*pi*i/20);

& // cout<<x<<"\n";

& k=(int)x;

& //cout<<k<<"\n";

& for (j=-35;j<36;j++){

& if(k==j && k>0)

& cout<<"*";

& else{

if(k==j && k<0)

& cout<<"o";

& else&

& cout<<" ";

& }

& }

& cout<<"\n";

}

&

&

&

//// cin>>minNum;

// cout <<" Enter midNum: ";

//cin>>midNum;

system("PAUSE");

}

#include<iostream>

using namespace std;

int main()

{

& float a,b,c,d,x,pi=3.141592;

int i,j,k;

cout<<"The sin curve is plotted below:& \n\n";

cout<<"-35 & 0 & 35\n";

& cout<<"-------------------------------------------------------------------------->";

& for (i=0;i<22;i++){

x=35*sin(2*pi*i/20);

& // cout<<x<<"\n";

& k=(int)x;

& //cout<<k<<"\n";

& for (j=-35;j<36;j++){

& if(k==j && k>0)

& cout<<"*";

& else{

if(k==j && k<0)

& cout<<"o";

& else&

& cout<<" ";

& }

& }

& cout<<"\n";

}

&

&

&

//// cin>>minNum;

// cout <<" Enter midNum: ";

//cin>>midNum;

system("PAUSE");

}

## Comments

## Leave a comment