E.2 Printing a Full-wave Rectified Sine Curve Requirements: Your program will pr
ID: 3723207 • Letter: E
Question
E.2 Printing a Full-wave Rectified Sine Curve Requirements: Your program will print a vertical, full-wave rectified sine curve on the console using"*" characters. You must not include the library. Specifications: The program will ask the user to enter a real number value indicating how many sine wave cycles they wish to print to the screen. The reason for allowing a decimal number to be entered is so that a partial cycle can be printed. Remember that a single cycle of a sine wave can be shown as: 1. And a single cycle of a full-wave rectified sine wave can be shown as: For simplicity, we are going to print this wave vertically on the console. to the console to represent the rectified sine wave as shown in the sample output section below. For more details on printing characters to the console with for loops, see lecture 2. Use a for loop, or set of nested for loops to print an appropriate number ofcharacters unit 4, slides 99-100.Explanation / Answer
Hello There,
PFB code for requested functionality along with the output of test run:
printSine.cpp
--------------------------------------
#include <iostream>
using namespace std;
// calculating sin(x)
double getSine(double x){
double sineValue = x - (x*x*x/6) + (x*x*x*x*x/120) - (x*x*x*x*x*x*x/5040);
if(sineValue < 0){
sineValue *= 1;
}
return sineValue;
}
int main(){
double n;
cout << "How many rectified sine curves should be printed? ";
cin >> n;
int totalDegrees = n*360.0;
for(int k=0; k<=totalDegrees; k += 5){
int degree = k;
while(degree > 180){ // making sure degree value lies with in 180 degrees (first two quardants where sine is positive)
degree -= 180;
}
double radian = degree*(22/7.0)*(1/180.0); // radian from degree
double sinX = getSine(radian);
for(int j=0; j<sinX*20; j++){ // printing *s
cout << "*";
}
cout << endl;
}
return 0;
}
--------------------------------------------------------
TestRun:
----------------------------------------------------------
$ g++ printSine.cpp
$ ./a.out
How many rectified sine curves should be printed? 0.25
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
$ ./a.out
How many rectified sine curves should be printed? 0.75
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
$ ./a.out
How many rectified sine curves should be printed? 3.5
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
**
****
******
*******
*********
***********
************
*************
***************
****************
*****************
******************
*******************
*******************
********************
********************
********************
********************
********************
********************
********************
*******************
*******************
******************
*****************
****************
***************
*************
************
**********
*********
*******
*****
***
*
$
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.