| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 573 人关注过本帖
标题:有个c程序编译时出现点错误需要大家帮忙,谢谢!
只看楼主 加入收藏
yhxc12345
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
有个c程序编译时出现点错误需要大家帮忙,谢谢!
#include <windows.h>
#include <math.h>
#include <stdio.h>

#define WINDOW_WIDTH  400
#define WINDOW_HEIGHT 400
char* g_szApplicationName="圆覆盖矩形(矩形覆盖)";
char* g_szWindowClassName="LinrenWindowClass";

struct mypoint{
    double x,y;
}myp[200];

struct myrect{
    double x,y;
    double x2,y2;
    double x3,y3;
}myr[200];

/**只用修改这里******************************/
#define PARM_R 24.1
#define PARM_L 233.5
#define PARM_D 197.4
/******************************只用修改这里**/

int n,n2;
double r=PARM_R,l=PARM_L,d=PARM_D;
double at,sq2,x,y;
double a,e;
#undef PARM_R
#undef PARM_L
#undef PARM_D
char str[100];

void fun(){
    int cl,cd,i,j;

    x=(double(WINDOW_WIDTH)-l)/2.0;
    y=(double(WINDOW_HEIGHT)-d)/2.0;
   
    sq2=sqrt(2.0);
    a=sq2*r;

    at=(a-r)/sq2;

    cl=(int)(l/a);
    cd=(int)(d/a);
    n=0;
    for(i=0;i<cl;i++){
        for(j=0;j<cd;j++){
            myp[n].x=x+a*i;
            myp[n].y=y+a*j;
            n++;
        }
    }
    e=(int)(r+r+1e-15);

    n2=0;
    double t1,t2,t3,t4;
    int kd;
    t1=l-cl*a;
    t2=sqrt((r+r)*(r+r)-t1*t1);
    t3=d-cd*a;
    t4=sqrt((r+r)*(r+r)-t3*t3);

    if(t1<t4){
        kd=(int)(l/t4);
        myr[n2].x=x+kd*t4;
        myr[n2].y=y+cd*a;
        myr[n2].x2=x+(kd+1)*t4;
        myr[n2].y2=y+d;
        myr[n2].x3=myr[n2].x-(r-t4/2.0);
        myr[n2].y3=myr[n2].y-(r-t3/2.0);
        n2++;
    }else if(t3<t2){
        kd=(int)(d/t2);
        myr[n2].x=x+cl*a;
        myr[n2].y=y+kd*t2;
        myr[n2].x2=x+l;
        myr[n2].y2=y+(kd+1)*t2;
        myr[n2].x3=myr[n2].x-(r-t1/2.0);
        myr[n2].y3=myr[n2].y-(r-t2/2.0);
        n2++;
    }else{
        kd=(int)(l/t4);
        myr[n2].x=x+kd*t4;
        myr[n2].y=y+cd*a;
        myr[n2].x2=x+(kd+1)*t4;
        myr[n2].y2=y+d;
        myr[n2].x3=myr[n2].x-(r-t4/2.0);
        myr[n2].y3=myr[n2].y-(r-t3/2.0);
        n2++;
        kd=(int)(d/t2);
        myr[n2].x=x+cl*a;
        myr[n2].y=y+kd*t2;
        myr[n2].x2=x+l;
        myr[n2].y2=y+(kd+1)*t2;
        myr[n2].x3=myr[n2].x-(r-t1/2.0);
        myr[n2].y3=myr[n2].y-(r-t2/2.0);
        n2++;
    }

    kd=(int)(d/t2);
    for(i=0;i<kd;i++){
        myr[n2].x=x+cl*a;
        myr[n2].y=y+i*t2;
        myr[n2].x2=x+l;
        myr[n2].y2=y+(i+1)*t2;
        myr[n2].x3=myr[n2].x-(r-t1/2.0);
        myr[n2].y3=myr[n2].y-(r-t2/2.0);
        n2++;
    }
   
    kd=(int)(l/t4);
    for(i=0;i<kd;i++){
        myr[n2].x=x+i*t4;
        myr[n2].y=y+cd*a;
        myr[n2].x2=x+(i+1)*t4;
        myr[n2].y2=y+d;
        myr[n2].x3=myr[n2].x-(r-t4/2.0);
        myr[n2].y3=myr[n2].y-(r-t3/2.0);
        n2++;
    }
    sprintf(str,"总数:%d",n+n2);
}

LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
    static HBRUSH hbrush=(HBRUSH)GetStockObject(NULL_BRUSH);
    static HPEN newpen=CreatePen(PS_SOLID,1,RGB(255,0,0));
    static HPEN oldpen=NULL;
    switch(msg){
    case WM_CREATE:
        {
            PAINTSTRUCT ps;
            int i;
            BeginPaint(hwnd,&ps);
            SelectObject(ps.hdc,hbrush);
            for(i=0;i<n;i++){
                Ellipse(ps.hdc,(int)(myp[i].x-at+0.5),(int)(myp[i].y-at+0.5),
                    (int)(myp[i].x-at+e+0.5),(int)(myp[i].y-at+e+0.5));
                Rectangle(ps.hdc,(int)(myp[i].x+0.5),(int)(myp[i].y+0.5),
                    (int)(myp[i].x+a+0.5),(int)(myp[i].y+a+0.5));
            }
            for(i=0;i<n2;i++){
                Ellipse(ps.hdc,(int)(myr[i].x3+0.5),(int)(myr[i].y3+0.5),
                    (int)(myr[i].x3+e+0.5),(int)(myr[i].y3+e+0.5));
                Rectangle(ps.hdc,(int)(myr[i].x+0.5),(int)(myr[i].y+0.5),
                    (int)(myr[i].x2+0.5),(int)(myr[i].y2+0.5));
            }
            oldpen=(HPEN)SelectObject(ps.hdc,newpen);
            Rectangle(ps.hdc,(int)(x+0.5),(int)(y+0.5),(int)(x+l+0.5),(int)(y+d+0.5));
            SelectObject(ps.hdc,oldpen);
            TextOut(ps.hdc,20,20,str,strlen(str));
            EndPaint(hwnd,&ps);
        }
        break;

    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            int i;
            BeginPaint(hwnd,&ps);
            SelectObject(ps.hdc,hbrush);
            for(i=0;i<n;i++){
                Ellipse(ps.hdc,(int)(myp[i].x-at+0.5),(int)(myp[i].y-at+0.5),
                    (int)(myp[i].x-at+e+0.5),(int)(myp[i].y-at+e+0.5));
                Rectangle(ps.hdc,(int)(myp[i].x+0.5),(int)(myp[i].y+0.5),
                    (int)(myp[i].x+a+0.5),(int)(myp[i].y+a+0.5));
            }
            for(i=0;i<n2;i++){
                Ellipse(ps.hdc,(int)(myr[i].x3+0.5),(int)(myr[i].y3+0.5),
                    (int)(myr[i].x3+e+0.5),(int)(myr[i].y3+e+0.5));
                Rectangle(ps.hdc,(int)(myr[i].x+0.5),(int)(myr[i].y+0.5),
                    (int)(myr[i].x2+0.5),(int)(myr[i].y2+0.5));
            }
            oldpen=(HPEN)SelectObject(ps.hdc,newpen);
            Rectangle(ps.hdc,(int)(x+0.5),(int)(y+0.5),(int)(x+l+0.5),(int)(y+d+0.5));
            SelectObject(ps.hdc,oldpen);
            TextOut(ps.hdc,20,20,str,strlen(str));
            EndPaint(hwnd,&ps);
        }
        break;

    case WM_DESTROY:
        DeleteObject(hbrush);DeleteObject(newpen);DeleteObject(oldpen);
        PostQuitMessage(0);break;
    }
    return DefWindowProc(hwnd,msg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                   LPSTR szCmdLine,int iCmdShow){
    HWND hWnd;
    WNDCLASSEX winclass;
    winclass.cbSize        = sizeof(WNDCLASSEX);
    winclass.style         = CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc   = WindowProc;
    winclass.cbClsExtra    = 0;
    winclass.cbWndExtra    = 0;
    winclass.hInstance     = hInstance;
    winclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
    winclass.lpszMenuName  = NULL;
    winclass.lpszClassName = g_szWindowClassName;
    winclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if (!RegisterClassEx(&winclass)){
        MessageBox(NULL,"RegisterClassEx Error!","error",0);return 0;
    }
   
    hWnd=CreateWindowEx(NULL,
        g_szWindowClassName,
        g_szApplicationName,
        WS_OVERLAPPEDWINDOW,
        GetSystemMetrics(SM_CXSCREEN)/2-WINDOW_WIDTH/2,
        GetSystemMetrics(SM_CYSCREEN)/2-WINDOW_HEIGHT/2,
        WINDOW_WIDTH,
        WINDOW_HEIGHT,
        NULL,NULL,hInstance,NULL);

    if(!hWnd){
        MessageBox(NULL,"CreateWindowEx Error!","error",0);return 0;
    }

    fun();
    ShowWindow(hWnd, iCmdShow);UpdateWindow(hWnd);
   
    MSG msg;
    while(GetMessage(&msg,NULL,0,0)){
        TranslateMessage(&msg);DispatchMessage(&msg);
    }
    return msg.wParam;
}

搜索更多相关主题的帖子: c程序 include double 
2011-06-25 17:17
wuzhanghao88
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:45
专家分:146
注 册:2009-10-25
收藏
得分:4 
你至少加上要实现什么功能嘛!和一些必要 语句的解释吧!这么长,见了就没有喟口了
2011-06-25 20:34
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:4 
我不会这个,顶一下

—>〉Sun〈<—
2011-06-26 00:07
weiwei555
Rank: 5Rank: 5
来 自:中国
等 级:职业侠客
帖 子:179
专家分:323
注 册:2011-3-4
收藏
得分:4 
我也不知道这个程序是干什么的…… 楼主说下啊
2011-06-26 12:01
liujigen
Rank: 2
等 级:论坛游民
帖 子:32
专家分:63
注 册:2010-8-24
收藏
得分:4 
编译时出错,那是语法的问题。
2011-06-27 15:12
whqjjqqpp
Rank: 2
等 级:论坛游民
帖 子:5
专家分:14
注 册:2007-7-5
收藏
得分:4 
最好将错误信息贴出来
2011-06-27 15:32
快速回复:有个c程序编译时出现点错误需要大家帮忙,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039610 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved