mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 11:26:25 +02:00
[CCV] Finished exercise 2
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -0,0 +1,7 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
add_library(Rectangle Rectangle.cpp)
|
||||||
|
project(sheet1)
|
||||||
|
add_executable(main main.cpp)
|
||||||
|
target_link_libraries(main Rectangle)
|
||||||
|
add_executable(hello hello.cpp)
|
||||||
|
add_executable(AskInteger AskInteger.cpp)
|
||||||
|
|||||||
@ -2,29 +2,16 @@
|
|||||||
// Created by jim on 4/4/17.
|
// Created by jim on 4/4/17.
|
||||||
//
|
//
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "Rectangle.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Rectangle
|
Rectangle::Rectangle(unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
private:
|
this->width = width;
|
||||||
unsigned int width;
|
this->height = height;
|
||||||
unsigned int height;
|
}
|
||||||
|
|
||||||
public:
|
unsigned int Rectangle::area()
|
||||||
Rectangle(unsigned int width, unsigned int height)
|
{
|
||||||
{
|
cout << this->width * this->height << endl;
|
||||||
this->width = width;
|
|
||||||
this->height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int area()
|
|
||||||
{
|
|
||||||
return this->height * this->width;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
Rectangle* rec = new Rectangle(10, 20);
|
|
||||||
cout << rec->area() << endl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
19
ccv/sheet1/Rectangle.h
Normal file
19
ccv/sheet1/Rectangle.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by jim on 4/4/17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SHEET1_RECTANGLE_H
|
||||||
|
#define SHEET1_RECTANGLE_H
|
||||||
|
|
||||||
|
class Rectangle
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Rectangle(unsigned int, unsigned int);
|
||||||
|
unsigned int area();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SHEET1_RECTANGLE_H
|
||||||
11
ccv/sheet1/main.cpp
Normal file
11
ccv/sheet1/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by jim on 4/4/17.
|
||||||
|
//
|
||||||
|
#include "Rectangle.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Rectangle* rec = new Rectangle(20, 10);
|
||||||
|
rec->area();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user