Write a program which inputs an integer value, incr, from the user at the keyboard, and then displays a graph of the sine of the degree values from 0 to 180, in increments of incr. You must use the sin function (in a similar manner to ceil and floor) to find the sine. Note that the sin function only operates on radians so the degree value must first be converted to radians. To do so, multiply the degree value by π (3.14159) and divide by 180.
To generate the graph, the printStars function given. One star must be generated for every 0.05 of the sine value. Also, you can use “\t” (tab character) to separate the degree value from the stars in the output.
#include <iostream> #include <cmath> using namespace std;
#define PI 3.14159 void printStars (int n) { int i; for (i=1; i<=n; i=i+1) cout << "*"; } int main () { return 0; }
WRITTEN IN C++
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.14159
void printStars (int n) {
int i;
for (i=1; i<=n; i=i+1)
cout << "*";
cout<<"\t\t\t";
}
int main () {
int incr;
cin>>incr;
double cur=0;
while(cur<=180){
double radians=(cur*PI)/180;
double value=sin(radians)/0.05;
cout<<cur<<"\t";
printStars(value);
cout<<endl;
cur+=incr;
}
}
/* not exactly confirmed how you want to print the graph from the above question using '*' , please do the correspoding changes of spacing and all using "\t" charcter */
Get Answers For Free
Most questions answered within 1 hours.