C/C++ 绘制初等函数曲线图形

初等函数曲线图形的简易绘制:设屏幕显示文本是25行,80列,可以用“+”和“——〉”号画坐标系,用“*”号画曲线上的点,给出初等函数,例如cos(x),ex, x3-3x+1,等等,还要给出x的一个估计的范围,程序就画出这个初等函数的简易图形。
这个就是原题了 一个字没少 其实要求也不是很高
平台最好是VC++6.0 语言用C或者C++

可以 CDC * pDC = pWnd->GetDC();
然后直接调用 CDC的成员函数实现曲线的绘制,具体看看msdn,上面有详细的说明,对于你所说的函数曲线直线片段来实现,使用for循环,递增t的值得到y的值。
打开位图BMP,使用 LoadImage 函数,MSDN上有说明,指定相应的参数即可,注意指定 LR_LOADFROMFILE 参数,返回值是图形的句柄,然后通过CDC的函数BitBlt来在设备描述符上绘制图象,
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);

// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);

// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);

dcMemory.SelectObject(pOldBitmap);
}
}
这段MSDN上的代码你参考一下
另外,虚机团上产品团购,超级便宜
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-19
这个不好做,画这些的数据类型最少都要float的数据,给你的条件精度不够,画不出来追问

不是要求精确的 不然也不能用*了。。。
简易绘制~

追答

#include "math.h"
#define row 50
#define col 162
class CTGDraw
{
public:
enum ct
{
ct_bk = int(char(' ')),
ct_org = int(char('+')),
ct_x = int(char('-')),
ct_y = int(char('|')),
ct_1 = int(char('*'))
};
CTGDraw();
virtual ~CTGDraw();

BOOL SaveToFile(LPCTSTR lpzPath);
BOOL DrawCosLine();
void ClearBk();

private:
char** m_pData;
};
CTGDraw::CTGDraw()
{
m_pData = new char*[row];
int len = sizeof(char) * col;
int i;
for (i = 0; i ';
for (i = 1; i < len; ++i)
{
m_pData[w][i] = ct_x;
}
}

BOOL CTGDraw::SaveToFile(LPCTSTR lpzPath)
{
CFile file;
if(!file.Open(lpzPath,CFile::modeCreate|CFile::modeReadWrite))
return FALSE;

for (int i = 0; i < row; ++i)
{
file.Write(m_pData[i],col);
}
file.Close();
return TRUE;
}

BOOL CTGDraw::DrawCosLine()
{
int orgx = (col -2)/2;
int orgy = row/2;
double s = 0.05;
int i = 0;
double v;
int x,y;
for (;i < col-2; ++i)
{
x = i - orgx;
v = cos(x*s);
y = (int)((v/s)+0.5);
y = abs(y- orgy);
m_pData[y][i] = ct_1;
}
return TRUE;
}
///////////////////////////////////////
//只做了画Cos的方法
//调用。
CTGDraw tgd;
tgd.ClearBk();
tgd.DrawCosLine();
tgd.SaveToFile("C:\\Documents and Settings\\Administrator.PC-20101126LEDB\\桌面\\aass.txt");

追问

那个这个直接放在VC6。0就可以么。。
还有我看不太明白。。。我只学了1年C语言的说。。。。 求稍微带点注释呗
感谢感谢~