标题:初学c++,这个移动的部分错在哪里呢?
取消只看楼主
遗情处有诗章
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2017-3-10
结帖率:75%
已结贴  问题点数:20 回复次数:0 
初学c++,这个移动的部分错在哪里呢?
程序代码:
// ConsoleApplication26.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<cstdlib>
using namespace std;
class myrect
{
public:
    double getArea()  //声明面积
    {
        return height*width;
    }
    int getgirth()   //声明周长
    {
        return height * 2 + width * 2;
    }
    myrect(int x, int yl, int h, int w)
    {
        this->x = x;
        y = yl;
        height = h;
        width = w;

    }

    void inflate(int n)//放大倍数
    {
        height *= n;
        width *= n;
    }

    void reduce(int p)//缩小倍数
    {
        height = height / p;
        width = width / p;
    }

    void move(int xm, int ym)//移动
    {
        x += xm;
        y += ym;
    }

private:  //变量
    int x, y;
    int height, width;
};
int main()
{
    int x, y;
    myrect rect1(100, 100, 20, 50);
    cout << rect1.getArea() << endl; //输出面积
    cout << rect1.getgirth() << endl;//输出周长
    rect1.inflate(3);//放大3倍
    cout << "increase" << 3 << ":" << rect1.getArea() << endl;
    rect1.reduce(2);//缩小2倍
    cout << "reduce" << 2 << ":" << rect1.getArea() << endl;
    rect1.move(30, 40);//x,y分别加的坐标
    cout << "x,y" <<x<<y << endl;
    system("pause");
    return 0;
}



void move(int xm, int ym)//移动
    {
        x += xm;
        y += ym;
    }


rect1.move(30, 40);//x,y分别加的坐标
    cout << "x,y" <<x<<y << endl;

这里有问题,但是不知道怎么改?
搜索更多相关主题的帖子: 移动 int void move cout 
2017-10-15 11:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-481419-1-1.html




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

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