Hi All,
Can someone look at this code and tell me how I may use the Array (CPoint point) to draw the lines based on user input in text box. The program works fine without the array right now. I want to try to use an Array instead. I'm trying to learn other ways of displaying graph lines. This code was generated using AppWizard in VC 60++.
Thanks

void CProject5View::OnDraw(CDC* pDC) 
{
	double PI = 3.1415926535;
	int x, y = 0;

	int i = 0;
	
	double dStep = (PI * 2) / m_iSamples;
	double dResult = i * dStep;

    pDC->MoveTo(60, 200);
	pDC->LineTo(60, 400);
	pDC->LineTo(550, 400);
	pDC->MoveTo(60, 400);
	pDC->LineTo(60, 600);

	
//**************** ARRAY CPOINT ***********************
	CPoint point[8]; {
		point[0] = (PI/4 * x, 0.707 * y);
		point[1] = (PI/2 * x, 1 * y);
		point[2] = ((3*PI)/4 * x, 0.707 * y);
		point[3] = (PI * x, 0 * y);
		point[4] = ((5*PI)/4 * x, -0.707 * y);
		point[5] = ((3*PI)/2 * x, -1 * y);
		point[6] = ((7*PI)/4 * x, -0.707 * y);
		point[7] = (2*PI * x, 0 * y);
	}
	int	PtX = 60;
	int PtY = 400;
	int xLine = 500 / m_iSamples;	
	
	switch (m_Graph) {
		
		case Sin:
			
			pDC->MoveTo(PtX,PtY);
				for(i=0; i<=m_iSamples; i++) {
			dResult = i*dStep;
			dResult = sin(dResult);		
			dResult = 200 * dResult;
			
			y = (int)dResult;
			y = PtY - y;
			x = PtX + i * xLine;
			pDC->LineTo(x,y);
				
		}

		break;

		case Cos:
			pDC->MoveTo(PtX, PtY - 200);
				for(i=0; i<=m_iSamples; i++) {
			dResult = i*dStep;
			dResult = cos(dResult);
			dResult = 200 * dResult;

			y = (int)dResult;
			y = PtY - y;
			x = PtX + i * xLine;
			pDC->LineTo(x,y);
		
		}
		break;

	}

Code tags added. -Narue

Use a vector of type CPoint instead of a CPoint array.

#include <vector> 
/* Only uncomment if its not already there */
//using namespace std;
....
void CProject5View::OnDraw(CDC* pDC) 
{
...
vector <CPoint> point;
point.push_back(PI/4 * x, 0.707 * y); 
point.push_back(PI/4 * x, 0.707 * y);
point.push_back(PI/2 * x, 1 * y);
point.push_back((3*PI)/4 * x, 0.707 * y);
point.push_back(PI * x, 0 * y);
point.push_back((5*PI)/4 * x, -0.707 * y);
point.push_back((3*PI)/2 * x, -1 * y));
point.push_back((7*PI)/4 * x, -0.707 * y);
point.push_back(2*PI * x, 0 * y);
...
}

Access the vector the same way you would the array.

I'm sorry, that's where i'm lost. I can't remember how to do that. I am about as lost as can be right now. Is it possible for your assistance with it :idea: ?

Use a vector of type CPoint instead of a CPoint array.

#include <vector> 
/* Only uncomment if its not already there */
//using namespace std;
....
void CProject5View::OnDraw(CDC* pDC) 
{
...
vector <CPoint> point;
point.push_back(PI/4 * x, 0.707 * y); 
point.push_back(PI/4 * x, 0.707 * y);
point.push_back(PI/2 * x, 1 * y);
point.push_back((3*PI)/4 * x, 0.707 * y);
point.push_back(PI * x, 0 * y);
point.push_back((5*PI)/4 * x, -0.707 * y);
point.push_back((3*PI)/2 * x, -1 * y));
point.push_back((7*PI)/4 * x, -0.707 * y);
point.push_back(2*PI * x, 0 * y);
...
}

Access the vector the same way you would the array.

This article has been dead for over six months. Start a new discussion instead.