For this lab you will be creating a class representing the shape square. A Square is a special case of a Rectangle where both sides have the same length. Rectangle has been provided for your use in this lab. A Rectangle has a height and a width as member variables, two constructors, two member functions, area() and perimeter(), and lastly, an input and output operator. Your Square class should publicly inherit from Rectangle. You will need to update the Constructors and the input/output operators to reflect that both sides, height and width are now equal. The Constructors should be default, which sets the height and width to 0, and a constructor that takes in a single double n and sets height and width to n. The operator<< should output the side size of the square to the stream. The operator>> should read in a double and store the information in the square correctly. NOTE: You should be able to output a square to a file using operator<< and read it back in to a square using operator>>. You have been given a text file containing a list of side sizes for some squares, you will need to write a small program that reads in each of these sides, stores it in a square, and then prints the perimeter and area of each square in the list
shell code
#ifndef _REC_H_ #define _REC_H_ #include <iostream> using namespace std; class Rectangle { public: Rectangle(): height_(0), width_(0) {} Rectangle(double h, double w): height_(h), width_(w) {} double area() { return height_ * width_; } double perimeter() { return 2 * height_ + 2 * width_; } friend istream& operator>>(istream&, Rectangle&); friend ostream& operator<<(ostream&, const Rectangle&); protected: double height_; double width_; }; istream& operator>>(istream& in, Rectangle& r) { in >> r.height_; in >> r.width_; return in; } ostream& operator<<(ostream& out, const Rectangle& r) { out << r.height_ << " " << r.width_; return out; } #endif
square sizes
1 2 3 4 5 10 15
c++
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
For this lab you will be creating a class representing the shape square. A Square is...
Task:
Tasks to complete:
------------------------------------------------------------------------------------------------------------------------------------------
given code:
------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include
#include "rectangleType.h"
using namespace std;
// part e
int main()
{
rectangleType rectangle1(10, 5);
rectangleType rectangle2(8, 7);
rectangleType rectangle3;
rectangleType rectangle4;
cout << "rectangle1: " << rectangle1 <<
endl;
cout << "rectangle2: " << rectangle2 <<
endl;
rectangle3 = rectangle1 + rectangle2;
cout << "rectangle3: " << rectangle3 << endl;
rectangle4 = rectangle1 * rectangle2;
cout << "rectangle4: " << rectangle4 << endl;
if (rectangle1 > rectangle2)
cout << "Area...
Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects 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 lengthand width. Write public...
Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. Write public set methods to set the values for length and width. Write...
Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...
17. Write a non-member function called centroid(param) that takes a static array of points and the size of the array and return the centroid of the array of points. If there is no center, return the origins private: double x, y, z public: /Constructors Point(); Point(double inX, double inY, double inZ = 0); Point(const Point& inPt); / Get Functions double getX() const; double getY) const; double getZ) const; Set Functions void setX(double inX); void setY(double inY); void setZ(double inZ); void...
Create a program that calculates the area of various shapes.
Console
Specifications
Create an abstract class named Shape. This
class should contain virtual member function named
get_area() that returns a double type.
Create a class named Circle that inherits the
Shape class and contains these constructors and member functions:
Circle(double radius)
double get_radius()
void set_radius(double radius)
double get_area()
Create a class named Square that inherits the
Shape class and contains these constructors and member functions:
Square(double width)
double get_width()
void...
/* FILE: ./shapes7/shape.h */
#include <iostream>
using std::ostream;
class shape{
int x,y;
public:
shape( )
{ x=y=0;}
shape(int xvalue, int yvalue);
void setShape(int new_x, int new_y);
void setX(int new_x);
void setY(int new_y);
int getX( ) const;
int getY( ) const;
virtual void move(int x, int y) = 0;
virtual void shift(int dx, int dy) = 0;
virtual void draw( ) = 0;
virtual void rotate(double r) = 0;
virtual void print(ostream&)const;
friend ostream & operator<<(ostream & os, const shape& s);...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp, and a test file to test the functionality of the class. Hint: read all the explanations in the header with attention. MyArray.h : #ifndef MYARRAY_H #define MYARRAY_H #include <iostream> using namespace std; class MyArray { friend ostream& operator<<( ostream & output, const MyArray & rhs); // to output the values of the array friend istream& operator>>( istream & input, MyArray & rhs); // to...