
c++
Please Dont use Chegg for this problem
15.7 In-Lab Activity 7: Shapes (I/O operator overloading)
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.
===================================================
files included below:
"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
Please don't Use Chegg

Trending nowThis is a popular solution!
Step by stepSolved in 7 steps with 1 images

- help with c++ paste indented code plzz Have to use given main function to test your answer Q2: Continue with House class:a) Copy the previous program to a new file.b) Write Constructor with two parameter, and assign to location, and price.c) Write default constructor, initialize location to “TBD”, price to 0, Implement constructor delegationd) implement a non-member function names output that will print all information of House object. Use following main() to test your class. int main(){House a("1234 qcc st, Bayside, NY",1000000); output(a); House b; output(b); } Output from given main: Location: 1234 qcc st, Bayside, NY Price: 1000000 Location: TBD Price: 0\ ANSWER:arrow_forwardUsing C++ Assume proper includes have been executed, but not using directive or declaration. Write a definition of an iterator for a vector named vec of int values. Write a for loop that will display the contents vec on the screen, separated by spaces. Use iterators for the loop control.arrow_forwardC++ Programming: How would you write a function that takes a filename and an array of struct time, opens a file, reads each line in the file as the number of days, converts this to a struct time and stores this is in an array? Here is my code so far (p.s. the function i need help with is called void readData): #include<iostream>#include<string>#include<fstream>#include<cstdlib>#include<vector> using namespace std; struct time{// private:int years, months, days;//public: time(){}time(int days){}}; time getYearsMonthsDays(int days){time x;x.years = days/450;days = days%450;x.months = days/30;x.days = days%30;return x;} int getTotalDays(time x){int totalDays;totalDays = x.years*450 + x.months*30 + x.days;return totalDays;} void openofile(string ofilename,ofstream &fout){fout.open(ofilename.c_str());if(!fout){cout << "Error opening output file..." << endl;exit(1);}} void openifile(string ifilename,ifstream…arrow_forward
- m6 C++ Question: Make an execution chart like the example below for the code provided. Example chart: An execution chart is a text version of the hierarchy. Indentation is used to indicate thesublevels or calls inside a call. It also contains the data exchange between the components asdesignated in the hierarchy chart. Given below is the execution chart that corresponds to thehierarchy chart of the property tax calculation program1.0 Main()2.0 CalculatePropertyTax()3.0 displayMessage( input string messageToDisplay)3.1 return double getHomeValue()3.2 return boolean checkHomeValue()3.3 return double applyPropertyTax(input double homeValue)3.4 displayPropertyTax(input homeValue)3.5 return Boolean queryMoreData()4.0 displayMessage(input string messageToDisplay)4.1 return char getYesNo()4.2 return char convertCase(input char)3.6 displayErrorMessage() More exlanation: example: 1.0 means it's of depth 1, line 0 then 2.0 means it's one call inside a function (aka it's inside another function)…arrow_forwardC++ Given code is #pragma once#include <iostream>#include "ourvector.h"using namespace std; ourvector<int> intersect(ourvector<int> &v1, ourvector<int> &v2) { // TO DO: write this function return {};}arrow_forward*C Programming This exercise is to help you learn how to debug compiler warnings/errors and other common errors in your code. For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what the issue was in the `Error:` section of each problem. Work on `segfault.c` along with your fixes and error comments. segfault.c file // P0#include <stdio.h>#include <stdlib.h>/* Error: */ void fib(int* A, int n); intmain(int argc, char *argv[]) {int buf[10];unsigned int i;char *str;char *printThisOne;char *word;int *integers;int foo;int *bar;char *someText; // P1for (i = 0; i <= 10; ++i) { buf[i] = i;}for (i = 0; i <= 10; ++i) { printf("Index %s = %s\n", i, buf[i]);}/* Error: */ // P2str = malloc(sizeof(char) * 10);strcpy(str, "Something is wrong");printf("%s\n", printThisOne);/* Error: */ // P3word = "Part 3";*(word + 4) = '-';printf("%s\n", word);/* Error: */ // P4*(integers + 10) = 10;printf("Part 4: %d\n", *(integers +…arrow_forward
- c++ A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it actually moves by 2 * n steps. Implement a FastCritter class derived from Critter whose move function behaves as described. Complete the following file: fastcritter_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A FastCritter moves twice as fast as a regular critter.*/class . . .{public:void move(int steps);}; . . . int main(){FastCritter speedy;speedy.move(10);cout << speedy.get_history() << endl;cout << "Expected: [move to 20]" << endl;speedy.move(-1);cout << speedy.get_history() << endl;cout << "Expected: [move to 20, move to 18]" << endl;return 0;} Use the following file: critter.h #ifndef CRITTER_H #define CRITTER_H #include <string> #include <vector> using namespace std; /** A simulated critter. */ class Critter { public: /** Constructs a critter at position 0 with blank history. */ Critter();…arrow_forwardDescription You are provided a skeleton code in the file student_code.c. Some functions are completely implemented, and some are partially implemented. Additionally, you can add your own functions if required. Complete the program as per following details so that we can have functionality as described in the Synopsis above. All the code in single C file. REMEMBER DO NOT USE sleep(). 1. The given code reads the file's content for you and populates a dynamic array of type struct thread with information about the threads. The threads have filled in this list of threads for you. Additionally, you can check the threadCount variable to see how many threads were created using the input file. If more members are needed, you can add them. You might be able to initialise those extra members during file read if you wish to. 2. The main() already contains the code to read threads from input file. However, there is no code to initialize, execute and synchronize threads. You have to perform these…arrow_forward# dates and times with lubridateinstall.packages("nycflights13") library(tidyverse)library(lubridate)library(nycflights13) Qustion: Create a function called date_quarter that accepts any vector of dates as its input and then returns the corresponding quarter for each date Examples: “2019-01-01” should return “Q1” “2011-05-23” should return “Q2” “1978-09-30” should return “Q3” Etc. Use the flight's data set from the nycflights13 package to test your function by creating a new column called quarter using mutate()arrow_forward
- What happens if the processor sends a request to the cache while a write buffer block is being written back to main memory?arrow_forwardc++ A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it actually moves by 2 * n steps. Implement a FastCritter class derived from Critter whose move function behaves as described. Complete the following file: fastcritter_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A FastCritter moves twice as fast as a regular critter.*/class FastCritter:public Critter{public:void move(int steps);}; . . . int main(){FastCritter speedy;speedy.move(10);cout << speedy.get_history() << endl;cout << "Expected: [move to 20]" << endl;speedy.move(-1);cout << speedy.get_history() << endl;cout << "Expected: [move to 20, move to 18]" << endl;return 0;} Use the following file: critter.h #ifndef CRITTER_H #define CRITTER_H #include <string> #include <vector> using namespace std; /** A simulated critter. */ class Critter { public: /** Constructs a critter at position 0 with blank…arrow_forwardYou may use the vector and iostream libraries. You are allowed to use three built-in vector member functions (and no others) but you may not have to use them all. The member functions you are allowed to use are size(), at(), and push_back() Write a function that outputs a vector of doubles with each number in the vector separated by a space then a newline after the entire vector is output. The whole vector output should be preceded by a single line saying "Current Vector Contents:". Write a function that takes a vector a doubles and reverses the order of all the elements of the vector. Write a function that fills a vector of doubles with positive numbers using the standard input stream cin, terminate the input when the user enters any negative number. A single output prompt should precede the initial input stating directions for user. Write a main function that creates an empty vector, calls functions from 2 & 3 and calls your output function before and after each of your calls…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





