[ create a new paste ] login | about

Link: http://codepad.org/GnbcKHiD    [ raw code | output | fork ]

C++, pasted on Mar 15:
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
   int amplitude = 1;
   int frequency = 1;
   int phase = 0;
   int start_time = 0;
   int end_time = 1;
   double f, t;

   printf("input the amplitude = %d\n", amplitude);
   printf("input the frequency= %d\n", frequency);
   printf("input the phase in radian= %d\n", phase);
   printf("input the start time= %d\n", start_time);
   printf("input the end time= %d\n", end_time);

//   printf("==============================================================\n");
   cout<<setfill('=');
   cout<<setw(70)<<endl;
   printf(" x   sin(x) value                 sin(x) graph \n");
   printf("==============================================================\n");
   printf("                    -1-------------------0-------------------1\n");
      cout.precision(2);
      cout.setf(ios::fixed);
      cout.setf(ios::right);
      //cout.setf(ios::showpos);
   for(t = start_time; t <= end_time; t+=0.05)
   {
      f = amplitude*sin(2*M_PI*frequency*t+phase);
//      printf("%.2f  %+.2f %*c\n", t, f,30-(int)(f*20),'*');
      cout<<t<<setw(8)<<f<<setw(30-(int)(f*20))<<"*"<<endl;

   }
   printf("==============================================================\n");

   return 0;
}


Output:
input the amplitude = 1
input the frequency= 1
input the phase in radian= 0
input the start time= 0
input the end time= 1

 x   sin(x) value                 sin(x) graph 
==============================================================
                    -1-------------------0-------------------1
==================================================================0.00====0.00=============================*
0.05====0.31=======================*
0.10====0.59==================*
0.15====0.81=============*
0.20====0.95==========*
0.25====1.00=========*
0.30====0.95==========*
0.35====0.81=============*
0.40====0.59==================*
0.45====0.31=======================*
0.50====0.00=============================*
0.55===-0.31===================================*
0.60===-0.59========================================*
0.65===-0.81=============================================*
0.70===-0.95================================================*
0.75===-1.00=================================================*
0.80===-0.95================================================*
0.85===-0.81=============================================*
0.90===-0.59========================================*
0.95===-0.31===================================*
==============================================================


Create a new paste based on this one


Comments: