[Solved] C++ Programming Homework 3

$25

File Name: C++_Programming_Homework_3.zip
File Size: 244.92 KB

SKU: [Solved] C++ Programming Homework 3 Category: Tag:
5/5 - (1 vote)

5/5 – (2 votes)

(80 points) Write a String class which will be a wrapper class to the C style strings. The strings will be of varying lengths and must grow and shrink as necessary. Your String class must implement all the appropriate methods including constructors, assignment, equality operators, the index operator, reverse, indexOf (find), print, and read. I would prefer you not use any of the C str functions (e.g. strcmp, or strcpy), however you may write them yourself, as static methods, then use them.

Class String declaration:class String{public:/// Both constructors should construct/// this String from the parameter sString( const char * s = );String( const String & s );String operator = ( const String & s );char & operator [] ( int index );int size();String reverse(); // does not modify this Stringint indexOf( char c );int indexOf( String pattern );bool operator == ( String s );bool operator != ( String s );bool operator ( String s );bool operator < ( String s )bool operator <= ( String s );bool operator = ( String s );/// concatenates this and s to return resultString operator + ( String s );/// concatenates s onto end of thisString operator += ( String s );void print( ostream & out );void read( istream & in );~String();private:bool inBounds( int i ){return i = 0 && i < len;}char * buf;int len;};ostream & operator << ( ostream & out, String str );istream & operator ( istream & in, String & str );

(20 points) Write a main function which tests each function defined in your class String.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] C++ Programming Homework 3
$25