Question: In C++ Implement each function prototyped in pointers.h . Read the provided preconditions and postconditions, ask questions if you do not understand them. Your implementation

In C++

Implement each function prototyped in pointers.h. Read the provided preconditions and postconditions, ask questions if you do not understand them. Your implementation will be checked for compliance to these conditions. You may assume the precondition is ALWAYS met, you do not need to confirm the precondition is true.

starter pointers.cpp

#include  #include  #include  #include "pointers.h" unsigned int len(int *start, int *end) { return 0; //TODO: Remove this line } std::string vectorIntToString(const std::vector&) { std::ostringstream oss; //TODO: Implement here return oss.str(); } void reverseVector(const std::vector &, std::vector &) { } std::vector compressSentence(const std::string &doc) { std::istringstream iss(doc); std::string word; while (iss >> word) { //Loop over words, automatically separates on space, each iteration of loop, word will be a new word } return {}; //TODO: remove this line } unsigned long long wordCount(const std::string &) { return 0; //TODO: remove this line } std::string decompressSentence(const std::vector &) { return ""; //TODO: remove this line } //bool isMagicSquare(const long long int *matrix, unsigned long long int size) { bool isMagicSquare(const std::vector& matrix) { return false;//TODO: remove this line }

pointers.h

#ifndef APOINTERS_H

#define APOINTERS_H

#include

#include

#include

//Precondition: none

//Postcondition: destination has (2n-1) items of source. The elements from position 1 to end of source

// are duplicates at the end of the vector in reverse order. The last element of source is NOT duplicated.

// [8, 2, 5] => [8, 2, 5, 2, 8]

void reverseVector(const std::vector& source, std::vector& destination);

//Precondion: n/a

//Postcondition: Returns a string of the vector contents in Python formatting, such as [8, 2, 5, 2, 8]

std::string vectorIntToString(const std::vector& array);

//Precondion: start and end point to elements in an array. end > start. end is inclusive.

//Postcondition: Returns the number of elements in the array

unsigned int len(int* start, int* end);

//Magic squares. An n n matrix that is filled with the numbers 1, 2, 3, . . ., n2 is a magic square if the sum of the

//elements in each row, in each column, and in the two diagonals is the same value.

// 16 3 2 13

// 5 10 11 8

// 9 6 7 12

// 4 15 14 1

// Precondition: size of array is a perfect square.

// Postcondition: Returns true of a nn matrix that is filled with the numbers 1, 2, 3, . . ., n^2

// created a magic square

bool isMagicSquare(const std::vector& matrix);

//When you read a long document, there is a good chance that many words occur multiple times.

// Instead of storing each word, it may be beneficial to only store unique words, and to represent the document

// as a vector of pointers to the unique words. The following functions implement this idea.

// Receive a string of words and return a vector of pointers to strings of individual words.

// If the new word is not contained in this vector, allocate memory, copy the word into it,

// and append a pointer to the new memory. If the word is already present, then append a pointer to the existing word.

// Precondition: String is a sentence with no punctuation except spaces. Sentence does not start or end with spaces.

// Postcondition: A vector is returned equal to the number of words in the sentence. However, only unique words

// allocations on the heap.

std::vector compressSentence(const std::string&);

// Precondition: Receives string pointers where each pointer points to a single word with no

// punctuation or spaces.

// Postcondition: The words are joined with spaces and returned

std::string decompressSentence(const std::vector&);

// Precondition: String is a sentence of 0 or more words, with no punctuation except spaces. Sentence does not start or end with a space

// Postcondition: The words are joined with spaces and returned

unsigned long long wordCount(const std::string&);

#endif //APOINTERS_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!