c 设计技术文档_第1页
c 设计技术文档_第2页
c 设计技术文档_第3页
c 设计技术文档_第4页
c 设计技术文档_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

最好的沉淀整理实验一技术开发文档1.需求分析(1)显示输入的点的坐标。(2)已知直线上两点的坐标,求取直线的斜率、截距和直线方程。(3)已知圆心坐标,圆的半径或直径,求取圆的周长、面积和圆的方程。(4)已知矩形一点的坐标,一边与x轴夹角的弧度值及两边长度,求取矩形四个点坐标、圆心坐标、周长、面积和矩形方程。(5)已知抛物线上一点的坐标及抛物线的对称轴,求取准线方程、抛物线开口方向和抛物线方程。2.概念抽象(1)定义点类,在点类中定义xinput()、yinput()和point_output()三个函数。(2)定义线类,在线类中定义first_point_input()、second_point_input()、tile_rate(_x1,_y1,_x2,_y2)、intercept(_k,_x1,_y1)和line_output()五个函数。(3)定义圆类,在圆类中定义circle_center_input()、r_or_d_input()、circle_perimeter()、circle_area()和circle_output()五个函数。(4)定义矩形类,在矩形类中定义rectangle_input()、rectangle_points()、rectangle_perimeter_and_area()和rectangle_output()四个函数。(5)定义抛物线类,在抛物线类中定义parabolic_input()和parabolic_output()两个函数。注:函数定义及具体应用详见附件3.类的分析及说明附件:点、线、圆、矩形、抛物线的对象定义源代实验二技术开发文档1.需求分析(1)定义AD、DA板卡类,完成对板卡的封装;(2)实现单通道和多通道的单点采集、多点采集、大批量采集;(3)实现单通道和多通道的单点输出、多点输出;2.现实世界(1)AD采集PCI8932板卡AD采集过程为创建设备对象、判断创建设备对象是否成功、用户从键盘选择输入量程、设置硬件参数、初始化AD、判断AD初始化是否成功、数据采集、电压转换并显示。定义AD板卡类,在类中定义创建设备对象函数、选择输入量程函数、设置硬件参数函数和初始化AD函数,从而完成对板卡的封装。(2)DA输出PCI8932板卡DA输出的过程为创建设备对象、判断创建设备对象是否成功、用户从键盘上输入DA通道号、用户从键盘上输入电压值和输出恒定电压。定义DA板卡类,在类中定义创建设备对象函数,从而完成对板卡的封装。注:函数定义及具体应用详见附件3.类的分析及说明(1)AD采集类图(2)DA输出类图附件:AD采集源代码DA输出源代码附件点、线、圆、矩形、抛物线的对象定义源代码//该程序用于几何图形点、线、圆、矩形、抛物线的对象定义//线由点派生;圆由点派生;矩形由线派生;抛物线由点派生//可以获得几何图形的特征点、特征线等参数#include<iostream>#include<cmath>usingnamespacestd;constdoublePI=3.14159;//定义点类classPoint{public:doublexinput();//输入点的横坐标doubleyinput();//输入点的纵坐标voidpoint_output();//输出点的坐标private:doublex;doubley;};//定义线类classLine:publicPoint{public:voidfirst_point_input();//输入线上一点的坐标voidsecond_point_input();//输入线上另一点的坐标doubletile_rate(double_x1,double_y1,double_x2,double_y2);//计算直线的斜率doubleintercept(double_k,double_x1,double_y1);//计算直线的截距voidline_output();//回显输入两点的坐标,输出斜率、截距和直线方程private:doublex1;doubley1;doublex2;doubley2;doublek;doubleb;};//定义圆类classCircle:publicPoint{public:voidcircle_center_input();//输入圆心坐标voidr_or_d_input();//输入半径或直径doublecircle_perimeter();//计算圆的周长doublecircle_area();//计算圆的面积voidcircle_output();//回显输入的圆心坐标、半径或直径,输出圆的方程private:charans;doubleox;doubleoy;doubler;doubled;doublel;doubles;};//定义矩形类classRectangle:publicLine{public:voidrectangle_input();//输入矩形一点的坐标,一边与x轴夹角的弧度值及两边长度voidrectangle_points();//计算矩形四个点和圆心的坐标voidrectangle_perimeter_and_area();//计算矩形周长和面积voidrectangle_output();//回显输入,输出矩形四个点和圆心坐标、周长及面积private:doublex1,y1;doublex2,y2;doublex3,y3;doublex4,y4;doublex_O,y_O;doubleangle;doublelength_1;doublelength_2;doublel;doubles;};//定义抛物线类classParabolic:publicPoint{public:voidparabolic_input();//输入抛物线上一点的坐标voidparabolic_output();//选择抛物线的对称轴//计算并输出抛物线方程,准线方程及抛物线开口方向private:doublex;doubley;doublep;charans;};intmain(){charans;cout<<"Pleaseenteralettertochoosethegeometrygraph"<<""<<"thatyouwanttohandle.\n";cout<<"pforpointandlforline\n"<<"cforcircleandrforrectangle\n"<<"tforparabolic\n";cin>>ans;//选择要处理的几何图形if((ans=='p')||(ans=='P'))//处理点{Pointpoint;cout<<"Enterthecoordinatesofthepoint:\n";//输入点的坐标point.xinput();point.yinput();cout<<"thecoordinatesofthepointis"<<""<<endl;//输出点的坐标point.point_output();cout<<endl;}elseif((ans=='l')||(ans=='L'))//处理线{Lineline;cout<<"Enterthecoordinatesoftwopoints:\n";//输入线上两点的坐标cout<<"Enterthecoordinatesofthefirstpoint:\n";line.first_point_input();cout<<"Enterthecoordinatesofthesecondpoint:\n";line.second_point_input();line.line_output();cout<<endl;}elseif((ans=='c')||(ans=='C'))//处理圆{Circlecircle;cout<<"Enterthecoordinatesofcirclecenter:\n";//输入圆心坐标circle.circle_center_input();circle.r_or_d_input();circle.circle_perimeter();circle.circle_area();circle.circle_output();cout<<endl;}elseif((ans=='r')||(ans=='R'))//处理矩形{Rectanglerectangle;rectangle.rectangle_input();rectangle.rectangle_points();rectangle.rectangle_perimeter_and_area();rectangle.rectangle_output();cout<<endl;}else{Parabolicparabolic;//处理抛物线cout<<"Enterthecoordinatesofonepointontheparabolic:\n";parabolic.parabolic_input();parabolic.parabolic_output();}return0;}doublePoint::xinput(){cout<<"Pleaseinputthexaxiscoordinateofthepoint."<<endl;cin>>x;returnx;}doublePoint::yinput(){cout<<"Pleaseinputtheyaxiscoordinateofthepoint."<<endl;cin>>y;returny;}voidPoint::point_output(){cout<<"("<<x<<","<<y<<")"<<endl;}voidLine::first_point_input(){x1=xinput();y1=yinput();}voidLine::second_point_input(){x2=xinput();y2=yinput();}doubleLine::tile_rate(double_x1,double_y1,double_x2,double_y2){double_k;_k=(_y2-_y1)/(_x2-_x1);return_k;}doubleLine::intercept(double_k,double_x1,double_y1){double_b;_b=_y1-_k*_x1;return_b;}voidLine::line_output(){k=tile_rate(x1,y1,x2,y2);b=intercept(k,x1,y1);cout<<"Thecoordinatesofthetwopointsare:\n"<<"("<<x1<<","<<y1<<")"<<""<<"("<<x2<<","<<y2<<")"<<endl;cout<<"Thetilerateofthelineis"<<""<<k<<endl;cout<<"Theinterceptofthelineis"<<""<<b<<endl;cout<<"Theequationexpressionofthelineis"<<"";if((k==0)&&(b==0))cout<<"y=0"<<endl;elseif((k==0)&&(b!=0))cout<<"y="<<b<<endl;elseif((k!=0)&&(b==0))cout<<"y="<<k<<"x"<<endl;elsecout<<"y="<<k<<"x"<<"+"<<b<<endl;}voidCircle::circle_center_input(){ox=xinput();oy=yinput();}voidCircle::r_or_d_input(){cout<<"Pleaseenteraletter:rforradiusanddfordiameter\n";cin>>ans;if(ans=='r'){cout<<"Entertheradiusofthecircle:\n";cin>>r;}else{cout<<"Enterthediameterofthecircle:\n";cin>>d;}}doubleCircle::circle_perimeter(){if((ans=='r')||(ans=='R'))l=2*PI*r;elsel=PI*d;returnl;}doubleCircle::circle_area(){if((ans=='r')||(ans=='R'))s=PI*pow(r,2);elses=PI*pow(d/2.0,2);returns;}voidCircle::circle_output(){cout<<"Thecoordinatesofcirclecenteris"<<""<<"("<<ox<<","<<oy<<")"<<endl;if((ans=='r')||(ans=='R')){cout<<"Theradiusofcircleis"<<""<<r<<endl;if((ox==0)&&(oy==0)){cout<<"Theequationexpressionofcircleis"<<""<<"x"<<"*"<<"x"<<"+"<<"y"<<"*"<<"y"<<"="<<r*r<<endl;}elseif((ox==0)&&(oy!=0)){cout<<"Theequationexpressionofcircleis"<<""<<"x"<<"*"<<"x"<<"+"<<"("<<"y"<<"-"<<oy<<")"<<"*"<<"("<<"y"<<"-"<<oy<<")"<<"="<<r*r<<endl;}elseif((ox!=0)&&(oy==0)){cout<<"Theequationexpressionofcircleis"<<""<<"("<<"x"<<"-"<<ox<<")"<<"*"<<"("<<"x"<<"-"<<ox<<")"<<"+"<<"y"<<"*"<<"y"<<"="<<r*r<<endl;}elseif((ox!=0)&&(oy!=0)){cout<<"Theequationexpressionofcircleis"<<""<<"("<<"x"<<"-"<<ox<<")"<<"*"<<"("<<"x"<<"-"<<ox<<")"<<"+"<<"("<<"y"<<"-"<<oy<<")"<<"*"<<"("<<"y"<<"-"<<oy<<")"<<"="<<r*r<<endl;}elsecout<<"Itisimpossible.\n";}else{cout<<"Thediameterofcircleis"<<""<<d<<endl;if((ox==0)&&(oy==0)){cout<<"Theequationexpressionofcircleis"<<""<<"x"<<"*"<<"x"<<"+"<<"y"<<"*"<<"y"<<"="<<(d/2.0)*(d/2.0)<<endl;}elseif((ox==0)&&(oy!=0)){cout<<"Theequationexpressionofcircleis"<<""<<"x"<<"*"<<"x"<<"+"<<"("<<"y"<<"-"<<oy<<")"<<"*"<<"("<<"y"<<"-"<<oy<<")"<<"="<<(d/2.0)*(d/2.0)<<endl;}elseif((ox!=0)&&(oy==0)){cout<<"Theequationexpressionofcircleis"<<""<<"("<<"x"<<"-"<<ox<<")"<<"*"<<"("<<"x"<<"-"<<ox<<")"<<"+"<<"y"<<"*"<<"y"<<"="<<(d/2.0)*(d/2.0)<<endl;}elseif((ox!=0)&&(oy!=0)){cout<<"Theequationexpressionofcircleis"<<""<<"("<<"x"<<"-"<<ox<<")"<<"*"<<"("<<"x"<<"-"<<ox<<")"<<"+"<<"("<<"y"<<"-"<<oy<<")"<<"*"<<"("<<"y"<<"-"<<oy<<")"<<"="<<(d/2.0)*(d/2.0)<<endl;}elsecout<<"Itisimpossible.\n";}cout<<"Theperimeterofcircleis"<<""<<l<<endl;cout<<"Theareaofcircleis"<<""<<s<<endl;}voidRectangle::rectangle_input(){cout<<"Pleaseinputthecoordinatesofonepoint:\n";cin>>x1>>y1;cout<<"Pleaseinputtheangle(rad):\n";cin>>angle;cout<<"Pleaseinputthelengthoftwosides:\n";cin>>length_1>>length_2;}voidRectangle::rectangle_points(){x2=x1+length_1*cos(angle);y2=y1+length_1*sin(angle);x3=x1-length_2*sin(angle)+length_1*cos(angle);y3=y1+length_2*cos(angle)+length_1*sin(angle);x4=x1-length_2*sin(angle);y4=y1+length_2*cos(angle);x_O=(x1+x3)/2.0;y_O=(y1+y3)/2.0;}voidRectangle::rectangle_perimeter_and_area(){l=2*(length_1+length_2);s=length_1*length_2;}voidRectangle::rectangle_output(){cout<<"thecoordinatesoftheinputpointis"<<""<<"("<<x1<<","<<y1<<")"<<endl;cout<<"theinputangleis"<<""<<angle<<endl;cout<<"theinputlengthoftwosidesare"<<""<<length_1<<","<<length_2<<endl;cout<<"thefourpointsoftherectangleare:\n"<<"("<<x1<<","<<y1<<")"<<""<<"("<<x2<<","<<y2<<")"<<""<<"("<<x3<<","<<y3<<")"<<""<<"("<<x4<<","<<y4<<")"<<endl;cout<<"thecoordinatesofthecenterpointis:\n"<<"("<<x_O<<","<<y_O<<")"<<endl;cout<<"theperimeteroftherectangleis"<<""<<l<<endl;cout<<"theareaoftherectangleis"<<""<<s<<endl;}voidParabolic::parabolic_input(){x=xinput();y=yinput();}voidParabolic::parabolic_output(){cout<<"Pleaseinputalettertochoosetheaxisthatparabolicsymmetryaboutit.\n"<<"xstandsforxaxisandystandsforyaxis"<<endl;cin>>ans;if((ans=='x')||(ans=='X')){p=(y*y)/(2*x);cout<<"Theequationexpressionofparabolicis"<<""<<"y*y="<<(2*p)<<"x"<<endl;cout<<"Theaccuratelineofparabolicis"<<""<<"x="<<(-p)/2.0<<endl;if(p>0)cout<<"Theopendirectionofparabolicisright.\n";elsecout<<"Theopendirectionofparabolicisleft.\n";}elseif((ans=='y')||(ans=='Y')){p=(x*x)/(2*y);cout<<"Theequationexpressionofparabolicis"<<""<<"x*x="<<(2*p)<<"y"<<endl;cout<<"Theaccuratelineofparabolicis"<<""<<"y="<<(-p)/2.0<<endl;if(p>0)cout<<"Theopendirectionofparabolicisright.\n";elsecout<<"Theopendirectionofparabolicisleft.\n";}elsecout<<"Theinputofletteriswrong.\n";}附件AD采集源代码//说明:本程序演示了如何用程序查询方式读取AD数据#include"stdafx.h"#include"windows.h"#include"stdio.h"#include"conio.h"#include"PCI8932.h"//驱动程序接口头文件,它位于该演示程序目录下HANDLEhDevice;DWORDdwErrorCode;charstrErrorMsg[256];intInputRange;LONGnReadSizeWords;//每次读取AD数据的长度(字)PCI8932_PARA_ADADPara;//硬件参数#defineMAX_AD_CHANNELS4//定义最大通道数#defineAD_DATA_LEN1024*8//要读取和处理的AD数据长度(点或字)USHORTADBuffer[AD_DATA_LEN];//分配缓冲区(存储原始数据)classDaq{public:voidCreateDevice(void);intSelectInputRange(void);voidsetparameter(void);voidInitDeviceAD(void);};intmain(intargc,char*argv[]){BOOLbFirstWait=TRUE;//为每次等待只显示一次提示LONGnRetSizeWords;intnADChannel=0;USHORTADData;floatfVolt;DaqAD;AD.CreateDevice();//创建设备对象InputRange=AD.SelectInputRange();//要求用户从键盘上选择输入量程AD.setparameter();//设置硬件参数AD.InitDeviceAD();//初始化ADwhile(!kbhit()){bFirstWait=TRUE;if(bFirstWait){printf("请等待,您可以按任意键退出,但请不要直接关闭窗口强制退出...\n");bFirstWait=FALSE;}if(!PCI8932_ReadDeviceAD(hDevice,ADBuffer,nReadSizeWords,&nRetSizeWords)){dwErrorCode=PCI8932_GetLastErrorEx("PCI8932_ReadDeviceAD",strErrorMsg);printf("dwErrorCode=%x,%s\n",dwErrorCode,strErrorMsg);getch();PCI8932_ReleaseDeviceAD(hDevice);PCI8932_ReleaseDevice(hDevice);//释放设备对象}nADChannel=ADPara.FirstChannel;for(intIndex=0;Index<64;Index++){if(kbhit())PCI8932_ReleaseDeviceAD(hDevice);PCI8932_ReleaseDevice(hDevice);//释放设备对象ADData=ADBuffer[Index]&0x1FFF;//将原码转换为电压值switch(InputRange){casePCI8932_INPUT_N10000_P10000mV://-10V-+10VfVolt=(float)((20000.00/8192)*ADData-10000.00);break;casePCI8932_INPUT_N5000_P5000mV://-5V-+5VfVolt=(float)((10000.00/8192)*ADData-5000.00);break;casePCI8932_INPUT_N2500_P2500mV://-2.5V-+2.5VfVolt=(float)((5000.00/8192)*ADData-2500.00);break;casePCI8932_INPUT_0_P10000mV://0V-+10VfVolt=(float)((10000.00/8192)*ADData);break;default:printf("InputRangeError...\n");getch();return0;}printf("CH%02d=%d\t",nADChannel,ADData);//显示电压值nADChannel++;if(nADChannel>ADPara.LastChannel){nADChannel=ADPara.FirstChannel;printf("\n");}}Sleep(200);}return0;}//创建设备对象voidDaq::CreateDevice(void){intDeviceLgcID;DeviceLgcID=0;hDevice=PCI8932_CreateDevice(DeviceLgcID);//创建设备对象if(hDevice==INVALID_HANDLE_VALUE){dwErrorCode=PCI8932_GetLastErrorEx("PCI8932_CreateDevice",strErrorMsg);printf("dwErrorCode=%x,%s\n",dwErrorCode,strErrorMsg);}}//获取用户选择的输入量程intDaq::SelectInputRange(void){LONGInputRange;Repeat:printf("\n");printf("0.-10V~+10V\n");printf("1.-5V~+5V\n");printf("2.-2.5V~+2.5V\n");printf("3.0V~+10V\n");printf("PleaseSelectInputRange[0-3]:");scanf("%d",&InputRange);if(InputRange<0||InputRange>3)gotoRepeat;//判断用户选择的量程是否合法,不合法,则重新选择returnInputRange;}//设置硬件参数voidDaq::setparameter(void){memset(&ADPara,0,sizeof(ADPara));//将参数结构初始化为确定值0(强烈建议)//预置硬件参数ADPara.FirstChannel=0;//首通道ADPara.LastChannel=3;//末通道ADPara.InputRange=InputRange;//模拟量输入量程范围ADPara.GroundingMode=PCI8932_GNDMODE_SE;//选择接地方式为单端ADPara.Gains=PCI8932_GAINS_1MULT;//程控增益intChannelCount=ADPara.LastChannel-ADPara.FirstChannel+1;nReadSizeWords=512-512%ChannelCount;//将数据长度字转换为双字}//初始化ADvoidDaq::InitDeviceAD(void){if(!PCI8932_InitDe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论