Created
August 21, 2012 01:03
-
-
Save raarce/3410161 to your computer and use it in GitHub Desktop.
Ejemplo para practicar uso de Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OJO: Este archivo contiene código que debe ser separado | |
// en los archivos: Rectangle.cpp, Rectangle.h, RectangleClient.cpp, | |
// y Makefile | |
//------ Rectangle.h file begins --------------------- | |
#include <iostream> | |
using namespace std; | |
#ifndef RECT_H | |
#define RECT_H | |
class Rectangle { | |
private: | |
int x; | |
int y; | |
int width; | |
int height; | |
public: | |
// constructors | |
Rectangle(): x(0), y(0), width(0), height(0) {} | |
Rectangle(int tX, int tY, int w, int h): | |
x(tX), y(tY), width(w), height(h) {} | |
// mutators | |
void setX(int tX) {x = tX;} | |
void setY(int tY) {y = tY;} | |
// accessors | |
int getX() const {return x;} | |
int getY() const {return y;} | |
int computeArea() const; | |
void addToX(int); | |
}; | |
#endif | |
//------ Rectangle.h file ends --------------------- | |
//------ Rectangle.cpp file begins ----------------- | |
#include "Rectangle.h" | |
using namespace std; | |
int Rectangle::computeArea() const { | |
return (this->width * this->height); | |
} | |
void Rectangle::addToX(int x) { | |
this->x = this->x + x; | |
} | |
//------ Rectangle.cpp file ends ------------------- | |
//------ RectangleClient.cpp file begins ----------- | |
#include "Rectangle.h" | |
using namespace std; | |
int main() { | |
Rectangle r1; | |
Rectangle r2(10,10,25,40); | |
r1.setX(20); | |
cout << "Area of r2: " << r2.computeArea() << endl; | |
} | |
//------ RectangleClient.cpp file ends ----------- | |
//------ Makefile begins ----------- | |
all: RectClient | |
RectClient: RectClient.o Rectangle.o | |
c++ -o RectClient RectClient.o Rectangle.o | |
RectClient.o: RectClient.cpp | |
c++ -c RectClient.cpp | |
Rectangle.o: Rectangle.cpp | |
c++ -c Rectangle.cpp | |
//------ Makefile ends ----------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment