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 7959059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:30:50+00:00 2026-06-04T04:30:50+00:00

My task is to write the main function which defines an array of objects

  • 0

My task is to write the main function which defines an array of objects called recs[] with the size of 4. Each element of recs must be initialized with width and length, and I have to calculate its area and circumference.

#include <iostream>
#include <cmath>
using namespace std;

struct recs
{
    double width;
    double length;
};

class rect
{
    public:
           rect();
           double area; 
           double circumference;
           void setrect();
           void calarea();
           void calcircumf();
           void print(); 
           friend bool operator==(rect rec1,rect rec2);
    private:
            double width,length;
            };
            rect recs[4];

bool operator==(rect rec1,rect rec2)
{
     return (rec1.area == rec1.area && rec1.circumference == rec2.circumference);
}

rect::rect()
{
    width=0.0;
    length=0.0;
}

void rect::setrect()
{
     cout << "width = ";
     cin >> width;
     cout << "length = ";
     cin >> length;
     print();
}

void rect::calarea()
{
     width == length;
     cout << "the return value true" << endl;
}

void rect::calcircumf()
{
     width == length;
     cout << "the return value true" << endl;
}

void rect::print()
{
     cout << "width = " << width << endl;
     cout << "length = " << length << endl << endl;
     }

int main()
{   
    double area;
    double circumference;
    double width;
    double length;

    rect recs[4] = { {10.0, 12.0}, {12.0, 14.0}, {14.0, 16.0}, {16.0, 18.0} };

    for (int i = 0; i <= 4; i++)
    {
        area = width * length;
        cout << "the area "<< i << " = " << area << endl ;

        circumference = ((width + length) + (width + length));
        cout << "the circumference" << i << " = " << circumference << endl;

    };

    system("pause");
    return 0;
}

I’ve been editing this code for 4 hours so far, but I couldn’t get it to compile.

  • 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-06-04T04:30:51+00:00Added an answer on June 4, 2026 at 4:30 am

    See this.

    I hope this helps.. 🙂

    //My task is to write the main function which defines an array of objects called recs[] with the size of 4.
    //Each element of recs must be initialized with width and length, and I have to calculate its area and circumference.
    
    #include <iostream>
    
    using namespace std;
    
    class Rect{
    
    //Data Abstraction - Not letting the user access the class variables
    private:    
        double width;
        double length;
    
    public:
    
        Rect(){         //default constructor
    
            width = 0.0;
            length = 0.0;
    
        }
    
        //setters for width and length
        void setWidthAndLength(double w, double l);
    
        //area and circumference calculators
        double area(); 
        double circumference();     
    };
    
    void Rect :: setWidthAndLength(double w, double l){
    
    width = w;
    length = l;
    
    }
    
    double Rect :: area(){
    
    return width * length;
    
    }
    
    
    double Rect :: circumference(){
    
    return 2 * width + 2 * length;   
    
    }
    
    int main(int argc, char* argv[]){
    
    Rect r[4];
    int i;
    double width,length;
    
    for(i=0;i<4;i++){
    
        cout<<"Enter the width and length for rectangle "<<i<<endl;
        cin>>width>>length;
    
        //set the width
        r[i].setWidthAndLength(width,length);               
    
        cout<<"The Area of the Rectangle is "<<r[i].area()<<endl;
        cout<<"The Circumference of the Rectangle is "<<r[i].circumference()<<endl<<endl;
    
    }
    
    return 0;
    }
    

    I was wondering why i could not do this.width = w; but anyways..

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

Sidebar

Related Questions

Here's the deal. The task is to write a function which should be able
My task is to write an app(unfortunatly on C) which reads expression in infix
My task is to write a class RFind which recursively searches the current directory
The task is to write a program which prompts for a filename and then
In my task would be very nice to write a kind of objects serialization
I have an interesting task: to write a program which captures input from the
Can I write an ant task which takes parameters when being executed from another
I have a task to write a set of http unit tests, which should
I had a task to write simple game simulating two players picking up 1-3
I had a task to write simple game simulating two players picking up 1-3

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.