24小时热门版块排行榜    

查看: 784  |  回复: 6
当前主题已经存档。

zhanglei22

银虫 (小有名气)

[交流] 【求助】好心人帮我看看这个c++! 谢谢了

这个程序在vc++ 6.0 怎么运行不了啊 ? 求助!问题在哪里这么改啊 ?谢谢了
#include
#include

struct polar
{
        double distance;
        double angle;
};

struct rect
{
        double x;
        double y;
};

polar rect_to_polar(rect xypos);
void show_polar(polar dapos);

int main()
{
        rect rplace;
        polar pplace;

        cout<<"Enter the x and y values:";
        while(cin>>rplace.x>>rplace.y)
    {
                pplace=rect_to_polar(rplace);
                show_polar(pplace);
                cout<<"Next two numbers(q to quit):";
        }

        cout<<"Done.\n";
        return 0;
}

polar rect_to_polar(rent xypos)
{
        polar answer;

        answer.distance=sqrt(xypos.x*xypos.x+xypos.y*xypos.y);
        answer.angle=atan2(xypos.y,xypos.x);
        return answer;
}

void show_polar(pelar dapos)
{
        const double Rad_to_deg=57.29577951;

        cout<<"distance="<< dapos.distance;
        cout<<", angle="<         cout<<" degrees\n";
}

