- #1
red123
- 22
- 0
Homework Statement
Write a program that plots and labels the points of the sine function.
Homework Equations
I can't figure out how to give the points horizontal position. I think it's position is determined by printing a series of 'space' characters followed by a '*' to mark the point, where the number of 'space' is determined by the function. Then I'd want to scale this spacing against a number line. Not using a loop function, haven't yet gotten to that in class.
The Attempt at a Solution
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
cout << "\n";
cout << "A plot of sine function from 0 to 180 degrees with 15 degrees increment:\n";
cout << "\n";
char space [] = " ";
cout << space << "-1 0 1" << endl;
cout << space << "++++++++++++++++++++" << endl; //number line
const double PI = 3.14159;
int degree = 0;
double x = degree * ( PI / 180 );
cout << fixed << setprecision(2);
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
degree = degree + 15, x = degree * ( PI / 180 );
cout << space << "* sin(" << degree << ") = " << sin(x) << "\n";
cout << endl;
return 0;
}
Last edited: