Hi,

I am writing a C++ code that draws a sine curve. The code is fine, but when I run it (the compiled output) I get strange characters for both x- and y- axis. They look like a small oval with a question mark in it. I tried to run in it in a xfce4-terminal and this time, I could not see any of the axis, so I figured it has to do with playing with configuration of either console of Terminal (or gnome-terminal). Here is the code for testing:

/* ----------------------------------------------------- 
 *   sinCurve.cpp
 *   Outputs a sine curve
 * ----------------------------------------------------- 
*/

#include <iostream>
#include <cmath>                         // Prototypes of sin()
using namespace std;

#define CLS         (cout << "\033[2J") 
#define LOCATE(z,s) (cout <<"\033["<<(z)<<';'<<(s)<<'H')

#define PI        3.1415926536
#define START     0.0                    // Lower limit
#define END     (2.0 * PI)               // Upper limit

#define PNT       64                     // Number of points on the curve
#define STEP  ((END-START)/PNT)
#define xA        14                     // Row  of x-axis
#define yA        10                     // Column of y-axis


int main()
{
  int  row, column;

  CLS;
  LOCATE(2,25);
  cout << "-------  The Sine Function  -------";


  //    ---  Draws the coordinate system: ---  

  LOCATE(xA,1);                               // x-axis
  for( column = 1 ; column < 78  ; ++column)
    {
      cout << ((column - yA) % 8  ?  '\304' : '\305');
    }

  cout << '\020';                             // top
  LOCATE(xA-1, yA+64);  cout << "2PI  x";

  for( row = 5 ; row < 24 ; ++row)            // y-axis
    {
      LOCATE(row, yA);  cout << '\305';
    }

  LOCATE( 4, yA);  cout << "\036 sin(x)";     // top
  LOCATE( xA-8, yA+1);  cout << " 1";
  LOCATE( xA+8, yA+1);  cout << " -1";

  //     ---  Displays the sine function:  --- 

  int begpt = yA,
    endpt = begpt + PNT;

  for( column = begpt ;  column <= endpt  ;  ++column)
    {
      double x = (column-yA) * STEP;
      row = xA - 8 * sin(x) + 0.5;
      LOCATE( row, column);  cout << '.';
    }

  LOCATE(25,1);                 // Cursor to the last row 

  return 0;
}

Any clue?

I am using an Ubuntu 11.10 box updated to the latests of packages.

~faizlo

Recommended Answers

All 2 Replies

Member Avatar for ovidiu_b13

I don't know if this will help, try running it in netbeans.

Member Avatar for ovidiu_b13

Sorry, same result in Netbeans:

sin(x)
         �
         � 1          .......
         �         ...       ...
         �       ..             ..
         �      .                 .
         �    ..                   ..
         �   .                       .
         � ..                         ..
         �.                             .                                2PI  x
���������.�������������������������������.�������������������������������.���
         �                                .                             .
         �                                 ..                         ..
         �                                   .                       .
         �                                    ..                   ..
         �                                      .                 .
         �                                       ..             ..
         �                                         ...       ...
         � -1                                         .......
         �


RUN SUCCESSFUL (total time: 195ms)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.