[ Last edited by nono2009 on 2009-9-30 at 00:00 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yeyunxiao

铁杆木虫 (小有名气)

★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
wangen994(金币+3,VIP+0):辛苦了,谢谢你对程序软件版的支持 9-23 12:13
#include
#include

struct polar
{
        double distance;
        double angle;
};

struct rect
{
        double x;
        double y;
};

polar rect_to_polar(rect xypos);
void show_polar(polar dapos);

int main()
{
        rect rplace;
        polar pplace;

        cout<<"Enter the x and y values:";
        while(cin>>rplace.x>>rplace.y)
    {
                pplace=rect_to_polar(rplace);
                show_polar(pplace);
                cout<<"Next two numbers(q to quit):";
        }

        cout<<"Done.\n";
        return 0;
}

polar rect_to_polar(rect xypos)
{
        polar answer;

        answer.distance=sqrt(xypos.x*xypos.x+xypos.y*xypos.y);
        answer.angle=atan2(xypos.y,xypos.x);
        return answer;
}

void show_polar(polar dapos)
{
        const double Rad_to_deg=57.29577951;

        cout<<"distance="<< dapos.distance;
        cout<<", angle="<         cout<<" degrees\n";
}

嘿嘿,是编译错误吧,

是你的笔误啊,帮你用红色标出来了

编程的时候一定要细心哦!
2楼2009-09-23 10:36:16
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhanglei22

银虫 (小有名气)

谢谢

我是论坛新人 且 新手学vc!

  感谢好心人帮忙!

  我在看 c++ primer plus 这本书, 用vc++ 6.0运行, 他里面得 这个语句
    using namespace std:   必须删了 才能在vc++ 6.0 运行。我有点一知半解。

  
  还有我有c得 基础 ,前面的基础 一扫而过,重点想看后面 对象啊  类什么的,
这种方法可行吧?
3楼2009-09-23 16:45:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hxz

木虫 (正式写手)


小木虫(金币+0.5):给个红包,谢谢回帖交流
没写拷贝复制函数 结构赋值不能用=
lz的纯c风格 囧
4楼2009-09-23 16:51:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hxz

木虫 (正式写手)

引用回帖:
Originally posted by zhanglei22 at 2009-9-23 16:45:
我是论坛新人 且 新手学vc!

  感谢好心人帮忙!

  我在看 c++ primer plus 这本书, 用vc++ 6.0运行, 他里面得 这个语句
    using namespace std:   必须删了 才能在vc++ 6.0 运行。我有点一知半解。

...

因为c++ primer plus用的是iso c++标准, vc6不完全兼容
学c++最好不要用vc6
5楼2009-09-23 16:53:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
6楼2009-09-23 23:55:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

green84

金虫 (正式写手)

努力学习~

帮你写了个类

★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
nono2009(金币+3,VIP+0):谢谢热心帮助。欢迎常来交流。 9-30 00:02
//Crect.h
#pragma once

class Crect
{
public:
        Crect(void);
        ~Crect(void);
        bool SetVal(void);
        double GetX(void) const;
        double GetY(void) const;
private:
        double m_x;
        double m_y;
};
//Crect.cpp
#include
using namespace std;

#include "Crect.h"

Crect::Crect(void):m_x(0.0),m_y(0.0)
{
}

Crect::~Crect(void)
{
}

bool Crect::SetVal()
{
        cout << "Please input the x value: ";
        cin >> m_x;
        cout << "Please input the y value: ";
        cin >> m_y;
        return true;
}

double Crect::GetX() const
{
        return m_x;
}

double Crect::GetY() const
{
        return m_y;
}
//polar.h
#pragma once
#include "Crect.h"

class CPolar
{
public:
        CPolar(void);
        ~CPolar(void);
        void SetValFromRect(const Crect& xypos);
        void Show(void);
private:
        double m_distance;
        double m_angle;
};
//Polar.cpp
#include
#include
using namespace std;

#include "Polar.h"

CPolar::CPolar(void):m_distance(0.0),m_angle(0.0)
{
}

CPolar::~CPolar(void)
{
}

void CPolar::SetValFromRect(const Crect& xypos)
{
        m_distance = sqrt(xypos.GetX() * xypos.GetX() + xypos.GetY() * xypos.GetY());
        m_angle = atan2(xypos.GetY(),xypos.GetX());
}

void CPolar::Show()
{
        const double RadToDeg = 57.29577951;
        cout << "distance = " << m_distance
                 << " angle = " << m_angle * RadToDeg
                 << " degress" << endl;
}
//main.cpp
#include
using namespace std;
#include "Polar.h"

int main()
{
        Crect rect1;
        CPolar polar1;
        while(rect1.SetVal())
        {
                polar1.SetValFromRect(rect1);
                polar1.Show();
        }

        system("Pause");
        return 0;
}

//虽然比你写的复杂点,但是进行了类封装,类的扩展性更好.
//^_^
//随便写写,请大家指教哈
------------------------------------------ The group of Organic Synthesis:31626069.Welcome everybody to join us!
7楼2009-09-29 23:23:22
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zhanglei22 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[教师之家] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +3 ero8OE6tv9cu 2026-09-02 7/350 2026-09-03 13:20 by T0rGB46095mJ
[考研] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +3 ero8OE6tv9cu 2026-09-02 8/400 2026-09-03 13:20 by T0rGB46095mJ
[基金申请] 国社科又开始会评了,不知道这次命运如何 +10 雨打竹帘 2026-08-30 14/700 2026-09-03 13:17 by qsd10086
[教师之家] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 YLHlRHNwYkce 2026-09-02 8/400 2026-09-03 12:03 by T0rGB46095mJ
[公派出国] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 ero8OE6tv9cu 2026-09-02 4/200 2026-09-03 03:14 by rM1TE0WVDIIY
[博后之家] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 ero8OE6tv9cu 2026-09-02 6/300 2026-09-02 23:59 by rM1TE0WVDIIY
[基金申请] 科研人应该花精力去思考如何解决问题,而不是去凝练问题 +7 瞬息宇宙 2026-09-01 14/700 2026-09-02 17:33 by ma0526
[基金申请] 要骂人了,新模版改版就是要淡化问题凝练这种虚的东西,结果有个评委还在说凝练得不够 +9 瞬息宇宙 2026-08-31 17/850 2026-09-02 14:04 by anjeeshine
[基金申请] 基金系统什么内容也没有 30+4 winsaint 2026-08-27 10/500 2026-09-02 11:35 by 大不刘6
[基金申请] 学科评审组评审是指会评吗? +5 瞬息宇宙 2026-08-31 5/250 2026-09-02 10:13 by 雨冰共舞
[基金申请] 面上函评意见出来了,像什么等级? 20+4 Tsingking1 2026-08-27 17/850 2026-09-01 19:51 by 超级无敌华子
[论文投稿] 小白求助 投论文要求的highlights应该如何写 5+3 l1963982152 2026-08-29 4/200 2026-09-01 09:04 by 北京莱茵编辑
[基金申请] 面上意见出来了 +12 黄鸟于飞Chao 2026-08-29 23/1150 2026-08-31 18:57 by 黄鸟于飞Chao
[基金申请] 能否申诉? +7 echo8914667 2026-08-30 8/400 2026-08-31 17:00 by yihongxu
[基金申请] 中青基了要发朋友圈吗? +7 349506619 2026-08-28 7/350 2026-08-31 13:39 by 冼亮淀粉酶
[基金申请] 29号明天会评吗 +4 笨笨唐 2026-08-28 4/200 2026-08-31 09:30 by huixian257
[基金申请] 为什么到现在没收到通知? +5 tannykie 2026-08-29 5/250 2026-08-30 21:05 by purplejack
[考博] 找导师 +6 yuanjiabao 2026-08-29 7/350 2026-08-30 14:40 by 生科新手
[基金申请] 我就是申请一个面上项目而已,这评审意见是按照杰青的条件评的吧? +6 gouxfjh 2026-08-28 11/550 2026-08-30 07:57 by gouxfjh
[基金申请] 国自然评审意见 +13 wangmingqi 2026-08-28 19/950 2026-08-29 10:22 by Poppy1104
信息提示
请填处理意见