1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
fomenos
1 year ago
15

In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle obj

ects and find their area and perimeter.
Instructions
Ensure the class file named Rectangle.cpp is open in your editor.
In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double.
Write public set methods to set the values for length and width.
Write public get methods to retrieve the values for length and width.
Write a public calculateArea()method and a public calculatePerimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle.
Open the file named MyRectangleClassProgram.cpp.
In the MyRectangleClassProgram, create two Rectangle objects named rectangle1 and rectangle2 using the default constructor as you saw in MyEmployeeClassProgram.cpp.
Set the length of rectangle1 to 10.0 and the width to 5.0. Set the length of rectangle2 to 7.0 and the width to 3.0.
Print the value of rectangle1’s perimeter and area, and then print the value of rectangle2’s perimeter and area.
Execute the program by clicking the Run button at the bottom of the screen
Computers and Technology
1 answer:
MakcuM [25]1 year ago
8 0

The program based on the information given is illustrated below.

<h3>What is a program?</h3>

A computer program simply means a sequence of instructions in a programming language that is created for a computer to execute.

It should be noted that computer programs are among the component of software.

The program to create two rectangle objects and get their area and perimeter is depicted:

// Rectangle.cpp

using namespace std;

class Rectangle

{

public:

// Declare public methods here

void setLength(double);

void setWidth(double);

double getLength();

double getWidth();

double calculateArea();

double calculatePerimeter();

private:

// Create length and width here

double length, width;

};

void Rectangle::setLength(double len)

{

length = len;

}

void Rectangle::setWidth(double wid)

{

// write setWidth here

width = wid;

}

double Rectangle::getLength()

{

// write getLength here

return length;

}

double Rectangle::getWidth()

{

// write getWidth here

return width;

}

double Rectangle::calculateArea()

{

// write calculateArea here

return length*width;

}

double Rectangle::calculatePerimeter()

{

// write calculatePerimeter here

return 2*(length+width);

}

// This program uses the programmer-defined Rectangle class.

#include "Rectangle.cpp"

#include <iostream>

using namespace std;

int main()

{

Rectangle rectangle1;

Rectangle rectangle2;

rectangle1.setLength(10.0);

rectangle1.setWidth(5.0);

rectangle2.setLength(7.0);

rectangle2.setWidth(3.0);

cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl;

cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl;

cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl;

cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;

return 0;

}

/*

output:

The perimeter of rectangle1 is 30

The area of rectangle1 is 50

The Perimeter of rectangle2 is 20

The area of rectangle2 is 21

*/

Learn more about program on:

brainly.com/question/1538272

#SPJ1

You might be interested in
Where is the typical location of a touchpad inside of a laptop?
butalik [34]

Answer:

Attached to the keyboard

Explanation:

Touch pad is the type of the mouse that is located on the laptop just near the keyboard or we can say that it is attached to the keyboard of the laptop. It has almost two buttons that are used for the purpose of Left and Right Click.

The touch pad is used to move the cursor to the required position on the screen of the laptop. This will work by just moving figure on the touch pad as the cursor move on the screen in the same direction of the finger..

5 0
3 years ago
Aapke question about computer keyboard​
Lapatulllka [165]

Explanation:

A computer keyboard is an input device that allows a person to enter letters, numbers, and other symbols (these are called characters in a keyboard) into a computer. It is one of the most used input devices for computers. Using a keyboard to enter lots of data is called typing

8 0
2 years ago
You are the system administrator for a medium-sized Active Directory domain. Currently, the environment supports many different
Bogdan [553]

Answer:

All the Above

Explanation:

Domain local groups, global Groups, Universal Security Groups all these 3 groups can be used.

7 0
3 years ago
What are the steps for creating a bookmark? 1. Place the insertion point where the bookmark should appear. 2. Click the tab. 3.
Paladinen [302]

Answer:

2. Insert

3. Links

4. Add

6. Advanced

Explanation:

HTML is an acronym for hypertext markup language and it is a standard programming language which is used for designing, developing and creating web pages.

A website refers to the collective name used to describe series of web pages linked together with the same domain name.

On the other hand, a webpage is the individual HTML document (single page) that makes up a website with a unique uniform resource locator (URL).

A bookmark can be defined as a placeholder or saved shortcut for a webpage and for future reference. Thus, it avails an end user the ability to quickly access a bookmarked webpage by automatically directing the web browser to the webpage.

Basically, the steps for creating a bookmark are;

1. The insertion point of the webpage should be placed at the point where the bookmark should appear.

2. Click the "INSERT" tab.

3. In the "LINKS" group, click "Bookmark"

4. When a dialog box opens, the bookmark should be named with a specific title, and then click "ADD"

5. To see bookmarks within the HTML document, you should go to Backstage view and click on "Options"

6. In ADVANCED, select Show Bookmarks to have them appear as a locked cursor within the HTML document.

6 0
3 years ago
What is an assembler?
Flauer [41]

an assembler is a program that converts code written in a high-level language to assembly language that the computer processor can execute.

4 0
3 years ago
Other questions:
  • Write a program that determines the price of a movie ticket (similar to the one in the chapter). The program asks for the custom
    9·1 answer
  • HELP ASAP!!!!!!!!! ITS A UNIT TEST: WILL MARK AS BRAINLIEST&gt;
    13·1 answer
  • Jorge has $300 for work he performed. He expects to spend the money in the next few weeks to buy a new bike. Which type of accou
    8·1 answer
  • Design and document an IP addressing scheme to meet ElectroMyCycle’s needs. Specify which IP address blocks will be assigned to
    11·1 answer
  • Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their
    14·1 answer
  • Wireless networks are the most difficult type of network to set up <br> true or false
    15·1 answer
  • Which of the following is NOT essential for individuals to have to build their own web page?
    9·1 answer
  • The set of rules for how computers talk to one another
    6·1 answer
  • Add a new row to a table by clicking in the
    10·1 answer
  • If you wish to sign out of your Microsoft account, tap or click ____ on the ribbon to open the Backstage view and then tap or cl
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!