Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***MICROSOFT VISUAL STUDIO*** C++ C++ PROGRAMMING FORMAT 1. Write a program that

ID: 3699803 • Letter: #

Question

***MICROSOFT VISUAL STUDIO*** C++
C++ PROGRAMMING FORMAT

1. Write a program that uses the sine function to graph a sine wave. The waveform should cover one full period. Write the output to the file graph.dat Let the horizontal and vertical axes represent x and y values respectively. Adjust the dimensions and the number of data points such that the graph fits on the printable surface of a single regular sheet of paper. The program will be graded based on a- functionality b-form and appeal of the output 50% 50% EW 303, Software Engineering Spring 2018 S18 RNEW303APR02 Page 1 of 1

Explanation / Answer


#include <iostream>
#include<math.h>
using namespace std;

int main()

{

/* Declare variables */

int no_of_lines, /* The number of lines to display in the graph */

line_count; /* Counts the number of lines in the graph */

double sine_count, /* Counts the sine values on the y-axis */

initial_step_size, /* The initial step size in degrees on the x-axis */

current_step_value, /* The current step value in degrees on the x-axis */

sine_step = 0.05, /* The step value on the y-axis */

radian_result; /* The resulting radian value on the x-axis */


cout << "Enter the initial step size in degrees " << " :" ;
cin >> initial_step_size;
cout <<endl;

cout << "Enter the number of lines to be displayed in the graph " << ":" ;

cin >> no_of_lines;

/* Conver to radians and assign to current step value */

current_step_value = initial_step_size * 3.14 / 180;

/* Print graph */

for (line_count = 0; line_count < no_of_lines; line_count++)

{

/* Convert to sin value of radians */

radian_result = sin(current_step_value);

  

/* To ensure that wave fits in window, we count the y-axis by a certain number of steps */

for (sine_count = -1; sine_count <= 1; sine_count += sine_step)

{

/* Check if radian x value is within y sine range */

if (radian_result >= sine_count && radian_result < (sine_count + sine_step))

{

cout << endl;

break;

}

else

cout << " ";

}

/* Increment steps on the x-axis */

current_step_value += initial_step_size * 3.14 / 180;

}

return 0;  

}