cpp assignment

profiletroook61
pa5.zip

PA5/main (1).cpp

#include <iostream> #include "String.h" #include <string> using namespace std; int main() { //calls constructor that accepts char* String s1{"Hello"}; //calls constructor that accepts C++ string String s2{string{"world"}}; //calls default constructor String s3{}; //calls copy constructor String s4{s1}; //should call move constructor String s5{String{"test"}}; //calls operator<< cout << "S1: " << s1 << endl; //calls operator>> cin >> s3; //calls getLength() cout << "length: " << s1.getLength() << endl; //calls subString() cout << s1.subString(1, 3) << endl; //calls find() cout << s1.find(String{"l"}, 1) << endl; //calls replace() cout << s1.replace(String{"l"}, String{"b"}, 2) << endl; //calls toUpper() cout << s2.toUpper() << endl; //calls toLower() cout << s1.toLower() << endl; //calls copy constructor s4 = s2; cout << s4 << endl; //calls operator[] cout << s1[0] << endl; //calls comparison operators cout << (s1 > s2) << " " << (s1 < s2) << " " << (s1 >= s2) << " " << (s1 <= s2) << " " << (s1 == s2) << endl; //calls string concatination cout << s1 + s2 << endl; //add s2 to s1 s1 += s2; cout << s1 << endl; return 0; }

__MACOSX/PA5/._main (1).cpp

PA5/PA5.docx

The purpose of this assignment is to reinforce the principles of object-oriented programming and operator overloading. To this end, in PA5, you will be implementing a custom String class that works just like the standard C++ string class. Our String class will be built on top of the LinkedList class developed in lab.

Requirements

Included with this document is starter code that includes skeleton code for our String as well as test functions that can be used to determine the correctness of our solution. The file String.h contains all required functions as well as a brief explanation of purpose for each function.

Header Comment, and Formatting

Be sure to modify the file header comment at the top of your script to indicate your name, student ID, completion time, and the names of any individuals that you collaborated with on the assignment.

Remember to follow the basic coding style guide.

Reflection Essay

In addition to the programming tasks listed above, your submission must include an essay that reflects on your experiences with this homework. This essay must be at least 350 words long. Note that the focus of this paper should be on your reflection, not on structure (e.g. introductory paragraph, conclusion, etc.). The essay is graded on content (i.e. it shows deep though) rather than syntax (e.g. spelling) and structure. Below are some prompts that can be used to get you thinking. Feel free to use these or to make up your own.

Describe a particular struggle that you overcame when working on this programming assignment.

Conversely, describe an issue with your assignment that you were unable to resolve.

Provide advice to a future student on how he or she might succeed on this assignment.

Describe the most fun aspect of the assignment.

Describe the most challenging aspect of the assignment.

Describe the most difficult aspect of the assignment to understand.

Provide any suggestions for improving the assignment in the future.

Deliverables

You must upload your assignment through Canvas no later than midnight on Tuesday, November 15, 2016. Remember that your submission must either contain a CodeBlocks or Visual Studio project file!

Grading Criteria

Your assignment will be judged by the following criteria:

Reflection essay (5pts)

Your reflection meets the minimum requirements as specified earlier in this document.

Error Free Compile (5pts)

[0] Your program contains compiler errors.

[1] Your program compiles without issue.

Error Free Runtime (5pts)

[0] Your program throws a runtime exception.

[1] Your program does not encounter any runtime exceptions.

Implementation (3pts per function)

[0-2] A string function is not implemented, implemented poorly, or implemented in a way that produces incorrect output.

[3] A string function is implemented correctly.

Style (5pts)

[0-1] Your code does not include any helpful comments. Indentation is poor. In general, your solution is hard to read.

[2-3] Your code falls somewhere between good and poor style.

[4-5] Your code is very easy to read and is well documented.

__MACOSX/PA5/._PA5.docx

PA5/String.h

#ifndef STRING_H #define STRING_H #include <ostream> #include <istream> #include <string> using namespace std; class String { public: //Basic empty constructor. String() { } //Constructor that takes a string literal, e.g. "this is a string literal" //and converts it into our String type. String(char *text) { } //Constructor that takes a C++ string and converts it into our String type. String(string text) { } //Copy constructor that makes a perfect copy of an existing String type. String(const String& to_copy) { } //Move constructor that assumes ownership of a temporary (r-value) String type. String(String &&to_move) { } //Cleans up any dynamic memory that you may have allocated. Note: depending //on your implementation, this may empty. virtual ~String() { } //Returns the length of our String int getLength() { return 0; } //Returns the set of characters, as a String type, that exist between start and start + length. //If start + length is longer than the String, return all characters up to the end of the string. String subString(int start, int length) { return String{}; } //Returns the index of the first occurance of toFind at or after the supplied starting location int find(String toFind, int start = 0) { return 0; } //Replaces any bits matching toFind with toReplace at or after the supplied starting location. int replace(String toFind, String toReplace, int start = 0) { return 0; } //Returns an upper case-only string version of us String toUpper() { return String{}; } //Returns a lower-case only string version of us String toLower() { return String{}; } //Copy operator. Makes a perfect copy of to_copy. String& operator=(const String& to_copy) { return *this; } //Move operator. Assumes ownership of to_move String& operator=(String&& to_move) { return *this; } //Returns the character at the given index in our String. virtual char& operator[](int index) { char c = '\0'; return c; } //Returns the character at the given index in our String. Code Will be exactly the //same as the function above. virtual const char& operator[](int index) const { char c = '\0'; return c; } //Compares two strings. Returns true if lhs < rhs, false otherwise. Comparisons //should be in dictionary order. friend bool operator<(const String &lhs, const String &rhs) { return false; } //Compares two strings. Returns true if lhs > rhs, false otherwise. Comparisons //should be in dictionary order. friend bool operator>(const String &lhs, const String &rhs) { return false; } //Compares two strings. Returns true if lhs >= rhs, false otherwise. Comparisons //should be in dictionary order. friend bool operator>=(const String &lhs, const String &hrs) { return false; } //Compares two strings. Returns true if lhs <= rhs, false otherwise. Comparisons //should be in dictionary order. friend bool operator<=(const String &lhs, const String &rhs) { return false; } //Returns true if lhs == rhs. Comparisons //should be in dictionary order. friend bool operator==(const String &lhs, const String &rhs) { return false; } //String concatination. Returns as a new string the combination of lhs and rhs. friend String operator+(const String &lhs, const String &rhs) { return String{}; } //String concatination. Returns as a new string the combination of lhs and rhs. friend String operator+=(const String &lhs, const String &rhs) { return String{}; } //Allows our String to be used easily with cout friend ostream& operator<<(ostream &out, const String &some_string) { return out; } //Allows our string to be used easily from cin friend istream& operator>>(istream &in, const String &some_string) { return in; } }; #endif // STRING_H

__MACOSX/PA5/._String.h