Sawtooth help!!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main(void)
{
    double angle=30.0;
    double angle_radians = angle * 2.0 * PI / 360.0;    // 2 PI radians in a full circle
    double my_cosine = cos(angle_radians);              // trig functions work in radians, not degrees
    double my_sine   = sin(angle_radians);

    cout << angle << "degrees equals "<< angle_radians << "radians"<<endl;
    cout << "cosine of " << angle_radians << " is " << my_cosine << endl;
    cout << "sine   of " << angle_radians << " is " << my_sine << endl;

            // now print out 24 sines and cosines (actually, 25 of 'em)

    cout << "i" << "\t" << "theta" << "\t" << "cosine" << "\t" << "sine" << endl;
    cout << setprecision(4);        // output with four decimal places.
    for (int i=0;i<=24; i++)
    {
        double theta;
        theta = 2.0*PI/24.0 * i;     // got partway around the circle each time through the loop

        cout << i << "\t" << theta << "\t" << cos(theta) << "\t" << sin(theta) << endl;
    }

    return 0;


The last sample program (above) generates a sine and a cosine waveform (angle, or perhaps time, in column 2, cosine in column 3 and sine in column 4. Write a program to generate 400 (x,y) points of a sawtooth waveform that repeats every 100 points, with a minimum of 0 and a maximum of 5 (as if it were the output of a 0-5v sawtooth wave from awaveform generator). Let x range from 0 to 1.0, and y range from 0 to 5.0. Hint: the modulus (%) operator comes in handy here…think about what i % 100 gives you (assuming you’re using i as a loop counter, from 0-399).
Your previous thread on the same homework: http://www.cplusplus.com/forum/beginner/111163/
Topic archived. No new replies allowed.