721
edits
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Hey there, we were using this [https://www.tutorialspoint.com/compile_cpp_online.php online compiler] to learn some basics about c++. Here are the code snippets we discussed: | |||
Little intro to data types: | Little intro to data types: | ||
| Line 34: | Line 36: | ||
The code about classes and pointers: | The code about classes and pointers: | ||
#include <iostream> | #include <iostream> | ||
using namespace std; | using namespace std; | ||
class Point2D { | class Point2D { | ||
| Line 59: | Line 61: | ||
float _y; | float _y; | ||
}; | }; | ||
int main() | int main() | ||
{ | { | ||
| Line 70: | Line 70: | ||
point1.print(); | point1.print(); | ||
point2.print(); | point2.print(); | ||
// this is an array of integers | |||
int integerArray[5] = { 0,1,2,3,4 }; | int integerArray[5] = { 0,1,2,3,4 }; | ||
cout << "first element: " << integerArray[0] << endl; | cout << "first element: " << integerArray[0] << endl; | ||
// we can also declare an array points | |||
Point2D pointArray[3] = {point1, point2, point3 }; | Point2D pointArray[3] = {point1, point2, point3 }; | ||
pointArray[2].print(); | pointArray[2].print(); | ||
// pointer version of the code | // pointer version of the code | ||
Point2D* p2d1_ptr = new Point2D(123, 234); | Point2D* p2d1_ptr = new Point2D(123, 234); | ||