C + +

Thread Starter

isha

Joined Sep 16, 2005
36

how can we draw sine wave in C++
1. without using graphics
and
2. with graphics
(i need source code )
 

BladeSabre

Joined Aug 11, 2005
105
1. What do you mean by "draw a sine wave ... without using graphics"?

2. C++ does not have its own graphics, and the code varies wildly depending on whether you're using the operating system's routines or some cross-platform library. Have you used any kind of graphics before? What did you use?
 

Papabravo

Joined Feb 24, 2006
14,702
Originally posted by BladeSabre@Jun 1 2006, 12:59 PM
1. What do you mean by "draw a sine wave ... without using graphics"?

2. C++ does not have its own graphics, and the code varies wildly depending on whether you're using the operating system's routines or some cross-platform library. Have you used any kind of graphics before? What did you use?
[post=17442]Quoted post[/post]​
We used to use FORTRAN programs on mainframe comnputers to plot graphs on line printers. Some SPICE programs still do this. It is just a matter of constructing the strings with blanks and asterisks and writing them to an output stream.
 

Thread Starter

isha

Joined Sep 16, 2005
36
Originally posted by BladeSabre@Jun 1 2006, 11:59 AM
1. What do you mean by "draw a sine wave ... without using graphics"?

2. C++ does not have its own graphics, and the code varies wildly depending on whether you're using the operating system's routines or some cross-platform library. Have you used any kind of graphics before? What did you use?
[post=17442]Quoted post[/post]​


1. using graphics mean that
in program including the header file
" #include <graphics.h> "

2. with out graphics mean that
using loop to
display a character in sine wave form
 

BladeSabre

Joined Aug 11, 2005
105
OK, so the answer to my second question is that you're using "graphics.h" for your graphics. I know roughly what that is, though I can't help you with code for it.

"Using loop to display a character in sine wave form" does not make any more sense to me than before. Are you intending to draw using a grid of characters, like what Papabravo suggested?
 

Thread Starter

isha

Joined Sep 16, 2005
36
Originally posted by BladeSabre@Jun 2 2006, 10:54 AM
OK, so the answer to my second question is that you're using "graphics.h" for your graphics. I know roughly what that is, though I can't help you with code for it.

"Using loop to display a character in sine wave form" does not make any more sense to me than before. Are you intending to draw using a grid of characters, like what Papabravo suggested?
[post=17468]Quoted post[/post]​

diplay character in sine wave form
or grid of characters
 

BladeSabre

Joined Aug 11, 2005
105
First, a little friendly feedback:

1. Writing in large italic makes your posts hard to read. And it looks like you're shouting (or attention-seeking).

2. We need more details of the problem if we're going to help you. You can help us to help you by telling us those details without being asked. Having to drag them out of you 10 words at a time is tiring. Most people won't bother with it, and I'm not going to bother any more after this post.

3. Asking people to write code for you will not usually work - particularly if you can't explain what you want. This time is a rare exception. (I'm new still, and the problem looked like an interesting one for me to practise on.)



That said, I had a quick bash at it. I have no idea if this is anything like what you want, because you didn't explain it very well. So, I defined the problem the way I liked it. (And this is C, by the way. But I think it will still work in C++.)

Rich (BB code):
#include <math.h>
#include <stdio.h>
 
#define ROWS 22
#define COLS 72
#define ZERO_LINE_ROW 10
 
#define VALUE_PER_ROW 0.1
#define RADS_PER_COL 0.5
#define STARTING_RADS 2.0
 
void drawwave (char grid[][COLS+1]) {
  int row, col;
  double x, y;
  for (row = 0; row < ROWS; row++) {
   for (col = 0; col < COLS; col++) {
     grid[row][col] = ' ';
   }
   grid[row][COLS] = '\0';
  }
 
  for (col = 0; col < COLS; col++) {
   x = STARTING_RADS + (RADS_PER_COL * col);
   y = sin(x);
   row = ZERO_LINE_ROW - (int) (y / VALUE_PER_ROW);
   if (row >= 0 && row < ROWS) {
     grid[row][col] = '*';
   }
  }
}
 
int main (int argc, char*argv[]) {
  char grid[ROWS][COLS+1];
  int row;
  drawwave(grid);
  for (row = 0; row < ROWS; row++) {
   puts (grid[row]);
  }
  getchar();
  return 0;
}
 
Top