Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ myString.h // FILE: mystring.h // CLASS PROVIDED: my_string // This is a simple version of the Standard Library string. // It is part

in C++

image text in transcribedmyString.h

// FILE: mystring.h // CLASS PROVIDED: my_string // This is a simple version of the Standard Library string. // It is part of the namespace main_savitch_4, from the textbook // "Data Structures and Other Objects Using C++" // by Michal Main and Walter Savitch // // CONSTRUCTOR for the my_string class: // string(const char str[ ] = "") -- default argument is the empty string. // Precondition: str is an ordinary null-terminated string. // Postcondition: The string contains the sequence of chars from str. // // CONSTANT MEMBER FUNCTIONS for the my_string class: // size_t length( ) const // Postcondition: The return value is the number of characters in the // string. // // char operator [ ](size_t position) const // Precondition: position >(istream& ins, string& target) // Postcondition: A string has been read from the istream ins, and the // istream ins is then returned by the function. The reading operation // skips white space (i.e., blanks, newlines, tabs) at the start of ins. // Then the string is read up to the next white space or the end of the // file. The white space character that terminates the string has not // been read. // // ostream& operator =, , and  // Provides size_t namespace hw4 { class my_string { public: // CONSTRUCTORS and DESTRUCTOR my_string(const char str[ ] = ""); my_string(const my_string& source); ~my_string( ); // MODIFICATION MEMBER FUNCTIONS void operator +=(const my_string& addend); void operator +=(const char addend[ ]); void operator +=(char addend); void reserve(size_t n); void operator =(const my_string& source); void insert(size_t n); // CONSTANT MEMBER FUNCTIONS size_t length( ) const { return current_length; } char operator [ ](size_t position) const; // FRIEND FUNCTIONS friend std::ostream& operator =(const my_string& s1, const my_string& s2); friend bool operator  (const my_string& s1, const my_string& s2); friend bool operator >(std::istream& ins, my_string& target); void getline(std::istream& ins, my_string& target); void eat_white(std::istream& ins, my_string& target); } #endif 

myString.cpp

// CLASS IMPLEMENTED: my_string (see mystring.h for documentation) // INVARIANT for the my_string class: // 1. The string is stored as a null-terminated string in the dynamic array // that characters points to. // 2. The total length of the dynamic array is stored in the member variable // allocated. // 3. The total number of characters prior to the null character is stored in // current_length, which is always less than allocated. #include  // Provides stream tools #include  // Provides assert() #include  // Provides strcpy(), strcat(), strlen(), strcmp() #include  // Provides size_t, NULL #include  // Provides stream types #include "mystring.h" using namespace std; namespace hw4 { // CONSTRUCTORS and DESTRUCTOR my_string::my_string(const char str[ ]) // Library facilities used: string.h { current_length = strlen(str); allocated = current_length + 1; sequence = new char[allocated]; strcpy(sequence, str); } my_string::my_string(const my_string& source) // Library facilities used: string.h { sequence = new char[source.allocated]; current_length = source.current_length; allocated = source.allocated; strcpy(sequence, source.sequence); } my_string::~my_string( ) { delete [ ] sequence; } // MODIFICATION MEMBER FUNCTIONS // CONSTANT MEMBER FUNCTIONS // In-lined: size_t length( ) const; char my_string::operator [ ](size_t position) const // Library facilities used: assert.h { assert(position   Recursion vs Iterative functions. For this assignment you will make a Vehicle class with two recursive member functions. a) Implement overloaded member functions called binSearchRec,the recursive binSearchRec algorithm is presented in this chapter, starting on page 68 for an array of vehicles. Use a vector instead of an array. Sort by make then call a recursive function to do a binary search which lists out the make, model and year for the first year found (or report accordingly) that matches the for a user input then start a new sort Sort by model then call a recursive function to do a binary search which lists out the make, model and year for the first year found (or report accordingly) that matches the for a user input. Read in the vehicles from a vehicle file (vehiclein.txt)that has a year, make, and model. You have a choice of reading in an integer and two strings OR reading in 3 strings and converting the year to an int. Remember that between a stream operator (

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_2

Step: 3

blur-text-image_3

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

4. Why is it that correlations do not imply causation?

Answered: 1 week ago