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
2 years 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]2 years 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
White meat and dark meat fish have slightly different nutritional characteristics. What are the nutrition characteristics of dar
ipn [44]

The nutrition characteristics of eating darker meat of fish like Salmon are that it is higher in healthy Omega-3 fats. It is true, however, that as much as it has the highest Omega-3 fats, it is also likely to be highest in any potential toxins.






6 0
3 years ago
Read 2 more answers
A key benefit of inheritance is Group of answer choices an object can have several types, it is type compatible with any of its
NARA [144]

Answer:

A key benefit of inheritance is: an object can have several types, it is type compatible with any of its super classes

Explanation:

  • Inheritance is one of the fundamental concepts of Object Oriented Programming.
  • Inheritance allows classes (derived classes) to inherit the methods and properties of a class (base class).
  • The class or classes that inherits the characteristics from another class is called a derived class, child class or sub class. Derived class can also has it own methods and attributes additionally.
  • The class whose methods and properties are inherited by the derived class or classes is called a base class, super class or a parent class.
  • Benefit of inheritance is that inheritance new objects can take properties of existing objects and an object can have many types.
  • Also a child class can inherit from more than one super classes which is called multiple inheritance.
  • Multiple inheritance allows a class to implement more than one abstract classes.
  • An object can have several types. These types can be of an object's own class and also other types which include all classes that a class inherits.
  • If a variable is declared to be the type of super class then value of that variable can refer to any instance that instantiated from any class that inherits that super class. This means that an object is type compatible with an of its super classes.
8 0
3 years ago
What is the full meaning of RFID in computer​
Brut [27]

Answer:

radio frequency identification

Explanation:

i thought i had answered this already...?

8 0
3 years ago
Read 2 more answers
Describe one reason you would import data into a database.
AURORKA [14]
<span>You typically import data for the following reasons: You want to merge two databases by copying all the objects in one database to another. [ When you import, you can copy all the tables, queries, forms, reports, macros, and modules, along with table relationships, to another database in a single operation. You need to create some tables that are similar to tables that exist in another</span>
6 0
4 years ago
Read 2 more answers
Debug the following program.
mamaluj [8]

Answer:

The debugged program is as follows:

A=2

B=2

For I=1 to 10

PRINT A

TEMP = A

A=B

B=TEMP+A

NEXT I

END

Explanation:

First, the value of B should be changed to 4 (because the second term of the sequence is 2

Next, change Display to Print because Q-basic uses the print keyword to display output

The sequence is not properly generated. So, I update that part of the program to:

<em>For I=1 to 10 </em>

<em>PRINT A </em>

<em>TEMP = A </em>

<em>A=B </em>

<em>B=TEMP+A </em>

<em>NEXT I </em>

<em />

Lastly, the loop is controlled by variable I (not X).

So change NEXT X to NEXT I

4 0
3 years ago
Other questions:
  • When approved for a loan, an individual essentially applied for aid in the area of...
    15·1 answer
  • Suppose arraylist list1 is [1, 2, 5] and arraylist list2 is [2, 3, 6]. after list1.addall(list2), list1 is __________.
    8·1 answer
  • After a new firewall is installed, users report that they do not have connectivity to the Internet. The output of the ipconfig c
    6·1 answer
  • Who is involved in helping shape the emotional impact of a film? (Select all that apply.)
    8·2 answers
  • Suppose we have a linearly separable dataset, and we divide the data into training and validation sets. Will a perceptron learne
    8·1 answer
  • What is the first thing Kernel does when WinLoad turns over the starttup process to it
    5·1 answer
  • Which type of financial institution typically has membership requirements?
    14·1 answer
  • You are having trouble cleaning your computer for a troublesome virus. you decide to try to clean your computer while in safe mo
    5·1 answer
  • What is data that originated in another program or format?
    7·1 answer
  • is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!