I am learning C++ and I have a question.
I made a class in Netbeans, which made Rectangle.h and Rectangle.cpp. I am trying to add methods that output the Area and Perimeter of the rectangle’s l and w variables. I don’t know how to create methods in a class and how to incorporate them in the Rectangle.h file.
Here’s what I’m trying to do:
Rectangle rct;
rct.l = 7;
rct.w = 4;
cout << "Area is " << rct.Area() << endl;
cout << "Perim is " << rct.Perim() << endl;
Can someone explain how to do this? I’m so confused.
Thanks,
Lucas
In the .h file you have the class definition, where you write down the member variables en member functions (generally as prototype)
In the .cpp file you declare the methods body. Example:
rectangle.h:
rectangle.cpp:
But like gmannickg said you should read a book about c++ or a real tutorial, that will explain you how the syntax works. And Object Oriented Programming (if you are not familiar with it)