private: };
enum _QUAD_ { para = 0, rect, sqr, diam, trap }; typedef pair
Diam:
#pragma once #include
Diamond(int d1 = 4, int d2 = 8, string nm = \) :Para(d1,d2,nm){}; ~Diamond(){};
void draw() const{ Para::draw(); };
double area() const{ return (double)width*height/2; }; string what() const{ return name; }; int& Width1(){ return d1; }; int& Width2(){ return d2; };
friend ostream&operator<<(ostream& os, const Diamond &c2); Diamond& operator= (const Diamond& di) { } int d1, d2;
name = di.name; d1 = di.d2; d2 = di.d2; return *this;
protected:
Experiment:
// experiment.h : PROJECT_NAME 应用程序的主头文件 //
#pragma once
#ifndef __AFXWIN_H__
#include \
// CexperimentApp:
// 有关此类的实现,请参阅 experiment.cpp //
class CexperimentApp : public CWinApp { public: // 重写 public: // 实现 };
extern CexperimentApp theApp; DECLARE_MESSAGE_MAP() virtual BOOL InitInstance(); CexperimentApp();
// 主符号
#error \在包含此文件之前包含“stdafx.h”以生成 PCH 文件\#endif
Experimentdlg.h:
// experimentDlg.h : 头文件 //
#pragma once #include \
// CexperimentDlg 对话框
class CexperimentDlg : public CDialogEx {
// 构造 public:
// 对话框数据 // 实现 protected: public: };
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); QUADPTR createAquad(void); bool lastDone; private:
// 生成的消息映射函数 virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() Canvas *pCanvas;
afx_msg void OnBnClickedOk(); double answer; CString result;
afx_msg void OnClickedButtonNext(); afx_msg void OnClickedButtonStop(); afx_msg void OnClickedButtonSubmit(); HICON m_hIcon; protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 enum { IDD = IDD_EXPERIMENT_DIALOG }; CexperimentDlg(CWnd* pParent = NULL);
// 标准构造函数
public:
List.h:
#pragma once
#include \
#include
//typedef void(*ACCESSFUN)(QUADPTR); //定义遍历时节点处理函数类型 class List { protected: public:
List() :head(NULL), tail(NULL){ len = 0; } //平凡构造函数 List(List const& l) {
head = tail = NULL; Node *p = l.head; while (p != NULL) { } len = 0;
this->push_back(p->data); p = p->next;
size_t len; //链表中节点的数目,即链表的长度 //typedef Node* _range; struct Node {
QUADPTR data; Node *next;
Node(QUADPTR d) :data(d){}
} *head, *tail; //链表的头尾指针
} //复制构造函数 ~List() { };
Node *Tail(){ return tail; }
//size_t size(){ return len; }; //获取链表的长度 size_t List::size()
Node *p = head, *q; while (p != NULL) { }
q = p; p = p->next; delete q;
{ }
void push_back(const QUADPTR quad) //尾部添加 { }
int pop_back() { }
void traverse(void(*f)(const QUADPTR&)) {
Node *p = head; int i = 1;
while (p != NULL) {
cout << \第\ << i++ << \个\ << endl; f(p->data); if(len == 0)
return len; Node *c = head; if (c == tail){ delete c; head = tail = NULL; } else{
while (c->next != tail) c++; delete tail; tail = c; tail->next = NULL; } len--; return len;
Node *p = new Node(quad); p->next = NULL;
if (tail == NULL) head = tail = p; else { tail->next = p; tail = p; } len++;
Node *p = head; size_t i = 0; while (p != NULL) { } return i;
p = p->next; ++i;