C++编程作业.docx
- 文档编号:16873135
- 上传时间:2023-07-19
- 格式:DOCX
- 页数:19
- 大小:122.93KB
C++编程作业.docx
《C++编程作业.docx》由会员分享,可在线阅读,更多相关《C++编程作业.docx(19页珍藏版)》请在冰点文库上搜索。
C++编程作业
16---1
voidCMy161View:
:
OnDraw(CDC*pDC)
{
CMy161Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahere
CRectrc;GetClientRect(rc);
pDC->SetMapMode(7);
pDC->SetWindowOrg(0,0);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SetWindowExt(200,400);
pDC->SetViewportExt(200,-200);
inti;
intpp[9][2]={-160,0,-160,40,-80,0,-80,80,0,0,80,80,80,0,160,40,160,0};
pDC->MoveTo(pp[0][0],pp[0][1]);
for(i=0;i<=8;i++)
pDC->LineTo(pp[i][0],pp[i][1]);
pDC->MoveTo(-240,0);
pDC->LineTo(0,120);
pDC->LineTo(240,0);
pDC->LineTo(-240,0);
pDC->MoveTo(0,120);
pDC->LineTo(0,0);
}
运行结果
16---3
#include"math.h
voidCMy16_3View:
:
OnDraw(CDC*pDC)
{
CMy16_3Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahere
CRectcr;GetClientRect(&cr);
pDC->SetMapMode(7);
pDC->SetWindowExt(400,400);
pDC->SetViewportExt(400,-400);
pDC->SetViewportOrg(cr.right/2,cr.bottom/2);
POINTpp[11];
inti;
for(i=0;i<11;i+=2)
{
pp[i].x=100*sin(36*3.1415926*i/180);
pp[i].y=100*cos(36*3.1415926*i/180);
}
for(i=1;i<10;i+=2)
{
pp[i].x=38.2*sin(36*3.1415926*i/180);
pp[i].y=38.2*cos(36*3.1415926*i/180);
}
pDC->Polyline(pp,11);
for(i=0;i<5;i++)
{
pDC->MoveTo(pp[i]);
pDC->LineTo(pp[5+i]);
}
}
运行结果
16---5
#include"stdafx.h"
#include"8.h"
#include"math.h"
#include"8Doc.h"
#include"8View.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
voidCMy8View:
:
OnDraw(CDC*pDC)
{
CMy8Doc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahere
CPen*p01,*p02;
CRectrc;GetClientRect(&rc);
pDC->SetMapMode(7);
pDC->SetWindowOrg(0,0);pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SetWindowExt(100,100);pDC->SetViewportExt(100,-100);
intpp[10][2]={0,125,-280,125,-280,-100,280,-100,280,125,0,125,
-60,-100,-60,0,60,-100,60,0};
pp[0][0]=-(int)(sqrt(150*150-125*125));
pp[5][0]=-pp[0][0];
pp[7][1]=-(int)(sqrt(100*100-60*60));
pp[9][1]=pp[7][1];
p01=newCPen(0,4,RGB(0,0,0));
p02=pDC->SelectObject(p01);
pDC->MoveTo(pp[0][0],pp[0][1]);
for(inti=1;i<=5;i++)pDC->LineTo(pp[i][0],pp[i][1]);
pDC->MoveTo(pp[6][0],pp[6][1]);pDC->LineTo(pp[7][0],pp[7][1]);
pDC->MoveTo(pp[8][0],pp[8][1]);pDC->LineTo(pp[9][0],pp[9][1]);
pDC->Arc(-100,-100,100,100,pp[9][0],pp[9][1],pp[7][0],pp[7][1]);
pDC->Arc(-150,-150,150,150,pp[5][0],pp[5][1],pp[0][0],pp[0][1]);
pDC->SelectObject(p02);
deletep01;
p01=newCPen(3,0,RGB(255,0,0));
p02=pDC->SelectObject(p01);
pDC->MoveTo(-120,0);pDC->LineTo(120,0);
pDC->MoveTo(0,-120);pDC->LineTo(0,170);
pDC->SelectObject(p02);
deletep01;
}
运行结果
16---6
#include"stdafx.h"
#include"16_6.h"
#include"math.h"
#include"16_6Doc.h"
#include"16_6View.h"
#definexf(theta)a*cos(theta)+xc
#defineyf(theta)b*sin(theta)+yc
#definexp(phi)70*cos(phi)+xc
#defineyp(phi)70*sin(phi)+yc
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
voidCXbView:
:
OnDraw(CDC*pDC)
{
CXbDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahereinta,b;
doublephi,theta,xc,yc;
inta,b;
a=140;b=50;
xc=0;yc=0;
elli(xc,yc,a,b,theta,phi);
}
CXbView:
:
elli(intxc,intyc,inta,intb,doubletheta,doublephi)
{
CClientDCdc(this);
CRectr;GetClientRect(r);
dc.SetMapMode(7);
dc.SetWindowOrg(0,0);
dc.SetViewportOrg(r.right/2,r.bottom/2);
dc.SetWindowExt(100,100);
dc.SetViewportExt(100,-100);
for(theta=0;theta<=2*3.1415926;theta+=0.001)
{
doublexf,yf,phi;intr;
r=70;
xf=a*cos(theta);yf=b*sin(theta);
if(theta==0)
dc.MoveTo(xf(theta),yf(theta));
else
if(yf>0&&sqrt(xf*xf+yf*yf) dc.SelectStockObject(NULL_PEN); else dc.SelectStockObject(BLACK_PEN); dc.LineTo(xf(theta),yf(theta));} for(phi=0;phi<=3.1415926;phi+=0.001) { if(phi==0) dc.MoveTo(xp(phi),yp(phi)); else dc.LineTo(xp(phi),yp(phi));} } 运行结果: 16——7 #include"stdafx.h" #include"16_7" #include"math.h" #include"16_7Doc.h" #include"16_7View.h" #ifdef_DEBUG #definenewDEBUG_NEW #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #endif voidCMy0View: : OnDraw(CDC*pDC) { CMy0Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere CRectrc;GetClientRect(&rc); pDC->SetMapMode(7); pDC->SetWindowOrg(0,0); pDC->SetViewportOrg(rc.right/2,rc.bottom/2); pDC->SetWindowExt(200,-200); pDC->SetViewportExt(300,300); CPointp1(-90,90),p2(90,-90); inti; doublex1,y1,x2,y2,x3,y3,x4,y4; for(i=0;i<=3;i++) { x1=-90*cos(i*3.1415926/6); y1=90; x2=90*cos(i*3.14159926/6); y2=-90; pDC->Arc(x1,y1,x2,y2,x2,0,x2,0); } for(i=0;i<=4;i++) { x3=sqrt(90*90-30*(i-2)*30*(i-2)); y3=30*(i-2); x4=-sqrt(90*90-30*(i-2)*30*(i-2)); y4=30*(i-2); pDC->MoveTo(x3,y3); pDC->LineTo(x4,y4); } pDC->MoveTo(0,90); pDC->LineTo(0,-90); } 运行结果 16-7 程序: voidCReView: : OnDraw(CDC*pDC) { CReDoc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere CRectrc;GetClientRect(&rc); pDC->SetMapMode(7); pDC->SetWindowOrg(0,0); pDC->SetViewportOrg(rc.right/2,rc.bottom/2); pDC->SetWindowExt(100,-100); pDC->SetViewportExt(150,150); CPointp1(-90,90),p2(90,-90); inti; doublex1,y1,x2,y2,x3,y3,x4,y4; pDC->Arc(-90,90,90,-90,90,0,90,0); for(i=1;i<=2;i++){ x1=-90*cos(i*3.1415926/6); y1=90; x2=90*cos(i*3.14159926/6); y2=-90; pDC->Arc(x1,y1,x2,y2,x2,0,x2,0);} for(i=0;i<=4;i++){ x3=sqrt(90*90-30*(i-2)*30*(i-2)); y3=30*(i-2); x4=-sqrt(90*90-30*(i-2)*30*(i-2)); y4=30*(i-2); pDC->MoveTo(x3,y3); pDC->LineTo(x4,y4);} 运行结果: 16——8 #include"stdafx.h" #include"16_8h" #include"math.h" #defineR(theta)cos(1.5*theta)*120 #include"16_8Doc.h" #include"16_8View.h" #ifdef_DEBUG #definenewDEBUG_NEW #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #endif voidCReView: : OnDraw(CDC*pDC) { CReDoc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere CRectrc;GetClientRect(&rc); pDC->SetMapMode(7); pDC->SetWindowOrg(0,0); pDC->SetViewportOrg(rc.right/2,rc.bottom/2); pDC->SetWindowExt(100,-100); pDC->SetViewportExt(100,100); doubletheta,r; intx,y; for(theta=0;theta<=20*3.1415926;theta+=0.01){ r=R(theta); x=(int)(r*cos(theta)); y=(int)(r*sin(theta)); if(theta==0) pDC->MoveTo(x,y); else pDC->LineTo(x,y);} } 运行结果: 16---9 #include"stdafx.h" #include"16_9.h" #include"math.h" #include"16_9Doc.h" #include"16_9View.h" #ifdef_DEBUG #definenewDEBUG_NEW #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #endif voidCMy16_9View: : OnDraw(CDC*pDC) { CMy16_9Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere CRectrc;GetClientRect(&rc); pDC->SetMapMode(7); pDC->SetWindowOrg(0,0); pDC->SetViewportOrg(rc.right/2,rc.bottom/2); pDC->SetWindowExt(100,-100); pDC->SetViewportExt(150,150); doublex1,y1,x2,y2,x3,y3,x4,y4; inti; pDC->Arc(-80,80,80,-80,80,0,80,0); pDC->Arc(-75,75,75,-75,75,0,75,0); for(i=0;i<=14;i++) { x1=sqrt(75*75-10*(i-7)*10*(i-7)); y1=10*(i-7); x2=-sqrt(75*75-10*(i-7)*10*(i-7)); y2=10*(i-7); x3=x1*cos(3.1415926/4)-y1*sin(3.1415926/4); y3=x1*sin(3.1415926/4)+y1*cos(3.1415926/4); x4=x2*cos(3.1415926/4)-y2*sin(3.1415926/4); y4=x2*sin(3.1415926/4)+y2*cos(3.1415926/4); pDC->MoveTo(x3,y3); pDC->LineTo(x4,y4); } } 运行结果 16——10 voidCMy1View: : OnDraw(CDC*pDC) { CMy1Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere CRectrc;GetClientRect(&rc); pDC->SetMapMode(7); pDC->SetWindowOrg(0,0); pDC->SetViewportOrg(rc.right/2,rc.bottom*2/3); pDC->SetWindowExt(100,-100); pDC->SetViewportExt(150,150); inti; for(i=1;i<=2;i++) { pDC->MoveTo(-100,-20+65*(i-1)); pDC->LineTo(100,-20+65*(i-1)+200*0.4); } for(i=-5;i<=5;i+=2) { pDC->MoveTo(20*i,20*i*0.4); pDC->LineTo(20*i,85+20*i*0.4); } for(i=-4;i<=5;i+=2) { pDC->MoveTo(20*i,20+20*i*0.4); pDC->LineTo(20*i,85+20*i*0.4); } } 16——11 #include"stdafx.h" #include"16_11.h" #include"math.h" #include"16_11Doc.h" #include"16_11View.h" #definexf(theta)a*cos(theta)*cos(phi)-b*sin(theta)*sin(phi)+xc #defineyf(theta)a*cos(theta)*sin(phi)+b*sin(theta)*cos(phi)+yc #ifdef_DEBUG #definenewDEBUG_NEW #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #endif voidCMy16_11View: : OnDraw(CDC*pDC) { CMy16_11Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere inta,b; doublephi,theta,xc,yc; a=100;b=40; xc=300;yc=0; elli(xc,yc,a,b,theta); } CTruView: : elli(intxc,intyc,inta,intb,doubletheta) { CClientDCdc(this); CRectr;GetClientRect(r); dc.SetMapMode(7); dc.SetWindowOrg(0,0); dc.SetViewportOrg(r.left/2,r.bottom/2); dc.SetWindowExt(100,100); dc.SetViewportExt(100,-100); doublephi; for(phi=0;phi<=2*3.1415926;phi+=3.1415926/8) for(theta=0;theta<=2*3.1415926;theta+=0.001) { if(theta==0) dc.MoveTo(xf(theta),yf(theta)); else dc.LineTo(xf(theta),yf(theta)); }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 编程 作业