測繪程序設計基礎 實驗3 CSU
實驗3 函數
(交會定點計算程序設計)
(工具:VS2010)
一、 實驗目的
• 掌握函數的定義、引用及應用方法
二、實驗內容與要求
• 把前方交會、側邊交會、後方交會程序寫成函數的形式,然後再通過主程序調用。
三、設計與實現:
3.1 設計思路:
1 在【文件】菜單執行【新建】,選擇【項目】。
2 在【項目類型】窗格中,選擇【Visual C++】下的“MFC”項。在【模板】窗格中,選擇“MFC 應用程序”模板,輸入應用名“RS_110_zhang_SY3_01”。按嚮導創建“RS_110_zhang_SY3_01”的MFC應用程序,應用程序類型爲基於對話框。
3 在窗體上放置3個命令按鈕,其【Caption】依次爲前方交會、後方交會、邊長交會,並修改ID。
4 在【資源視圖】窗格中的“Dialog”文件右擊,插入“Dialog(E)”,出現一個新的對話框,修改對話框ID。共創建4個對話框:
5 設置對話框屬性:
以後方交會爲例:將2個編輯框依次右擊執行【添加變量】,在彈出的【添加成員變量嚮導】對話框中,【類別】屬性更改爲“Value”型,【變量類型】屬性更改爲“CString”類型,將【變量名】依次命名爲“strResection”、“strResult”,並修改其ID。
5.1 點擊一命令按鈕,將其【Caption】屬性更改爲“計算”。雙擊命令按鈕,進入“void Back::OnBnClickedWorktoback1()”中,添加代碼,在該.cpp文件中依次添加函數並輔以說明;另一完成歸零功能的命令按鈕操作與上類似。
5.2 流程圖如下:
6 添加輔助類“Support”:
7 包含頭文件:“Back.cpp”“Front.cpp”“Side.cpp”分別在頭文件中添加語句
“#include “Support.h””
8 運行和調試程序;
9 保存應用程序。
3.2 界面設計:
3.2.1界面
3.2.2控件屬性
3.3主要代碼:
3.3.1文件:<Support.h>
#pragma once
class CSupport
{
public:
CSupport(void);
~CSupport(void);
int SplitStringArray(CString str, char split, CStringArray& aStr);
double Process_oppDegree(double dDms);
double Process_oppD(double dDeg);
double Back1(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB);
double Back2(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB);
double length(double x1,double y1,double x2,double y2);
double angle(double a,double b,double c);
double pocess_P(double a,double b);
double pocess_answer01(double PA,double PB,double PC,double a,double b,double c);
double Process_Rad(double dx1,double dy1,double dx2,double dy2);
bool AreYouTriangle(double a,double b,double c);
void CBack_intersection(CString strResection,CString &strResult);
void CFore_intersection(CString strFront,CString &strOutFront);
void CLinear_intersection(CString strSide,CString &strOutSide);
};
3.3.2文件:<Support.cpp>
包含13個函數,由三個主函數與9個小函數相輔而成。
/***************************************************************************
* 文件名:<Support.cpp> *
* *
* 描述:封裝所有函數的類 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建 *** *
* *
* 外部過程: *
* *
/**************************************************************************/
/***************************************************************************
* 名字:double CSupport::SplitStringArray(CString str, char split, CStringArray& aStr) *
* *
* 描述:字符串分割函數 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.CString str *
* 2.char split *
* 3.CStringArray& aStr *
* 返回值:int類型數據 返回n *
* *
* 注: *
/**************************************************************************/
int CSupport::SplitStringArray(CString str, char split, CStringArray& aStr)
{
int startIdx = 0;
int idx = str.Find(split, startIdx);
aStr.RemoveAll();//先清空
while (-1 != idx)
{
CString sTmp = str.Mid(startIdx, idx - startIdx);
aStr.Add(sTmp);
startIdx = idx + 1;
idx = str.Find(split, startIdx);
}
CString sTmp = str.Right(str.GetLength() - startIdx);
if (! sTmp.IsEmpty())
aStr.Add(sTmp);
return aStr.GetSize();
}
/***************************************************************************
* 名字:double Process_oppD(double dDeg) *
* *
* 描述:十進制的角度值--》弧度式方位角 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double dDeg*PI/180 *
* *
* *
* 返回值:double類型數據 返回弧度值 *
* *
* 注: *
/**************************************************************************/
double CSupport::Process_oppD(double dDeg)
{
return dDeg*Pi/180;
}
/***************************************************************************
* 名字:Back1(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB) *
* *
* 描述:前方交會的主要公式之一 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double Xa *
* 2.double Xb *
* 3.double Ya *
* 4.double Yb *
* 5.double dCotA *
* 6.double dCotB *
* 返回值:double類型數據 返回xp座標 *
* *
* 注: *
/**************************************************************************/
double CSupport::Back1(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB)
{
return (((Xa*dCotB+Xb*dCotA)+(Yb-Ya))/(dCotA+dCotB));
}
/***************************************************************************
* 名字:Back2(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB) *
* *
* 描述:前方交會的主要公式之一 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double Xa *
* 2.double Xb *
* 3.double Ya *
* 4.double Yb *
* 5.double dCotA *
* 6.double dCotB *
* 返回值:double類型數據 返回yp座標 *
* *
* 注: *
/**************************************************************************/
double CSupport::Back2(double Xa,double Xb,double Ya,double Yb,double dCotA,double dCotB)
{
return (((Ya*dCotB+Yb*dCotA)+(Xa-Xb))/(dCotA+dCotB));
}
/***************************************************************************
* 名字:Process_oppDegree(double dDms) *
* *
* 描述:度分秒形式--》十進制的角度值 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月8日 創建該函數 *** *
* 2019年3月20日 再次調用 *** *
* 參數: 1.double dDms *
* *
* *
* 返回值:double類型數據 dDeg 返回十進制的角度值 *
* *
* 注: *
/**************************************************************************/
double CSupport::Process_oppDegree(double dDms)
{
int iDegree,iMin;
double dSec;
double dDeg;
iDegree=int(dDms);
iMin=int((dDms-iDegree)*100);
dSec=((dDms-iDegree)*100-iMin)*100;
dDeg=iDegree+double(iMin)/60+dSec/3600;
return dDeg;
}
/***************************************************************************
* 名字:double length(double x1,double y1,double x2,double y2) *
* *
* 描述:由(x1,y1)和(x2,y2)計算兩點之間距離 長度 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double x1 *
* 2.double y1 *
* 3.double x2 *
* 4.double y2 *
* 返回值:double類型數據 返回距離 *
* *
* 注: *
/**************************************************************************/
double CSupport::length(double x1,double y1,double x2,double y2)
{
double tmp=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
return sqrt(tmp);
}
/***************************************************************************
* 名字:double angle(double a,double b,double c) *
* *
* 描述:三角形已知a、b、c三邊長,計算a,b之間夾角 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double a *
* 2.double b *
* 3.double c *
* 返回值:double類型數據 返回夾角 *
* *
* 注: *
/**************************************************************************/
double CSupport::angle(double a,double b,double c)
{
return acos((a*a+b*b-c*c)/(2*a*b));
}
/***************************************************************************
* 名字:double pocess_P(double a,double b) *
* *
* 描述:後方交會的公式之一 求P值 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double a *
* 2.double b *
* 返回值:double類型數據 返回P值 *
* *
* 注: *
/**************************************************************************/
double CSupport::pocess_P(double a,double b)
{
return ((tan(a)*tan(b))/(tan(a)-tan(b)));
}
/***************************************************************************
* 名字:pocess_answer01(double PA,double PB,double PC,double a,double b,double c)*
* *
* 描述:後方交會的公式之一 求xp或yp點位座標 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.double PA *
* 2.double PB *
* 3.double PC *
* 4.double a *
* 5.double b *
* 6.double c *
* 返回值:double類型數據 返回P值 *
* *
* 注: *
/**************************************************************************/
double CSupport::pocess_answer01(double PA,double PB,double PC,double a,double b,double c)
{
return ((PA*a+PB*b+PC*c)/(PA+PB+PC));
}
/***************************************************************************
* 名字:double Process_Rad(double dx1,double dy1,double dx2,double dy2) *
* *
* 描述:4個座標值--》弧度式方位角 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月8日 創建該函數 *** *
* 2019年3月21日 調用 *** *
* 參數: 1.double dx1 *
* 2.double dy1 *
* 3.double dx2 *
* 4.double dy2 *
* *
* 返回值:double類型數據 轉換後的rad型方位角 *
* *
* 注:該函數在輸入兩座標值相同時,會有一對話框彈出,且此時返回值爲0 *
/**************************************************************************/
double CSupport::Process_Rad(double dx1,double dy1,double dx2,double dy2)
{
double dx=dx2-dx1;
double dy=dy2-dy1;
double dRad;
if(dy>0){
if(dx<0){
dRad=atan(dy/dx)+PI;//第二象限
}
else if(dx>0){
dRad=atan(dy/dx);//第一象限
}
else{
dRad=PI/2;//位於Y軸正方向
}
}
else if(dy<0){
if(dx<0){
dRad=atan(dy/dx)+PI;//第三象限
}
else if(dx>0){
dRad=atan(dy/dx)+2*PI;//第四象限
}
else{
dRad=PI*3/2;//位於Y軸負方向
}
}
else{
if(dx>0){
dRad=0;//位於X正半軸
}
else if(dx<0){
dRad=PI;//位於X負半軸
}
else{
AfxMessageBox(_T("您不能輸入相同的座標。"));//(x1,y1)==(x2,y2)的情況
return 0;
}
}
return dRad;
}
/***************************************************************************
* 名字:bool CSupport::AreYouTriangle(double a,double b,double c) *
* *
* 描述:判斷三條邊是否能構成三角形 *
* *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月22日 創建該函數 *** *
* 參數: 1.double a *
* 2.double b *
* 2.double c *
* *
* 返回值:bool型 *
* *
* 注:暫時僅支持一行數據處理 *
/**************************************************************************/
bool CSupport::AreYouTriangle(double a,double b,double c)
{
return bool(a+b>c&&a+c>b&&b+c>a);
}
/***************************************************************************
* 名字:void CBack_intersection(CString strResection,CString &strResult) *
* *
* 描述:前方交會主函數,調用了SplitStringArray、Process_oppD *
* Process_oppDegree、length、angle、pocess_P、pocess_answer01等7個函數 *
* *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.CString strResection *
* 2.CString &strResult *
* *
* 返回值:CString類型數據 輸出座標(xp,yp) *
* *
* 注:支持多行數據處理 *
/**************************************************************************/
void CSupport::CBack_intersection(CString strResection,CString &strResult)
{
int iLine;//行數
CStringArray aStrLine;
iLine=SplitStringArray(strResection,13,aStrLine);
if(iLine==0)
{
AfxMessageBox(_T("請輸入數據!"));
}
/*
if(iLine>1)
{
AfxMessageBox(_T("當前僅支持處理單行數據"));
}*/
//定義結構體和動態數組
struct Point2D
{
double dx1;
double dy1;
double dx2;
double dy2;
double dx3;
double dy3;
double dAlpha;
double dBeta;
double dGamma;
double dAlpha0;
double dBeta0;
double dGamma0;
double dlength[3];
double dAngel[3];
double dP[3];
double dxp;
double dyp;
double temp1;
double temp2;
double temp3;
bool dDanger;
};
Point2D *point= new Point2D[iLine];
//使用Split函數分離,獲得座標
CStringArray aStrTmp;
//int i=0;
int n;
for(int i=0;i<iLine;i++)
{
n=SplitStringArray(aStrLine[i],',',aStrTmp);
point[i].dx1 =_tstof(aStrTmp[0]);
point[i].dy1 =_tstof(aStrTmp[1]);
point[i].dx2 =_tstof(aStrTmp[2]);
point[i].dy2 =_tstof(aStrTmp[3]);
point[i].dx3 =_tstof(aStrTmp[4]);
point[i].dy3 =_tstof(aStrTmp[5]);
//讀取三個角度並處理,由角度轉爲十進制的角度再轉爲弧度制
point[i].dAlpha =_tstof(aStrTmp[6]);
point[i].dBeta =_tstof(aStrTmp[7]);
point[i].dGamma =_tstof(aStrTmp[8]);
point[i].dAlpha0=point[i].dAlpha;
point[i].dBeta0=point[i].dBeta;
point[i].dGamma0=point[i].dGamma;
point[i].dAlpha=Process_oppD(Process_oppDegree(point[i].dAlpha));
point[i].dBeta=Process_oppD(Process_oppDegree(point[i].dBeta));
point[i].dGamma=Process_oppD(Process_oppDegree(point[i].dGamma));
//求三條邊的長度
point[i].dlength[0]=length(point[i].dx1,point[i].dy1,point[i].dx2,point[i].dy2);//(x1,y1)與(x2,y2)之間長度 記爲邊1
point[i].dlength[1]=length(point[i].dx1,point[i].dy1,point[i].dx3,point[i].dy3);//(x1,y1)與(x3,y3)之間長度 記爲邊2
point[i].dlength[2]=length(point[i].dx2,point[i].dy2,point[i].dx3,point[i].dy3);//(x2,y2)與(x3,y3)之間長度 記爲邊3
//求角度
point[i].dAngel[0]=angle(point[i].dlength[0],point[i].dlength[1],point[i].dlength[2]);//邊1與邊2夾角 角A
point[i].dAngel[1]=angle(point[i].dlength[1],point[i].dlength[2],point[i].dlength[0]);//邊2與邊3夾角 角B
point[i].dAngel[2]=angle(point[i].dlength[0],point[i].dlength[2],point[i].dlength[1]);//邊1與邊3夾角 角C
//計算P
point[i].dP[0]=pocess_P(point[i].dAlpha,point[i].dAngel[0]);//求PA
point[i].dP[1]=pocess_P(point[i].dBeta,point[i].dAngel[1]);//求PB
point[i].dP[2]=pocess_P(point[i].dGamma,point[i].dAngel[2]);//求PC
//計算xp,yp
point[i].dxp=pocess_answer01(point[i].dP[0],point[i].dP[1],point[i].dP[2],point[i].dx1,point[i].dx2,point[i].dx3);
point[i].dyp=pocess_answer01(point[i].dP[0],point[i].dP[1],point[i].dP[2],point[i].dy1,point[i].dy2,point[i].dy3);
//判斷數據 判斷後方交會是否危險園附近
point[i].temp1 =point[i].dGamma0+point[i].dBeta0+point[i].dAngel[0]*180/PI;
point[i].temp2 =point[i].dAlpha0+point[i].dGamma0+point[i].dAngel[1]*180/PI;
point[i].temp3 =point[i].dAlpha0+point[i].dBeta0+point[i].dAngel[2]*180/PI;
if((point[i].temp1>170&&point[i].temp1<190)||(point[i].temp2>170&&point[i].temp2<190)||(point[i].temp3>170&&point[i].temp3<190))
{
point[i].dDanger=1;
}
else
{
point[i].dDanger=0;
}
//輸出
strResult.Format(_T("%s\t%s\t%s\t\r\n"),
_T("Yp:"),
_T("Xp:"),
_T(" ")
);
CString strOutput;
for(int z=0;z<iLine;z++)
{
if(point[z].dAlpha0+point[z].dBeta0+point[z].dGamma0==360){
if(AreYouTriangle(point[z].dlength[0],point[z].dlength[1],point[z].dlength[2]))
{
if(point[z].dDanger)
{
strOutput.Format(_T("%.3lf\t%.3lf\t%s\r\n"),point[z].dxp,point[z].dyp,_T("危險圓"));
strResult=strResult+strOutput;
}
else
{
strOutput.Format(_T("%.3lf\t%.3lf\t\r\n"),point[z].dxp,point[z].dyp);
strResult=strResult+strOutput;
}
}
else
{
strOutput.Format(_T("錯誤,不能構成三角形\r\n"));
strResult=strResult+strOutput;
}
}
else
{
strOutput.Format(_T("α與β與γ之和非360,錯誤\r\n"));
strResult=strResult+strOutput;
}
}
}
if(point!=NULL)
{
delete[] point;
point=NULL;
}
}
/***************************************************************************
* 名字:CFore_intersection(CString strFront,CString &strOutFront) *
* *
* 描述:前方交會主函數,調用了SplitStringArray、Process_oppD *
* Process_oppDegree、Back1、Back2等5個函數 *
* *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.CString strFront *
* 2.CString &strOutFront *
* *
* 返回值:CString類型數據 輸出座標(xp,yp) *
* 注:支持多行數據處理 *
* *
/**************************************************************************/
void CSupport::CFore_intersection(CString strFront,CString &strOutFront)
{
int iLine;
CStringArray aStrLine;
iLine=SplitStringArray(strFront,13,aStrLine);
if(iLine==0)
{
AfxMessageBox(_T("請輸入數據!"));
}
struct Point2D
{
double dx1;
double dy1;
double dx2;
double dy2;
double dAlpha;
double dBeta;
double dCotA;
double dCotB;
double dxp;
double dyp;
};
Point2D *point= new Point2D[iLine];
//使用Split函數分離,獲得座標
CStringArray aStrTmp;
int n;
for(int i=0;i<iLine;i++)
{
n=SplitStringArray(aStrLine[i],',',aStrTmp);
point[i].dx1 =_tstof(aStrTmp[0]);
point[i].dy1 =_tstof(aStrTmp[1]);
point[i].dx2 =_tstof(aStrTmp[2]);
point[i].dy2 =_tstof(aStrTmp[3]);
point[i].dAlpha =_tstof(aStrTmp[4]);
point[i].dBeta =_tstof(aStrTmp[5]);
point[i].dCotA=1/tan(Process_oppD(Process_oppDegree(point[i].dAlpha)));
point[i].dCotB=1/tan(Process_oppD(Process_oppDegree(point[i].dBeta)));
point[i].dxp=Back1(point[i].dx1,point[i].dx2,point[i].dy1,point[i].dy2,point[i].dCotA,point[i].dCotB);
point[i].dyp=Back2(point[i].dx1,point[i].dx2,point[i].dy1,point[i].dy2,point[i].dCotA,point[i].dCotB);
//輸出
strOutFront.Format(_T("%s\t%s\t\r\n"),
_T("Xp:"),
_T("Yp:"));
CString strOutput;
for(int z=0;z<iLine;z++)
{
if((point[z].dAlpha+point[z].dBeta)<180)
{
strOutput.Format(_T("%.3lf\t%.3f\t\r\n"),point[z].dxp,point[z].dyp);
strOutFront=strOutFront+strOutput;
}
else
{
strOutput.Format(_T("錯誤,alpha+β>180\r\n"));
strOutFront=strOutFront+strOutput;
}
}
}
if(point!=NULL)
{
delete[] point;
point=NULL;
}
}
/***************************************************************************
* 名字:CLinear_intersection(CString strSide,CString &strOutSide) *
* *
* 描述:前方交會主函數,調用了SplitStringArray、Process_Rad *
* angle、AreYouTriangle等4個函數 *
* *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建該函數 *** *
* 參數: 1.CString strSide *
* 2.CString &strOutSide *
* *
* 返回值:CString類型數據 輸出座標(xp,yp) *
* *
* 注:支持多行數據處理 *
/**************************************************************************/
void CSupport::CLinear_intersection(CString strSide,CString &strOutSide)
{
CSupport j;
int iLine;
CStringArray aStrLine;
iLine=SplitStringArray(strSide,13,aStrLine);
if(iLine==0)
{
AfxMessageBox(_T("請輸入數據!"));
}
struct Point2D
{
double dx1;
double dy1;
double dx2;
double dy2;
double dDab;//兩點長度
double dDap;
double dDbp;
double dAlphaAB;
double dAlphaBA;
double dBAP;
double dABP;
double dap;
double dbp;
double dxp;
double dyp;
};
Point2D *point= new Point2D[iLine];
//使用Split函數分離,獲得座標
CStringArray aStrTmp;
int n;
for(int i=0;i<iLine;i++)
{
n=SplitStringArray(aStrLine[i],',',aStrTmp);
point[i].dx1 =_tstof(aStrTmp[0]);
point[i].dy1 =_tstof(aStrTmp[1]);
point[i].dx2 =_tstof(aStrTmp[2]);
point[i].dy2 =_tstof(aStrTmp[3]);
point[i].dDap =_tstof(aStrTmp[4]);
point[i].dDbp =_tstof(aStrTmp[5]);
point[i].dDab =length(point[i].dx1,point[i].dy1,point[i].dx2,point[i].dy2);
point[i].dAlphaAB=Process_Rad(point[i].dx1,point[i].dy1,point[i].dx2,point[i].dy2);
point[i].dAlphaBA=Process_Rad(point[i].dx2,point[i].dy2,point[i].dx1,point[i].dy1);
point[i].dBAP=angle(point[i].dDab,point[i].dDap,point[i].dDbp);
point[i].dABP=angle(point[i].dDab,point[i].dDbp,point[i].dDap);
point[i].dap=point[i].dAlphaAB-point[i].dBAP;
point[i].dbp=point[i].dAlphaBA+point[i].dABP;
point[i].dxp=point[i].dx1+point[i].dDap*cos(point[i].dap);
point[i].dyp=point[i].dy1+point[i].dDap*sin(point[i].dap);
//輸出
strOutSide.Format(_T("%s\t%s\t\r\n"),
_T("Xp:"),
_T("Yp:"));
CString strOutput;
for(int z=0;z<iLine;z++)
{
if(AreYouTriangle(point[z].dDab,point[z].dDap,point[z].dDbp))
{
strOutput.Format(_T("%.3f\t%.3f\t\r\n"),point[z].dxp,point[z].dyp);
strOutSide=strOutSide+strOutput;
}
else
{
strOutput.Format(_T("錯誤,不能構成三角形\r\n"));
strOutSide=strOutSide+strOutput;
}
}
}
if(point!=NULL)
{
delete[] point;
point=NULL;
}
}
3.3.3文件:< CRS_110_zhang_SY3_01Dlg.cpp>
/***************************************************************************
* 文件名:<RS_110_zhang_SY3_01Dlg.cpp> *
* *
* 描述:主界面 生成後方、前方、邊長交會 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建 *** *
* *
* 外部過程: *
* *
/**************************************************************************/
void CRS_110_zhang_SY3_01Dlg::OnBnClickedButton1Back()
{
// TODO: 在此添加控件通知處理程序代碼
Back B;
B.DoModal ();
}
void CRS_110_zhang_SY3_01Dlg::OnBnClickedButton2Front()
{
// TODO: 在此添加控件通知處理程序代碼
Front B;
B.DoModal ();
}
void CRS_110_zhang_SY3_01Dlg::OnBnClickedButton3Side()
{
// TODO: 在此添加控件通知處理程序代碼
Side B;
B.DoModal ();
}
3.3.4文件:<Back.cpp>
/***************************************************************************
* 文件名:<Back.cpp> *
* *
* 描述:實現後方交會的類 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建 *** *
* *
* 外部過程: *
* *
/**************************************************************************/
void Back::OnBnClickedWorktoback1()
{
// TODO: 在此添加控件通知處理程序代碼
UpdateData(true);
CSupport k;
k.CBack_intersection(strResection,strResult);
UpdateData(false);
}
void Back::OnBnClickedButton1Zeroing1()
{
// TODO: 在此添加控件通知處理程序代碼
strResection.Format(_T(""));
strResult.Format(_T(""));
UpdateData(false);
}
3.3.5文件:<Front.cpp>
/***************************************************************************
* 文件名:<Front.cpp> *
* *
* 描述:實現前方交會的類 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建 *** *
* *
* 外部過程: *
* *
/**************************************************************************/
void Front::OnBnClickedWorkFront2()
{
// TODO: 在此添加控件通知處理程序代碼
UpdateData(true);
CSupport k;
k.CFore_intersection(strFront,strOutFront);
UpdateData(false);
}
void Front::OnBnClickedButton1Zeroing2()
{
// TODO: 在此添加控件通知處理程序代碼
strFront.Format(_T(""));
strOutFront.Format(_T(""));
UpdateData(false);
}
3.3.6文件:<Side.cpp>
/***************************************************************************
* 文件名:<Side.cpp> *
* *
* 描述:實現邊長交會的類 *
* *
* 歷史:**日期** **理由** **簽名** *
* 2019年3月20日 創建 *** *
* *
* 外部過程: *
* *
/**************************************************************************/
void Side::OnBnClickedSide3()
{
UpdateData(true);
CSupport k;
k.CLinear_intersection(strSide,strOutSide);
UpdateData(false);
// TODO: 在此9添加控件通知處理程序代碼
}
void Side::OnBnClickedButton1Side3()
{
strSide.Format(_T(""));
strOutSide.Format(_T(""));
UpdateData(false);
}
3.4運行結果
3.5設計技巧:
創建一個新類“Support”,將用到的函數全部定義爲該類的共有函數,再創建對象,調用該類中的函數,使程序變得整潔,尋找修改函數也更加方便。
在設計之前,要有個整體的框架。提前想好ID及變量名,這樣在搭建Dialog時不必糾結,浪費時間,減少錯誤。此次實驗其實也能僅由一個Dialog加多個按鈕來完成,不需要多個對話框。而我做之前思路沒清晰,搭建過程中不好修改,浪費了一些功夫。
熟練調用函數、結構體可以大幅度節省時間。
調用以前自己編寫的函數。