Question
Help with the big five constructors Create and test a class called Points2. This class describes a sequence of 2D points. For example (1, 3),
Help with the big five constructors
Create and test a class called Points2. This class describes a sequence of 2D points. For example (1, 3), (4, 5) is a sequence of two points, where each coordinate is an integer. (1.2, 3.4), (5.6, 10.1), (11.1, 12.0) is a sequence of three points where each coordinate is a double. A sequence can have any size. An empty sequence has size 0.
Please fill out the code. To make things easier I will provide the file to input and the main file that will be used to test it. Please just stick with these functions that I have written out.
Please just help me with filling out the whole class(points2.h file)
Thank you.
points2.h file
#ifndef CSCI335_HOMEWORK1_POINTS2_H_ #define CSCI335_HOMEWORK1_POINTS2_H_
#include
namespace teaching_project { // Place comments that provide a brief explanation of the class, // and its sample usage. template
// Zero-parameter constructor. // Set size to 0. Points2() = default;
// Copy-constructor. Points2(const Points2 &rhs) = default;
// Copy-assignment. If you have already written // the copy-constructor and the move-constructor // you can just use: // { // Points2 copy = rhs; // std::swap(*this, copy); // return *this; // } Points2& operator=(const Points2 &rhs) = default;
// Move-constructor. Points2(Points2 &&rhs) = default;
// Move-assignment. // Just use std::swap() for all variables. Points2& operator=(Points2 &&rhs) = default;
~Points2() = default;
// End of big-five.
// One parameter constructor. Points2(conststd::array
// Read a chain from standard input. void ReadPoints2() { // Part of code included (without error checking). std::string input_line; std::getline(std::cin, input_line); std::stringstream input_stream(input_line); if (input_line.empty()) return; // Read size of sequence (an integer). int size_of_sequence; input_stream >> size_of_sequence; // Allocate space for sequence. // Add code here. Object token; for (inti = 0 ;input_stream >> token; ++i) { // Read coordinates. // Fill sequence_ here. } }
size_t size() const { // Code missing. }
// @location: an index to a location in the sequence. // @returns the point at @location. // const version. // abort() if out-of-range. conststd::array
// @c1: A sequence. // @c2: A second sequence. // @return their sum. If the sequences are not of the same size, append the // result with the remaining part of the larger sequence. friend Points2 operator+(const Points2 &c1, const Points2 &c2) { // Code missing. }
// Overloading the << operator. friendstd::ostream &operator<<(std::ostream &out, const Points2 &some_points2) { // Code missing. } private: // Sequence of points. std::array
};
} // namespace teaching_project #endif
This would be the sequence to input.
3 7 4 3 5 19 71 4 100 101 2 3 40 50 11 33 3 2.1 20.3 11.11 12.45 13.1 14.2 2 1.1 100.0 20.1 30.2
And the following functions I have written to test the code.
// Do not change this file #include
#include
// Place stand-alone function in unnamed namespace. namespace { void TestPart1() { Points2
int main(int argc, char **argv) { TestPart1(); TestPart2(); return 0; }
PLease help me. thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started