Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:34+00:00 2026-05-31T23:18:34+00:00

I am learning C++ and I have a question. I made a class in

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:18:35+00:00Added an answer on May 31, 2026 at 11:18 pm

    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:

    class rectangle
    {
        public:
        // Variables (btw public member variables are not a good 
        //   practice, you should set them as private and access them 
        //   via accessor methods, that is what encapsulation is)
        double l;
        double w;
    
        // constructor
        rectangle();
        // Methods
        double area();
        double perim();
    };
    

    rectangle.cpp:

    #include "rectangle.h" // You include the class description
    
    // Contructor
    rectangle::rectangle()
    {
       this->l = 0;
       this->w = 0;
    }
    
    // Methods
    double rectangle::area()
    {
       return this->w * this->l;
    }
    
    double rectangle::perim()
    {
       return 2*this->w + 2*this->l;
    }
    

    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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning JPA and have one question: In which situations we need more
I'm learning java and I have made simple program that simply reads value from
I am learning Servlets/JSP/MVC and have a question about architecting a simple application. I
I'm learning C in ansi c and I have a question. I what to
I have been learning the Definitive Guide of JavaScript.i got a question about the
im currently learning stacks in java and have a quick question. what will the
I'm learning JavaFX and this is just a small programming question. I have 3
i have two questions, that i encountered in my learning project 1) Setting: i
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I am learning drupal and am trying to add some extra features to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.