Question
Programming problem in C++ Included are two files which are the test_chain cpp file and the chain.h header file. The header file must be edited
Programming problem in C++
Included are two files which are the test_chain cpp file and the chain.h header file. The header file must be edited to compile with the main file. The main file is NOT to be edited and there are instructions within the comments of the header file for what needs to be edited for the program to work correctly.
Create and test a class called Chain. A chain is just a series of items, e.g. [2 7 -1 43] is a chain containing four integers. A Chain can have any size. An empty Chain has size 0.create a Chain class from scratch without using the STL. Since Chain can have arbitrary size, you should use pointers. The private data members should be: size_t size_; Object *array_;
test+chain cpp code
#include
// Place stand-alone function in unnamed namespace. namespace { void TestPart1() { Chain
void TestPart2() { Chain
} // namespace
int main(int argc, char **argv) { TestPart1(); TestPart2(); return 0; }
chain.h header file
#include
namespace teaching_project { // Place comments that provide a brief explanation of the class, // and its sample usage. template
// Zero-parameter constructor. Chain() = default;
// Copy-constructor. Chain(const Chain &rhs) = default;
// Copy-assignment. If you have already written // the copy-constructor and the move-constructor // you can just use: // { // Chain copy = rhs; // std::swap(*this, copy); // return *this; // } Chain& operator=(const Chain &rhs) = default;
// Move-constructor. Chain(Chain &&rhs) = default;
// Move-assignment. // Just use std::swap() for all variables. Chain& operator=(Chain &&rhs) = default;
~Chain() { // Provide destructor. }
// End of big-five.
// One parameter constructor. Chain(const Object& item) { // Write something. }
// Read a chain from standard input. void ReadChain() { // Write something. }
size_t size() const { // Write something }
// @location: an index to a location in the chain. // @returns the Object at @location. // const version. // abort() if out-of-range. const Object& operator[](size_t location) const { // Write something }
// @location: an index to a location in the range. // @returns the Object at @location. // non-const version. // abort() if out-of-range. Object& operator[](size_t location) { // Write something (will be the same as above) }
// @c1: A chain. // @c2: A second chain. // @return the concatenation of the two chains. friend Chain operator+(const Chain &c1, const Chain &c2) { // Write something. }
// Overloading the << operator. friend std::ostream &operator<<(std::ostream &out, const Chain &a_chain) { // Print the chain. return out; }
private: size_t size_; Object *array_; };
} // namespace teaching_project
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