Last active
February 19, 2021 08:08
-
-
Save povilasb/55885a5dd492a9f0a8f8bec8cc151018 to your computer and use it in GitHub Desktop.
Misc simple C++ samples
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
#include <iostream> | |
using namespace std; | |
class Rectangle { | |
public: | |
int width; | |
int height; | |
Rectangle(int width, int height) { | |
this->width = width; | |
this->height = height; | |
} | |
int area() { | |
return this->width * this->height; | |
} | |
}; | |
int main() | |
{ | |
auto rect = Rectangle(2, 3); | |
cout << "Rect area: " << rect.area() << "\n"; | |
return 0; | |
} |
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
#include <iostream> | |
using namespace std; | |
class Rectangle { | |
public: | |
int width; | |
int height; | |
Rectangle(int width, int height) { | |
this->width = width; | |
this->height = height; | |
} | |
int area() { | |
return this->width * this->height; | |
} | |
}; | |
int main() | |
{ | |
auto rect1 = Rectangle(2, 3); | |
auto rect2 = Rectangle(4, 5); | |
cout << "Rect1 area: " << rect1.area() << "\n"; | |
cout << "Rect2 area: " << rect2.area() << "\n"; | |
return 0; | |
} |
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
#include <iostream> | |
using namespace std; | |
class Box { | |
public: | |
int length; | |
int height; | |
int breadth; | |
Box(int length, int height, int breadth) { | |
this->length = length; | |
this->height = height; | |
this->breadth = breadth; | |
} | |
int volume() { | |
return this->length * this->height * this->breadth; | |
} | |
}; | |
int main() | |
{ | |
auto b1 = Box(2, 3, 4); | |
auto b2 = Box(2, 3, 5); | |
cout << "Box1 volume: " << b1.volume() << "\n"; | |
cout << "Box2 volume: " << b2.volume() << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment