Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

GIVES THE ERROR ******* 0 0 illegal instruction: 4 // --> YOUR NAME here // Few comments describing the class Points2 #ifndef CSCI335_HOMEWORK1_POINTS2_H_ #define CSCI335_HOMEWORK1_POINTS2_H_

GIVES THE ERROR

*******

0 0

illegal instruction: 4

// --> YOUR NAME here // Few comments describing the class Points2

#ifndef CSCI335_HOMEWORK1_POINTS2_H_ #define CSCI335_HOMEWORK1_POINTS2_H_

#include #include #include #include #include

namespace teaching_project { // Place comments that provide a brief explanation of the class, // and its sample usage. template class Points2 { public: // Default "big five" -- you have to alter them for your assignment. // That means that you will remove the "= default" statement. // and you will provide an implementation.

// Zero-parameter constructor. // Set size to 0. Points2() { size_ = 0; } // Move-constructor.

Points2(Points2 &&rhs){ swap(sequence_, rhs.sequence_); swap(size_, rhs.size_());

} // Copy-constructor. Points2(const Points2 &rhs) { this->size_ = rhs.size(); sequence_ = new std::array[rhs.size_](); for(int i = 0; i < rhs.size_; i++){ sequence_[i] = rhs.sequence_[i]; } }

// 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) { Points2 copy = rhs; std::swap(*this, copy); return *this; }

// Move-assignment. NOT SURE // Just use std::swap() for all variables. Points2& operator=(Points2 &&rhs) { *this = std::move(rhs); return *this; }

~Points2() { delete[] sequence_; }

// End of big-five.

// One parameter constructor. Points2(const std::array& item) { size_ = item.size_()/2; sequence_ = new std::array{item}; }

// Read a chain from standard input. NOT SURE 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 (int i = 0 ;input_stream >> token; ++i) { int x, y; std::cin >> x >> y; sequence_[i].fill(x); sequence_[i].fill(y); // Read coordinates. // Fill sequence_ here. } }

size_t size() const { return size_; }

// @location: an index to a location in the sequence. // @returns the point at @location. // const version. // abort() if out-of-range. const std::array& operator[](size_t location) const { if(location > size_) || (location < 0){ std::abort(); } return sequence_[location]; }

// @c1: A sequence.IN PROGRESS // @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) { // Points2 output; // output.x = c1.x + c2.x; // output.y = c1.y + c2.y; // return output; }

// Overloading the << operator. IN PROGRESS friend std::ostream &operator<<(std::ostream &out, const Points2 &some_points2) { for(int i =0; i < some_points2.size(); i++){ out << some_points2.sequence_[i][0] << some_points2.sequence_[i][1] << std::endl; } return out; } private: // Sequence of points. std::array *sequence_; // Size of sequence. size_t size_;

};

} // namespace teaching_project #endif // CSCI_335_HOMEWORK1_POINTS2_H_

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions