직사각형 모양을 그리기로되어있는 지정이 있습니다. 평면에서 두 점을 지정하는 방법은 두 개의 수평선과 두 개의 수직선을 그립니다. Rectangle 클래스에서 Point 클래스를 사용해야합니다.직사각형 그리기 및 인쇄 방법
나는 할당 지침 .h
(Point 클래스), .cpp
(Point 클래스), .h
(Rectangle 클래스), .cpp
(Rectange 클래스) 메인 있습니다. 나는 본부에서 너무 많이하지 않았지만해야 할 일을 명기했다. 그는 y
또는 문자 y
으로 구성된 윤곽선으로 그려진 사각형을 원합니다.
나는 모든이, .cpp
(Point 클래스), .h
(Rectangle 클래스)를 .h
(Point 클래스) 좋은 생각,하지만 난 사각형 .cpp
의 무승부 방법 및 인쇄 방법에 문제가 있어요, 강사는 말했다 그리기 메소드 또는 그와 비슷한 것에서 원점에 대한 임시 변수를 사용하십시오.
.cpp
직사각형 파일의 인쇄 방법에 대해 잘 모르는 경우 도움이됩니다. 컴파일하려고했지만 모든 지옥 느슨하게 부러, 어떤 설명/예를 많이 도움이 될 것입니다.
Point.h
//the Point.cpp file
#include "Point.h"
#include<iostream>
using namespace std;
//Getters
double Point::getX()const {return x;}
double Point::getY()const {return y;}
//setters
void Point::setX(double x) {this->x=x;}
void Point::setY(double y) {this->y=y;}
//Public functions
void Point::print()const{
cout << "(" << x << "," << y << ")" << endl;
}
//overloading '+' operator
const Point Point::operator+(const Point & rt) const{
return Point(x + rt.x, y + rt.y);
}
const Point Point::operator-(const Point & rt) const{
return Point(x - rt.x, y - rt.y);
}
Point Point::operator+=(Point & rt){
return Point(x+=rt.x, y+=rt.y);
}
int Point::operator ==(Point & rt){
return (x == rt.x && y==rt.y);
}
int Point::operator <(Point & rt){
return (x < rt.x && y<rt.y);
}
int Point::operator >(Point & rt){
return (x > rt.x && y>rt.y);
}
int Point::operator <=(Point & rt){
return (x <= rt.x && y<=rt.y);
}
int Point::operator >=(Point & rt){
return (x >= rt.x && y>=rt.y);
}
//;
//;
//END POINT.CPP
사각형 h 파일
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <iostream.h>
#include "Point.h"
class Rectangle {
private:
Point origin;
Point corner;
public:
Rectangle (const Point & or, const Point & cr):origin(or),corner(cr) {}
// void move(int dx, int dy);
void draw();
void print()const;
};
#endif /* RECTANGLE_H */
사각형이 파일을 .CPP 통화 당
//Point.h
#include <iostream.h>
/* The Point class Header file (Point.h) */
#ifndef POINT_H
#define POINT_H
class Point {
private:
double x,y;//x and y are private variables
public:
Point(int x, int y):x(x),y(y){}//use initialization list
double getX() const; //Getters
double getY() const;
void setX(double x); //Setters
void setY(double y); //Setters
void print()const;
//Overload '+' operator
const Point operator +(const Point & rt)const;
//Overload '-' operator
const Point operator - (const Point &rt)const;
Point operator +=(Point & rt);
Point operator -=(Point & rt);
//Overload '==' operator comparing two points
int operator ==(Point &rt);
int operator <(Point &rt);
int operator >(Point &rt);
int operator <=(Point &rt);
int operator >=(Point &rt);
};
/* POINT_H */
#endif
포인트
/* The Rectangle.cpp file) */
#include "Point.h"
#include "Rectangle.h"
#include <iostream.h>
#include <string>
#include <conio.h>
using namespace std;
// Public Functions
void Rectangle::print() const
{
cout<<"(" <<origin <<"," <<corner << ")" <<endl;
}
void Rectangle::draw()
{
Point temp=origin; //store origin in temp object
while (temp.getX() < corner.getX()) {
putch('y');
}
/* int temp=origin;
for (int x = temp.getX(); x < center.getX(); x++) {
Point pt1 (x, temp.getY());
Point pt2 (x, center.getY());
pt1(6,4);
// move to p1 // not sure how to do this
putCH ('y');
pt2(30,15);
// move to p2 //not sure how to do this
putCH ('y');
}
for (int y = lowerRight.getY(); y < upperLeft.getY(); y++) {
Point pt1 (origin.getX(),y);
Point pt2 (corner.getX(),y);
pt1(6,4);
//move to p1 //not sure how to do this
putCH('y');
pt2(30,15);
// move to p2 //not sure how to do this
putCH ('y');
}*/
//return 0;
}//;
,
내가 한 C++ 특정 문제를 볼 수
#include "Point.h"
#include "Rectangle.h"
#include <iostream>
#include <conio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//char y;
Point p1(6, 4), p2(30, 15);
//cout<<"\n the origin of Rectangle is at: ";
//p1.print();
//cout<<"\n the opposite corner of rect is at:";
//p2.print();
Rectangle r1(p1,p2);
r1.draw();
clrscr();
gotoxy(1,20);
//r1.print();
getch();
return 0;
} //;
//END OF MAIN
두 가지 도움말. 1. 컴파일러에서 오류 메시지의 첫 번째 줄을 가져 와서 수정하십시오. 2. 전체를 많이 입력하지 말고 최선을 기원합니다. 몇 줄에 묶어서 컴파일하면됩니다. 자신감이 있으면 합병증 사이에 더 많은 줄을 입력 할 수 있습니다. –