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
The border that defines the outer boundary of a shape or other object
Over [174]
The answer is outline
8 0
3 years ago
You need to deploy a new cloud-based windows intune deployment to manage mobile devices in your organization. drag and drop the
Elena L [17]

Answer:

step 1: sign up for an intune account

step 2: create intune user accounts

step 3: define intune policies

step 4: enroll mobile devices

step 5: link mobile devices to users.

Explanation:

The Microsoft Windows intune is a Microsoft cloud-based service that provides a central cloud service for all subscribed and linked devices. It provides a sense of security of data resource and tracking of device activities.

A company subscribes to intune to allow the use of both cooperate and BYOD (bring your own device to work), to access data. First, the administrator sign up and create the intune account, then defined the intune security policies. Then it enrolls the individual devices and links them to their respective users.

3 0
3 years ago
(1) Prompt the user for an automobile service. Output the user's input. (1 pt) Ex: Enter desired auto service: Oil change You en
Pavlova-9 [17]

Answer:

In Python:

#1

service = input("Enter desired auto service: ")

print("You entered: "+service)

#2

if service.lower() == "oil change":

   print("Cost of oil change: $35")

elif service.lower() == "car wash":

   print("Cost of car wash: $7")

elif service.lower() == "tire rotation":

   print("Cost of tire rotation: $19")

else:

   print("Invalid Service")

Explanation:

First, we prompt the user for the auto service

service = input("Enter desired auto service: ")

Next, we print the service entered

print("You entered: "+service)

Next, we check if the service entered is available (irrespective of the sentence case used for input). If yes, the cost of the service is printed.

This is achieved using the following if conditions

For Oil Change

<em>if service.lower() == "oil change":</em>

<em>    print("Cost of oil change: $35")</em>

For Car wash

<em>elif service.lower() == "car wash":</em>

<em>    print("Cost of car wash: $7")</em>

For Tire rotation

<em>elif service.lower() == "tire rotation":</em>

<em>    print("Cost of tire rotation: $19")</em>

Any service different from the above three, is invalid

<em>else:</em>

<em>    print("Invalid Service")</em>

<em></em>

6 0
3 years ago
The following are reasons why many organizations are trying to reduce and right-size their information foot-print by using data
blagie [28]

Answer:

C.<em> improve data quality and reduce redundancies, reduce increased and staggering storage management costs</em>

<em></em>

Explanation:

Excess data retention can lead to retention of redundant and irrelevant data, which can reduce data handling and processing efficiency, while at the same time increasing the cost of data storage and management. This can be curbed be reducing data to the right size by using data governance techniques like data cleansing and de-duplication

6 0
3 years ago
What would happen without satellites???
laila [671]

Answer: without satellites there would be no way for the world to communicate

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • The document responsible for describing the type of data stored in the database is called the:
    5·1 answer
  • Please answer this correctly the underline drop down menu in the font group contains options to underline
    13·1 answer
  • You are configuring a switch that has three hosts attached to FastEthernet 0/2 through 0/4. All three hosts are part of a public
    10·1 answer
  • You should structure the<br> first before you search for a relevant picture.
    11·1 answer
  • Leonardo is having difficulty accessing the course website. he should contact the for assistance. (points:1)
    13·1 answer
  • What are some (free) good animation websites (for PC/Microsoft) for a short informational video about homelessness?
    15·1 answer
  • There are many apps that help find you cheaper gas. If the cost of a gallon of regular gas is $3 at one station and $3.50 at ano
    15·1 answer
  • What would be the best tool to display the following information from a basketball game?
    6·1 answer
  • In order to create a chart, which of the following must be selected?
    8·1 answer
  • Why is it a good idea not to change the subject line when replying to a message?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!