Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Given code is provided down below. Please do not change the existing code. The instructions are in the image. Please explain and show each step and a screenshot of the input and output. Thank you.

main.cpp

#include "Triangle.h"
#include "Square.h"
#include <iostream>

using namespace std;

int main() {
 
   //Do not modify
 
   return 0;
}

-------------------------------------------

Square.cpp

#include "Square.h"
#include <iostream>
using namespace std;

Square::Square(){
  base = 0;
  height = 0;
}

Square::Square(int b, int h) : base(b), height(h) { }

void Square::setBase(int b){
  base = b;
}

void Square::setHeight(int h){
  height = h;
}

void Square::calculateArea(){
  // calculate Area correctly depending on shape type
}

int Square::getBase() const{
  return base;
}

int Square::getHeight() const{
  return height;
}

double Square::getArea() const{
  return area;
}
// Overloaded << operator

// Overloaded >> operator

-------------------------------------------

Square.h

#ifndef SQUARE_H_
#define SQUARE_H_

#include <iostream>
using namespace std;

class Square {
public:
    Square();
    Square(int b, int h);
   
   //Setters
   void setBase(int b);
   void setHeight(int h);

   //Getters
   int getBase() const;
   int getHeight() const;
   double getArea() const;
   
   void calculateArea();

   // Overloaded << operator declaration

   // Overloaded >> operator declaration

private:
   int base;
   int height;
   double area;
};

#endif

-------------------------------------------

Triangle.cpp

#include "Triangle.h"
#include <iostream>
using namespace std;

Triangle::Triangle(){
   base = 0;
   height = 0;
}

Triangle::Triangle(int b, int h) : base(b), height(h) { }

void Triangle::setBase(int b){
   base = b;
}

void Triangle::setHeight(int h){
   height = h;
}

void Triangle::calculateArea(){
  // calculate Area correctly depending on shape type
}

int Triangle::getBase() const{
  return base;
}

int Triangle::getHeight() const{
  return height;
}

double Triangle::getArea() const{
  return area;
}

// Overloaded << operator declaration

// Overloaded >> operator declaration

-------------------------------------------

Triangle.h

#ifndef TRIANGLE_H_
#define TRIANGLE_H_

#include <iostream>
using namespace std;

class Triangle {
public:
    Triangle();
    Triangle(int b, int h);
   
   //Setters
   void setBase(int b);
   void setHeight(int h);

   //Getters
   int getBase() const;
   int getHeight() const;
   double getArea() const;
   
   void calculateArea();

   // Overloaded << operator declaration

   // Overloaded >> operator declaration
   

private:
   int base;
   int height;
   double area;
};

#endif

In this program, you must implement I/O operator overloading (`<<` and `>>`) to match a shape's functionality.

You must modify the following files:

**Triangle.h**
- Implement the declaration for the overloaded I/O operator functions.

**Triangle.cpp**
- Implement the `calculateArea()` function to find the area of the triangle.
- Implement the definitions for the overloaded I/O operator functions.
- The input function will take in two variables: The base and height (`cin >> base >> height`)
  - Call the object’s `calculateArea()` function after inputting the variables.

The output function will send the following to the output stream (for base = 10 and height = 20):
```
Triangle Object:
Base: 10
Height: 20
Area is: 100
```

**Square.h**
- Implement the declaration for the overloaded I/O operator functions.

**Square.cpp**
- Implement the `calculateArea()` function to find the area of the square.
- Implement the definitions for the overloaded I/O operator functions.
- The input function will take in two variables: The base and height (`cin >> base >> height`)
  - Call the object’s `calculateArea()` function after inputting the variables.

The output function will send the following to the output stream (for base = 10 and height = 20):
```
Square Object:
Base: 10
Height: 20
Area is: 200
```

*HINT: Print newline characters after every line (`endl` or `"\n"`)*
*Do not modify the main.cpp file.*
expand button
Transcribed Image Text:In this program, you must implement I/O operator overloading (`<<` and `>>`) to match a shape's functionality. You must modify the following files: **Triangle.h** - Implement the declaration for the overloaded I/O operator functions. **Triangle.cpp** - Implement the `calculateArea()` function to find the area of the triangle. - Implement the definitions for the overloaded I/O operator functions. - The input function will take in two variables: The base and height (`cin >> base >> height`) - Call the object’s `calculateArea()` function after inputting the variables. The output function will send the following to the output stream (for base = 10 and height = 20): ``` Triangle Object: Base: 10 Height: 20 Area is: 100 ``` **Square.h** - Implement the declaration for the overloaded I/O operator functions. **Square.cpp** - Implement the `calculateArea()` function to find the area of the square. - Implement the definitions for the overloaded I/O operator functions. - The input function will take in two variables: The base and height (`cin >> base >> height`) - Call the object’s `calculateArea()` function after inputting the variables. The output function will send the following to the output stream (for base = 10 and height = 20): ``` Square Object: Base: 10 Height: 20 Area is: 200 ``` *HINT: Print newline characters after every line (`endl` or `"\n"`)* *Do not modify the main.cpp file.*
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education