百韵网 >>  正文

求一个C++的程序 大约在1000行左右的 要求有注释的 求一个C++的程序 大约在1000行左右的 要求有注释的 题...

来源:www.baiyundou.net   日期:较早时间
#include "MyFace.h"
#include "Edge.h"
#include "Bucket.h"
#include "P2D.h"
#define Number 4//N为闭合多边形顶点数,顶点存放在整型二维数组Point[N]中

class CTestView : public CView
{
protected: // create from serialization only
CTestView();
DECLARE_DYNCREATE(CTestView)

// Attributes
public:
CTestDoc* GetDocument();

// Operations
public:
void GetMaxX();//获得屏幕的最大x值
void GetMaxY();//获得屏幕的最大y值
void ReadPoint();//读入顶点表
void ReadFace();//读入面表
void InitParameter();//参数初始化
void VisualVector(int);//求视向量分量
void NormalVector(int,int,int);//求法向量
double Product(P3D &,P3D &);//求向量的数量积
void SetCoord();//坐标设置
void DrawSmoothObject(CDC* mdc);//面顶点设置
void DrawFace(CDC *pDC);//画各个面
void Project(P3D &);//透视投影
void CreatBucket();//建立桶结点
void Et();//构造边表
void AddAet(Edge *);//将边插入Aet表
void AetOrder();//对Aet表进行排序
void PolygonFill(CDC*);//下闭上开填充多边形
MyRGB Interpolation(int,int,int,MyRGB &,MyRGB &);//线性插值
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CTestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
int MaxX,MaxY;//屏幕水平和垂直的最大坐标
P3D P[9],ViewP,N,S;//N法向量,S视向量
MyFace F[7];//面表
double R,Theta,Phi,D;//R,Theta,Phi视点在用户坐标系的球坐标,D视距
double k[9];//运算常量
double O1,O2,O3;//视点球坐标分量
P2D Point[4],ScreenP;//屏幕坐标系的二维坐标点
int Face;//面
CDC Picture;//双缓冲图片
Bucket *CurrentB,*HeadB;//桶指针
Edge E[Number],*CurrentE,*HeadE,*T1,*T2;//边表指针
BOOL Play;//动画开关
// Generated message map functions
protected:
//{{AFX_MSG(CTestView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnMENUPlay();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnUpdateMENUPlay(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in TestView.cpp
inline CTestDoc* CTestView::GetDocument()
{ return (CTestDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TESTVIEW_H__A75FDCFB_621C_4E38_A154_C344803E6372__INCLUDED_)
// TestView.cpp : implementation of the CTestView class
//

#include "stdafx.h"
#include "Test.h"
#include "TestDoc.h"
#include "TestView.h"
#define ROUND(a) int(a+0.5)//四舍五入
#define PI 3.1415926//圆周率
#include "cmath"//数学头文件
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestView

IMPLEMENT_DYNCREATE(CTestView, CView)

BEGIN_MESSAGE_MAP(CTestView, CView)
//{{AFX_MSG_MAP(CTestView)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDBLCLK()
ON_WM_ERASEBKGND()
ON_COMMAND(ID_MENUPlay, OnMENUPlay)
ON_WM_TIMER()
ON_UPDATE_COMMAND_UI(ID_MENUPlay, OnUpdateMENUPlay)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction

CTestView::CTestView()
{
// TODO: add construction code here
Play=FALSE;
R=700.0;D=1000;Theta=-10;Phi=20;
}

CTestView::~CTestView()
{
}

BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestView drawing

void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CTestView printing

BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics

#ifdef _DEBUG
void CTestView::AssertValid() const
{
CView::AssertValid();
}

void CTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CTestDoc* CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers

void CTestView::GetMaxX()//获得屏幕宽度
{
CRect Rect;
GetClientRect(&Rect);
MaxX=Rect.right;
}
void CTestView::GetMaxY()//获得屏幕高度
{
CRect Rect;
GetClientRect(&Rect);
MaxY=Rect.bottom;
}

void CTestView::ReadPoint()//读入8个顶点坐标
{
double a=100;//正方体边长
//x,y,z和顶点颜色
P[1].x=-a;P[1].y=-a;P[1].z=-a;P[1].c.red=0.0;P[1].c.green=1.0;P[1].c.blue=1.0;
P[2].x=-a;P[2].y=a;P[2].z=-a;P[2].c.red=1.0;P[2].c.green=0.0;P[2].c.blue=1.0;
P[3].x=-a;P[3].y=a;P[3].z=a;P[3].c.red=0.0;P[3].c.green=0.0;P[3].c.blue=1.0;
P[4].x=-a;P[4].y=-a;P[4].z=a;P[4].c.red=0.0;P[4].c.green=0.0;P[4].c.blue=0.0;
P[5].x=a;P[5].y=-a;P[5].z=-a;P[5].c.red=0.0;P[5].c.green=1.0;P[5].c.blue=0.0;
P[6].x=a;P[6].y=a;P[6].z=-a;P[6].c.red=1.0;P[6].c.green=1.0;P[6].c.blue=1.0;
P[7].x=a;P[7].y=a;P[7].z=a;P[7].c.red=1.0;P[7].c.green=0.0;P[7].c.blue=0.0;
P[8].x=a;P[8].y=-a;P[8].z=a;P[8].c.red=1.0;P[8].c.green=1.0;P[8].c.blue=0.0;
}
void CTestView::ReadFace()//读入6个面坐标
{
//面的边数,面的顶点编号,面的颜色
F[1].En=4;F[1].p[1]=1;F[1].p[2]=4;F[1].p[3]=3;F[1].p[4]=2;//左面
F[2].En=4;F[2].p[1]=5;F[2].p[2]=6;F[2].p[3]=7;F[2].p[4]=8;//右面
F[3].En=4;F[3].p[1]=8;F[3].p[2]=4;F[3].p[3]=1;F[3].p[4]=5;//底面
F[4].En=4;F[4].p[1]=7;F[4].p[2]=6;F[4].p[3]=2;F[4].p[4]=3;//顶面
F[5].En=4;F[5].p[1]=3;F[5].p[2]=4;F[5].p[3]=8;F[5].p[4]=7;//前面
F[6].En=4;F[6].p[1]=2;F[6].p[2]=6;F[6].p[3]=5;F[6].p[4]=1;//后面
}

void CTestView::VisualVector(int pt)//求视矢量分量
{
O1=R*k[5];O2=R*k[6];O3=R*k[4];//观察坐标系的视点球坐标
S.x=O1-P[pt].x;S.y=O2-P[pt].y;S.z=O3-P[pt].z;//视矢量
}

void CTestView::NormalVector(int p1,int p2,int p3)//求表面法矢量分量
{
P3D F,H;
//求第一条边的分量
F.x=P[p2].x-P[p1].x;F.y=P[p2].y-P[p1].y;F.z=P[p2].z-P[p1].z;
//求第二条边的分量
H.x=P[p3].x-P[p1].x;H.y=P[p3].y-P[p1].y;H.z=P[p3].z-P[p1].z;
//法向量为第一和第二个向量的叉积
N.x=F.y*H.z-F.z*H.y;N.y=F.z*H.x-F.x*H.z;N.z=F.x*H.y-F.y*H.x;
}

double CTestView::Product(P3D &v,P3D &n)//求矢量的数量积
{
double NProduct;
NProduct=v.x*n.x+v.y*n.y+v.z*n.z;
return(NProduct);
}

void CTestView::Project(P3D &P)//透视变换
{
ViewP.x=k[1]*P.x-k[3]*P.y;//观察坐标系三维坐标
ViewP.y=-k[7]*P.x-k[8]*P.y+k[2]*P.z;
ViewP.z=-k[5]*P.x-k[6]*P.y-k[4]*P.z+R;
ScreenP.x=D*ViewP.x/ViewP.z;//屏幕坐标系二维坐标
ScreenP.y=ROUND(D*ViewP.y/ViewP.z);
ScreenP.c=P.c;
}

void CTestView::InitParameter()//透视变换初始化参数
{
k[1]=sin(PI*Theta/180);
k[2]=sin(PI*Phi/180);
k[3]=cos(PI*Theta/180);
k[4]=cos(PI*Phi/180);
k[5]=k[3]*k[2];
k[6]=k[1]*k[2];
k[7]=k[3]*k[4];
k[8]=k[1]*k[4];
}
void CTestView::OnLButtonDown(UINT nFlags, CPoint point)//鼠标左键函数
{
// TODO: Add your message handler code here and/or call default
R=R+100;
SetCoord();
CView::OnLButtonDown(nFlags, point);
}

void CTestView::OnRButtonDblClk(UINT nFlags, CPoint point)//鼠标右键函数
{
// TODO: Add your message handler code here and/or call default
R=R-100;
SetCoord();
CView::OnRButtonDblClk(nFlags, point);
}

void CTestView::SetCoord()//坐标设置
{
CRect Rect;
GetClientRect(&Rect);
CDC MemDC;
CBitmap Bitmap,*OldBitmap;
Bitmap.LoadBitmap(IDB_BITMAP2);
MemDC.CreateCompatibleDC(GetDC());
OldBitmap=MemDC.SelectObject(&Bitmap);
MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),&Picture,0,0,SRCCOPY);
int P1,P2,P3;//面的顶点
for(Face=1;Face<=6;Face++)
{
P1=F[Face].p[1];//面的第一个顶点
P2=F[Face].p[2];//面的第二个顶点
P3=F[Face].p[3];//面的第三个顶点
VisualVector(P1);//求视矢量
NormalVector(P1,P2,P3);//求法矢量
if(Product(S,N)>=0)//判断数量积正负
DrawSmoothObject(&MemDC);//数量积大于零,表面画出
}
CClientDC dc(this);
dc.BitBlt(0,0,Rect.Width(),Rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(OldBitmap);
}
void CTestView::DrawSmoothObject(CDC* mdc)//面顶点设置
{
int TotalEdge=F[Face].En;//计算每个面的总边数
for(int edge=1;edge<=TotalEdge;edge++)//边循环
{
P3D Vertex;
int PointNumber=F[Face].p[edge];//面的顶点号
Vertex=P[PointNumber];
Project(Vertex);//透视投影
Point[edge-1]=ScreenP;
}
CreatBucket();//初始化桶
Et();//用于建立边表
PolygonFill(mdc);//进行填充
}
//*****************有效边表算法开始***********************

void CTestView::PolygonFill(CDC* mdc)//下闭上开多边形填充
{
HeadE=NULL;
for(CurrentB=HeadB;CurrentB!=NULL;CurrentB=CurrentB->next)//访问所有桶结点
{
for(CurrentE=CurrentB->p;CurrentE!=NULL;CurrentE=CurrentE->next)//访问桶中排序前的边结点
{
Edge *TEdge=new Edge;
TEdge->k=CurrentE->k;
TEdge->x=CurrentE->x;
TEdge->yMax=CurrentE->yMax;
TEdge->x1=CurrentE->x1;
TEdge->y1=CurrentE->y1;
TEdge->c1=CurrentE->c1;
TEdge->x2=CurrentE->x2;
TEdge->y2=CurrentE->y2;
TEdge->c2=CurrentE->c2;
TEdge->next=NULL;
AddAet(TEdge);//将该边插入临时Aet表
}
AetOrder();//使得Aet表按照x递增的顺序存放
T1=HeadE;//根据ymax抛弃扫描完的边结点
if(T1==NULL)
{
return;
}
while(CurrentB->ScanLine>=T1->yMax)//放弃该结点,Aet表指针后移
{
T1=T1->next;
HeadE=T1;
if(HeadE==NULL)
{
return;
}
}
if(T1->next!=NULL)
{
T2=T1;
T1=T2->next;
}
while(T1!=NULL)
{
if(CurrentB->ScanLine>=T1->yMax)//跳过一个结点
{
T2->next=T1->next;
T1->next=NULL;
T1=T2->next;
}
else
{
T2=T1;
T1=T2->next;
}
}
MyRGB Is,It,Ip;
if(CurrentE!=NULL)//扫描线上两边共线
{
Is=Interpolation(CurrentB->ScanLine,HeadE->y1,HeadE->y2,HeadE->c1,HeadE->c2);
It=Interpolation(CurrentB->ScanLine,HeadE->next->y2,HeadE->next->y1,HeadE->c2,HeadE->c1);
}
else
{
Is=Interpolation(CurrentB->ScanLine,HeadE->y1,HeadE->y2,HeadE->c1,HeadE->c2);
It=Interpolation(CurrentB->ScanLine,HeadE->next->y2,HeadE->next->y1,HeadE->next->c2,HeadE->next->c1);
}
BOOL In=false;//设置一个BOOL变量In,初始值为假
int xb,xe;//扫描线区间的起点和终点
for(T1=HeadE;T1!=NULL;T1=T1->next)//填充扫描线和多边形相交的区间
{
if(In==false)
{
xb=ROUND(T1->x)-1;
In=true;//每访问一个结点,把In值取反一次
}
else//如果In值为真,则填充从当前结点的x值开始到下一结点的x值结束的区间
{
xe=ROUND(T1->x);
for(double x=xb;x<=xe;x++)
{
Ip=Interpolation(ROUND(x),xb,xe,Is,It);
mdc->SetPixel(MaxX/2+ROUND(x),MaxY/2+CurrentB->ScanLine,RGB((BYTE)(Ip.red*255),(BYTE)(Ip.green*255),(BYTE)(Ip.blue*255)));
}
In=false;
}
}
for(T1=HeadE;T1!=NULL;T1=T1->next)//边连贯性
{
T1->x=T1->x+T1->k;//x=x+1/k
}
}
delete HeadB;
delete CurrentB;
delete CurrentE;
delete HeadE;
}

void CTestView::CreatBucket()//初始化桶结点
{
int ScanMin,ScanMax;//确定扫描线的最小值和最大值
ScanMax=ScanMin=Point[0].y;
for(int i=1;i<Number;i++)
{
if(Point[i].y<ScanMin)
{
ScanMin=Point[i].y;//扫描线的最小值
}
if(Point[i].y>ScanMax)
{
ScanMax=Point[i].y;//扫描线的最大值
}
}
for(i=ScanMin;i<=ScanMax;i++)//建立桶结点
{
if(ScanMin==i)
{
HeadB=new Bucket;//建立桶的头结点
CurrentB=HeadB;//CurrentB为Bucket当前结点指针
CurrentB->ScanLine=ScanMin;
CurrentB->p=NULL;//没有连接边链表
CurrentB->next=NULL;
}
else//建立桶的其它结点
{
CurrentB->next=new Bucket;//新建一个桶结点
CurrentB=CurrentB->next;//使CurrentB指向新建的桶结点
CurrentB->ScanLine=i;
CurrentB->p=NULL;//没有连接边链表
CurrentB->next=NULL;
}
}
}

void CTestView::Et()//构造边表
{
for(int i=0;i<Number;i++)//访问每个顶点
{
CurrentB=HeadB;//从桶链表的头结点开始循环
int j=i+1;//边的第二个顶点,Point[i]和Point[j]构成边
if(j==Number) j=0;//保证多边形的闭合
if(Point[j].y>Point[i].y)//边在扫描线的上方
{
while(CurrentB->ScanLine!=Point[i].y)//在桶内寻找该边的yMin
{
CurrentB=CurrentB->next;//在桶内寻找该边的yMin
}
E[i].x=Point[i].x;//计算Aet表的值
E[i].yMax=Point[j].y;
E[i].k=double((Point[j].x-Point[i].x))/(Point[j].y-Point[i].y);//代表1/k
E[i].x1=Point[i].x;
E[i].y1=Point[i].y;
E[i].c1=Point[i].c;
E[i].x2=Point[j].x;
E[i].y2=Point[j].y;
E[i].c2=Point[j].c;
E[i].next=NULL;
CurrentE=CurrentB->p;//获得桶上链接边表的地址
if(CurrentE==NULL)//当前桶结点上没有链接边结点
{
CurrentE=&E[i];//赋边的起始地址
CurrentB->p=CurrentE;//第一个边结点直接连接到对应的桶中
}
else
{
while(CurrentE->next!=NULL)//如果当前边已连有边结点
{
CurrentE=CurrentE->next;//移动指针到当前边的最后一个边结点
}
CurrentE->next=&E[i];//把当前边接上去
}
}
if(Point[j].y<Point[i].y)//边在扫描线的下方
{
while(CurrentB->ScanLine!=Point[j].y)
{
CurrentB=CurrentB->next;
}
E[i].x=Point[j].x;
E[i].yMax=Point[i].y;
E[i].k=double((Point[i].x-Point[j].x))/(Point[i].y-Point[j].y);
E[i].x1=Point[i].x;
E[i].y1=Point[i].y;
E[i].c1=Point[i].c;
E[i].x2=Point[j].x;
E[i].y2=Point[j].y;
E[i].c2=Point[j].c;
E[i].next=NULL;
CurrentE=CurrentB->p;
if(CurrentE==NULL)
{
CurrentE=&E[i];
CurrentB->p=CurrentE;
}
else
{
while(CurrentE->next!=NULL)
{
CurrentE=CurrentE->next;
}
CurrentE->next=&E[i];
}
}
}
CurrentB=NULL;
CurrentE=NULL;
}

void CTestView::AddAet(Edge *NewEdge)//边插入Aet表
{
T1=HeadE;
if(T1==NULL)//Aet表为空,将Aet表置为TEdge
{
T1=NewEdge;
HeadE=T1;
}
else
{
while(T1->next!=NULL)//Aet表不为空,将TEdge连在该边之后
{
T1=T1->next;
}
T1->next=NewEdge;
}
}

void CTestView::AetOrder()//对Aet表进行排序
{
T1=HeadE;
if(T1==NULL)
{
return;
}
if(T1->next==NULL)//如果该Aet表没有再连Aet表
{
return;//桶结点只有一条边,不需要排序
}
else
{
if(T1->next->x<T1->x)//Aet表按x值排序
{
T2=T1->next;
T1->next=T2->next;
T2->next=T1;
HeadE=T2;
}
T2=HeadE;
T1=HeadE->next;
while(T1->next!=NULL)//继续两两比较相连的Aet表的x值,进行排序
{
if(T1->next->x<T1->x)
{
T2->next=T1->next;
T1->next=T1->next->next;
T2->next->next=T1;
T2=T2->next;
}
else
{
T2=T1;
T1=T1->next;
}
}
}
}

MyRGB CTestView::Interpolation(int m,int m1,int m2,MyRGB &c1,MyRGB &c2)//线性插值
{
MyRGB I;
I.red=double(m-m2)/(m1-m2)*c1.red+double(m1-m)/(m1-m2)*c2.red;
I.green=double(m-m2)/(m1-m2)*c1.green+double(m1-m)/(m1-m2)*c2.green;
I.blue=double(m-m2)/(m1-m2)*c1.blue+double(m1-m)/(m1-m2)*c2.blue;
return I;
}

BOOL CTestView::OnEraseBkgnd(CDC* pDC)//设置背景函数
{
// TODO: Add your message handler code here and/or call default
CRect Rect;
pDC->GetClipBox(&Rect);
pDC->FillSolidRect(Rect,RGB(0,0,0));
//return CView::OnEraseBkgnd(pDC);
return true;
}

void CTestView::OnMENUPlay()//动画按钮函数
{
// TODO: Add your command handler code here
Play=Play?FALSE:TRUE;
if (Play)
//设置动画的时间步
SetTimer(1,15,NULL);
else
KillTimer(1);
}

void CTestView::OnTimer(UINT nIDEvent)//动画时间函数
{
// TODO: Add your message handler code here and/or call default
GetMaxX();GetMaxY();
Phi-=6;
Theta-=6;
InitParameter();
ReadPoint();
ReadFace();
SetCoord();
CView::OnTimer(nIDEvent);
}

void CTestView::OnUpdateMENUPlay(CCmdUI* pCmdUI) //动画按钮状态函数
{
// TODO: Add your command update UI handler code here
if(Play)
pCmdUI ->SetCheck(TRUE);
else
pCmdUI ->SetCheck(FALSE);
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include <sstream>
#include<map>
using namespace std;
chuangjian();
mima(int jk);
zidianlujing();
xuanzemoshi(map<string,string> pp,string name);
lianxu(map<string,string> pc,string dd);
dange(map<string,string> pa,string la);
tianjia(string jx);
gongneng();
int main()
{
cout<<endl;
cout<<" 虾味单词搜索引擎 V1.2"<<endl;
cout<<endl;
cout<<" 虾味千层糕荣誉出品"<<endl;
cout<<endl;
cout<<" 本程序受虾味密码引擎保护"<<endl;
cout<<endl;
cout<<" QQ: 381426068"<<endl;
cout<<" 435952144"<<endl;
cout<<endl;
int uh=0;
mima(uh);
return 0;
}
mima(int jk)
{
if(jk==3)
{
cout<<"已连续 3 次输入错误!"<<endl;
cout<<endl;
cout<<"禁止进入程序!"<<endl;
cout<<endl;
cout<<"终止程序!"<<endl;
cout<<endl;
system("pause");
return 0;
}else{
cout<<endl;
cout<<"退出请输入 end"<<endl;
cout<<endl;
cout<<"请输入程序开启密码:"<<endl;
string pp;
cin>>pp;
cout<<"正在验证密码......."<<endl;
if(pp=="1q2w3e")
{
cout<<endl;
cout<<"密码正确!"<<endl;
cout<<endl;
cout<<"进入主程序...."<<endl;
cout<<endl;
cout<<endl;
zidianlujing();
}else{
if(pp=="end")
{
return 0;
}
++jk;
cout<<endl;
cout<<"密码错误!还剩下"<<3-jk<<"次机会"<<endl;
cout<<endl;
cout<<"重试? y or n"<<endl;
string zxcv;
cin>>zxcv;
if(zxcv=="y")
{
system("cls");
mima(jk);
}else{
cout<<"终止程序!"<<endl;
system("pause");
return 0;
}
}
}
return 0;
}
zidianlujing()
{
system("cls");
cout<<endl;
cout<<"-------------------"<<endl;
cout<<"1.打开字典"<<endl;
cout<<"2.生成新字典"<<endl;
cout<<"3.功能介绍"<<endl;
cout<<"4.退出"<<endl;
cout<<"-------------------"<<endl;
cout<<"请选择:"<<endl;
string la;
cin>>la;
if(la=="1"){
cout<<"请输入字典路径(默认为当前程序目录):"<<endl;
string zidian;
cin>>zidian;
ifstream lk(zidian.c_str());
if(!lk)
{
cout<<endl;
cout<<"找不到该文件!"<<endl;
cout<<endl;
cout<<"请重新输入!"<<endl;
cout<<endl;
system("pause");
cout<<endl;
cout<<"-------------------"<<endl;
cout<<"1.生成新字典"<<endl;
cout<<"2.返回菜单"<<endl;
cout<<"3.退出程序"<<endl;
cout<<"-------------------"<<endl;
cout<<"请选择:"<<endl;
string lpl;
cin>>lpl;
if(lpl=="1")
{
lk.close();
lk.clear();
cout<<endl;
chuangjian();
}
if(lpl=="2")
{
lk.close();
lk.clear();
cout<<endl;
zidianlujing();
}
if(lpl=="3")
{
lk.close();
lk.clear();
return 0;
}
}else{
cout<<"已成功打开字典!"<<endl;
cout<<endl;
cout<<"正在读入字典资料......"<<endl;
map<string,string> hello;
string name,ziliao;
while(lk>>name>>ziliao)
{
hello.insert(make_pair(name,ziliao));
}
cout<<"已读入完毕!"<<endl;
lk.close();
lk.clear();
cout<<"已关闭程序流!"<<endl;
cout<<endl;
system("pause");
xuanzemoshi(hello,zidian);
}
}
if(la=="2")
{
chuangjian();
}
if(la=="3")
{
gongneng();
}
if(la=="4")
{
return 0;
}
return 0;
}
xuanzemoshi(map<string,string> pp,string name)
{
system("cls");
cout<<endl;
cout<<"-----------------------"<<endl;
cout<<"(退出请输入任意字母)"<<endl;
cout<<endl;
cout<<"1.单个查找模式"<<endl;
cout<<"2.连续查找模式"<<endl;
cout<<"3.添加单词模式"<<endl;
cout<<"----------------------"<<endl;
cout<<"请选择模式:"<<endl;
int xuanze;
cin>>xuanze;
if(xuanze==1)
{
dange(pp,name);
}
if(xuanze==2)
{
lianxu(pp,name);
}
if(xuanze==3)
{
tianjia(name);
}
return 0;
}
dange(map<string,string> pa,string la)
{
system("cls");
cout<<endl;
cout<<"已成功进入单个查找模式!"<<endl;
cout<<endl;
cout<<"请输入要查找的单词:"<<endl;
string word;
cin>>word;
map<string,string>::const_iterator lq=pa.find(word);//查找
if(lq==pa.end())
{
cout<<endl;
cout<<"没有找到此单词!"<<endl;
cout<<endl;
system("pause");
}
if(lq!=pa.end())
{
cout<<endl;
cout<<"要查找的目标单词: "<<lq->first<<endl;
cout<<endl;
cout<<"单词解释: "<<lq->second<<endl;
cout<<endl;
}
cout<<endl;
cout<<"继续? y or n"<<endl;
cout<<endl;
cout<<"请选择:"<<endl;
string qw;
cin>>qw;
if(qw=="y")
{
dange(pa,la);
}else{
cout<<endl;
cout<<"-------------------"<<endl;
cout<<"1.返回菜单"<<endl;
cout<<"2.重新选择字典文件"<<endl;
cout<<"3.添加单词到字典"<<endl;
cout<<"4.退出程序"<<endl;
cout<<"-------------------"<<endl;
cout<<"请选择:"<<endl;
string ad;
cin>>ad;
cout<<endl;
if(ad=="1"|ad=="2"|ad=="3"|ad=="4")
{
if(ad=="1")
{
xuanzemoshi(pa,la);
}
if(ad=="2")
{
zidianlujing();
}
if(ad=="3")
{
int uj=tianjia(la);
if(uj==-1)
{
return 0;
}
}
if(ad=="4")
{
return 0;
}
}else{
cout<<endl;
cout<<"没有该选项!"<<endl;
cout<<endl;
system("pause");
cout<<"返回菜单!"<<endl;
cout<<endl;
xuanzemoshi(pa,la);
return 0;
}
}
return 0;
}
lianxu(map<string,string> pc,string dd)
{
system("cls");
cout<<endl;
cout<<"已成功进入连续查找模式!"<<endl;
cout<<endl;
cout<<"请输入要查找的单词(用空格隔开并以#结束输入):"<<endl;
string yy;//要查找的
cin>>yy;
map<string,string>::const_iterator uu;//存储结果
while(yy!="#")
{
uu=pc.find(yy);
if(uu!=pc.end()){
cout<<endl;
cout<<"要查找的单词: "<<uu->first<<endl;
cout<<"该单词资料: "<<uu->second<<endl;
cout<<endl;
}
if(uu==pc.end())
{
cout<<endl;
cout<<"没有找到"<<yy<<"这个单词!"<<endl;
cout<<endl;
}
cin>>yy;
}
cout<<endl;
cout<<"已查找完毕!"<<endl;
cout<<endl;
cout<<"继续? y or n"<<endl;
string qw;
cin>>qw;
cout<<endl;
if(qw=="y")
{
lianxu(pc,dd);
}else{
cout<<"-------------------"<<endl;
cout<<"1.返回菜单"<<endl;
cout<<"2.重新选择字典"<<endl;
cout<<"3.添加单词到字典"<<endl;
cout<<"4.退出程序"<<endl;
cout<<"-------------------"<<endl;
cout<<"请选择:"<<endl;
string ad;
cin>>ad;
if(ad=="1"|ad=="2"|ad=="3"|ad=="4")
{
if(ad=="1")
{
xuanzemoshi(pc,dd);
}
if(ad=="2")
{
zidianlujing();
}
if(ad=="3")
{
int uu=tianjia(dd);
if(uu==-1)
{
return 0;
}
}
if(ad=="4")
{
return 0;
}
}else{
cout<<endl;
cout<<"没有该选项!"<<endl;
cout<<endl;
system("pause");
cout<<endl;
cout<<"返回菜单!"<<endl;
cout<<endl;
xuanzemoshi(pc,dd);
return 0;
}
}
return 0;
}
tianjia(string jx)
{
system("cls");
cout<<endl;
cout<<"已成功进入单词添加模式!"<<endl;
cout<<endl;
cout<<"正在展开字典...."<<endl;
ofstream qq(jx.c_str(),ios::out|ios::app|ios::ate);
cout<<"展开成功!"<<endl;
if(!qq)
{
qq.close();
qq.clear();
cout<<"展开失败!"<<endl;
cout<<endl;
cout<<"要创建字典吗? y or n"<<endl;
string oo;
cin>>oo;
if(oo=="y")
{
cout<<"请输入要创建的路径:"<<endl;
string op;
cin>>op;
ofstream qe(op.c_str());
if(!qe)
{
cout<<endl;
cout<<"创建失败!"<<endl;
cout<<"返回菜单!"<<endl;
cout<<endl;
zidianlujing();
}
cout<<"已创建成功!"<<endl;
qe.close();
qe.clear();
cout<<endl;
cout<<"请重新输入路径!"<<endl;
cout<<endl;
tianjia(jx);
}
if(oo=="n")
{
qq.close();
qq.clear();
cout<<"1.重新输入要添加的字典的路径"<<endl;
cout<<"2.返回菜单!"<<endl;
cout<<endl;
cout<<"请选择:"<<endl;
string lp;
cin>>lp;
if(lp=="1")
{
tianjia(jx);
}
if(lp=="2")
{
cout<<endl;
cout<<"返回程序开端!"<<endl;
cout<<endl;
main();
}
cout<<endl;
cout<<"返回输入字典路径"<<endl;
cout<<endl;
zidianlujing();
}
cout<<endl;
system("pause");
cout<<endl;
cout<<"返回程序开端!"<<endl;
cout<<endl;
zidianlujing();
}
string word,ziliao;
cout<<endl;
cout<<"字典打开成功!"<<endl;
cout<<endl;
cout<<"允许开始添加!"<<endl;
cout<<endl;
cout<<endl;
cout<<"注意:绝对不可以在单词或解释内使用空格和换行!"<<endl;
cout<<endl;
system("pause");
cout<<endl;
cout<<"请输入要创建的单词:"<<endl;
cin>>word;
cout<<"请输入该单词解释:"<<endl;
cin>>ziliao;
cout<<"正在处理中...."<<endl;
qq<<"\n"<<word<<" "<<ziliao;
cout<<"已添加成功!"<<endl;
cout<<endl;
cout<<"继续添加? y or n"<<endl;
string ty;
cin>>ty;
if(ty=="y")
{
tianjia(jx);
}
if(ty=="n")
{
cout<<"退出?否将返回程序开端 y or n"<<endl;
string kl;
cin>>kl;
if(kl=="y")
{
qq.close();
qq.clear();
return -1;
}
cout<<endl;
system("pause");
cout<<endl;
cout<<"返回程序开端!"<<endl;
qq.close();
qq.clear();
cout<<"已成功关闭数据流!"<<endl;
cout<<endl;
cout<<endl;
zidianlujing();
}
qq.close();
qq.clear();
return 0;
}
chuangjian()
{
system("cls");
cout<<endl;
cout<<"请输入要创建的路径(默认为当前程序目录):"<<endl;
string op;
cin>>op;
ofstream qe(op.c_str());
if(!qe)
{
cout<<endl;
cout<<"创建失败!"<<endl;
cout<<endl;
system("pause");
cout<<endl;
cout<<"返回菜单!"<<endl;
cout<<endl;
zidianlujing();
}
cout<<"文件创建成功!"<<endl;
cout<<endl;
cout<<"正在生成字典原始框架....."<<endl;
cout<<"已生成成功!"<<endl;
cout<<endl;
cout<<"正在为字典输入基础资料....."<<endl;
qe<<"hi 你好"<<endl;
qe<<"want 想"<<endl;
qe<<"big 大"<<endl;
qe<<"small 小"<<endl;
qe<<"count 计算"<<endl;
qe<<"find 找到"<<endl;
qe<<"world 地球"<<endl;
qe<<"green 绿";
cout<<"已输入完毕!"<<endl;
cout<<endl;
cout<<"字典生成成功!"<<endl;
cout<<endl;
system("pause");
cout<<endl;
qe.close();
qe.clear();
cout<<"关闭该数据流!"<<endl;
cout<<endl;
cout<<"返回菜单!"<<endl;
cout<<endl;
zidianlujing();
return 0;
}
gongneng()
{
system("cls");
cout<<endl;
cout<<"!!!功能介绍!!!"<<endl;
cout<<endl;
cout<<"本程序由虾味千层糕制作"<<endl;
cout<<endl;
cout<<"程序名: 单词搜索引擎"<<endl;
cout<<endl;
cout<<"以字典为基础实现搜索功能,"<<endl;
cout<<endl;
cout<<"以输入的字符为索引对字典所有的资料进行搜索,"<<endl;
cout<<endl;
cout<<"对错误进行了综合处理也是此程序一大特色"<<endl;
cout<<endl;
cout<<"此处的字典应用了文本格式"<<endl;
cout<<endl;
cout<<"应用了两种截然不同的选择方式,"<<endl;
cout<<endl;
cout<<"包括用数字为索引和用单词名为索引"<<endl;
cout<<endl;
cout<<"搜索引擎拥有搜索速度高,精确度高的特点"<<endl;
cout<<endl;
cout<<"本程序自带了字典生成功能"<<endl;
cout<<endl;
cout<<"可是只能生成一些基础资料"<<endl;
cout<<endl;
cout<<"仅是用来展示字典需要的编写格式"<<endl;
cout<<endl;
cout<<"建议生成的文件名: 文件名.txt"<<endl;
cout<<endl;
cout<<"这样的格式可方便查看字典的内容"<<endl;
cout<<endl;
cout<<"这样可知道搜索引擎搜索出来的结果是否准确"<<endl;
cout<<endl;
cout<<"本程序暂不支持中文输入!"<<endl;
cout<<endl;
cout<<"介绍完毕"<<endl;
cout<<endl;
system("pause");
system("cls");
cout<<endl;
cout<<"返回菜单!"<<endl;
cout<<endl;
cout<<endl;
system("pause");
system("cls");
cout<<endl;
zidianlujing();
return 0;
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

求一个C++的程序 大约在1000行左右的 要求有注释的 题目也告诉我~

你好!

具体什么要求,要实现的功能,私信联系

#include //引用文件
using namespace std; //使用命名空间
void Bubblesort(int b[],int n);//申明自定义函数
void main()
{
const int N=10; //const关键字定义常亮
int a[N]={300,46,78,109,21,70,26,290,166,8};//定义数组并初始化

Bubblesort(a,N);//引用自定义函数
cout<<"排序后的数据为:"; //输出提示信息
for(int m=0;m<=9;m++) //定义循环,m初值为0,每次循环加1,m值小于等于9结束
{
cout<<a[m]<<","; //输出数组元素
}
cout<<endl; //提示信息换行
}
void Bubblesort(int b[],int n) //定义自定义函数,将数组和数组大小传递进去
{
int t; //定义整形变量
for(int i=1;i<n;i++) //定义循环
{
for(int k=0;k<n-i;k++)
{
if(b[k]>b[k+1]) //如果前一个元素大于后一个元素
{
t=b[k]; //将b[k]值赋给中间变量t
b[k]=b[k+1];//将后一个元素赋值给前一个元素
b[k+1]=t;//将中间变量t值赋给b[k+1]
}//三部操作实质是实现前后两个元素交换
}
}
}//此自定义的功能是实现冒泡排序

相关要点总结:
(编辑:本站网友)
相关推荐
关于我们 | 客户服务 | 服务条款 | 联系我们 | 免责声明 | 网站地图
@ 百韵网