C++ homework about strings

profileManarQu
string.zip

string/.DS_Store

__MACOSX/string/._.DS_Store

string/log_1_tiny.txt

131.123.47.176 - - [18/Sep/2002:12:05:25 -0400] "GET /~darci/ HTTP/1.0" 200 5625

__MACOSX/string/._log_1_tiny.txt

string/log_2_small.txt

131.123.47.176 - - [18/Sep/2002:12:05:25 -0400] "GET /~darci/ HTTP/1.0" 200 5625 198.143.205.166 - - [18/Sep/2002:12:06:06 -0400] "GET /~reichel/b.jpg HTTP/1.1" 200 16514 24.203.197.200 - - [18/Sep/2002:12:06:46 -0400] "GET /~jkuleck/bannerbar.gif HTTP/1.1" 304 - 4.19.70.66 - - [18/Sep/2002:12:07:34 -0400] "GET /~ydrabu/ HTTP/1.0" 200 483

__MACOSX/string/._log_2_small.txt

string/logentry.cpp.txt

// // // File: logentry.cpp // // Version: 1.0 // Date: // Author: // // Description: Class implementation for a log entry. // // //////////////////////////////////////////////////////////// #include <iostream> #include <vector> #include "string.hpp" #include "logentry.hpp" ////////////////////////////////////////////////////////// // REQUIRES: // ENSURES: // LogEntry::LogEntry(String s) { // ... std::vector<String> vec = s.split(' '); } ////////////////////////////////////////////////////////// // REQUIRES: // ENSURES: // std::vector<LogEntry> parse(std::istream& in) { std::vector<LogEntry> result; return result; } ////////////////////////////////////////////////////////// // REQUIRES: // ENSURES: // void output_all(std::ostream& out, const std::vector<LogEntry> &) { } ////////////////////////////////////////////////////////// // REQUIRES: // ENSURES: // void by_host(std::ostream& out, const std::vector<LogEntry>&) { } ////////////////////////////////////////////////////////// // REQUIRES: // ENSURES: // int byte_count(const std::vector<LogEntry> &) { return 0; }

__MACOSX/string/._logentry.cpp.txt

string/logentry.hpp.txt

#ifndef CS_LOGENTRY_H_ #define CS_LOGENTRY_H_ //////////////////////////////////////////////////////////// // // File: logentry.hpp // // Version: 1.0 // Date: // Author: // // Description: Class definition for a log entry. // // // //////////////////////////////////////////////////////////// #include <iostream> #include <vector> #include "string.hpp" //////////////////////////////////////////////////////////// class Date { public: Date() {}; private: String day, month; int year; }; //////////////////////////////////////////////////////////// class Time { public: Time() {}; private: int hour, minute, second; }; //////////////////////////////////////////////////////////// class LogEntry { public: LogEntry() {}; LogEntry(String); friend std::ostream& operator<<(std::ostream&, const LogEntry&); private: String host; Date date; Time time; String request; String status; int number_of_bytes; }; //////////////////////////////////////////////////////////// // // Free functions // std::vector<LogEntry> parse (std::istream&); void output_all (std::ostream&, const std::vector<LogEntry> &); void by_host (std::ostream&, const std::vector<LogEntry> &); int byte_count (const std::vector<LogEntry>&); #endif

__MACOSX/string/._logentry.hpp.txt

string/logview.cpp.txt

// File: main.cpp // // Version: 1.0 // Date: // Author: // // Description: Main body for logview application // //////////////////////////////////////////////////////////// #include <cstdlib> #include <iostream> #include <fstream> #include <vector> #include "string.hpp" #include "logentry.hpp" //////////////////////////////////////////////////////////// void output_usage_and_exit(const char cmd[], const std::vector<String>& opts); //////////////////////////////////////////////////////////// int main(int argc, char *argv[]) { // Options std::vector<String> opt(3); opt[0] = "all"; opt[1] = "bytes"; opt[2] = "host"; // Error if there are not 3 things on the command line if (argc != 3) { output_usage_and_exit(argv[0], opt); } // Open file, quit if open fails std::ifstream in(argv[2]); if (!in) { std::cerr << "Couldn't open " << argv[2] << "\n"; exit(2); } // Process the log file std::vector<LogEntry> log_entries = parse(in); // We're done with the file in.close(); // Handle the specified option String option(argv[1]); if (option == opt[0]) { // Output everything output_all(std::cout, log_entries); } else if (option == opt[1]) { // Output total number of bytes std::cout << "Total number of bytes sent: " << byte_count(log_entries) << std::endl; } else if (option == opt[2]) { // Output host names only by_host(std::cout, log_entries); } else { //Error, bad option std::cerr << "Unrecognized option: " << option << std::endl; std::cerr << "Recognized options: " << opt[0] << " " << opt[1] << " " << opt[2] << std::endl; } // Return success return 0; } //////////////////////////////////////////////////////////// void output_usage_and_exit(const char cmd[], const std::vector<String>& opt) { // Output usage message std::cerr << "Usage: " << cmd << " ["; for (std::vector<String>::size_type idx = 0; idx < opt.size() - 1; ++idx) std::cerr << opt[idx] << " | "; std::cerr << opt[opt.size() - 1] << "] log_file\n"; // Exit with error exit(1); }

__MACOSX/string/._logview.cpp.txt

string/Makefile.txt

############################################################### # String & Oracle # # CS II Kent State University # Make file for string class and testing oracle # J. Maletic Fall 2016 # # ############################################################### # Variables CPP = clang++ OPTIONS = -g -Wall -W -Wunused -Wuninitialized -Wshadow -std=c++11 # Names of your test files - add them in as you build them. # Names must start with "test_" Also add here MYTESTS = test_default_ctor test_ctor_charArray # Names of test oracle files CTOR = testoracle_ctor_default testoracle_ctor_char testoracle_ctor_charArray REL = testoracle_equal testoracle_lessThan COPY = testoracle_ctor_copy testoracle_assign OPS = testoracle_concat ############################################################### # Compile just the string # Compile and run all provided test oracles on string # Compile and run all your tests on string # Compile and run the project msg: @echo 'Targets are:' @echo ' string' @echo ' tests' @echo ' oracle' @echo ' logview' @echo ' clean' ############################################################### # Compile string # string: string.hpp string.cpp $(CPP) -c $(OPTIONS) string.cpp -o string.o ############################################################### # Run all of your tests # # You will need to ADD your other below: # For example: ./test_plus #add here your tests tests: $(MYTESTS) ./test_default_ctor ./test_c_str_ctor #ADD YOUR TESTS HERE *************** ############################################################### # Compile all test programs # test_%: string.o test_%.o $(CPP) string.o test_$*.o -o test_$* test_%.o: string.hpp test_%.cpp $(CPP) $(OPTIONS) -c test_$*.cpp ############################################################### # Run test oracle # Comment out one's you don't want to run. # oracle: $(CTOR) $(REL) $(COPY) $(OPS) ./testoracle_ctor_default ./testoracle_ctor_char ./testoracle_ctor_charArray ./testoracle_equal ./testoracle_lessThan ./testoracle_ctor_copy ./testoracle_assign ./testoracle_concat ############################################################### # Compile all test programs # testoracle_%: string.o testoracles/testoracle_%.o $(CPP) string.o testoracles/testoracle_$*.o -o testoracle_$* ############################################################### # Compile Project # logview.o: logview.cpp logentry.hpp string.hpp $(CPP) -c $(OPTIONS) logview.cpp -o logview.o logentry.o: logentry.cpp logentry.hpp string.hpp $(CPP) -c $(OPTIONS) logentry.cpp -o logentry.o logview: logview.o string.o logentry.o $(CPP) $(OPTIONS) logview.o string.o logentry.o -o logview ############################################################### # clean # Removes all .o files and all executables # clean: rm -f *.o rm -f $(CTOR) $(REL) $(COPY) $(OPS) rm -f $(MYTESTS) rm -f logview

__MACOSX/string/._Makefile.txt

string/string-mile1.hpp.txt

//File: string-interface.hpp // //Version: 1.0 //Date: Fall 2017 //Author: Dr. J. Maletic // //Description: Interface definition of String class for Project 2, milestone 1. // // To use the supplied test oracles you will need to use this interface and namings. // You must also have all of these methods and functions defined for your string class. // // You will either have use this interface or call your methods through this interface. // // You need to implement all of the methods and funcitons declared here. // #ifndef CS23001_STRING_INTERFACE_HPP #define CS23001_STRING_INTERFACE_HPP #include <iostream> const int STRING_SIZE = 256; //The size of the array. //////////////////////////////////////////////////// // CLASS INV: str[length()] == 0 // && 0 <= length() <= capacity() // && capacity() == STRING_SIZE - 1 // // class String { public: String (); //Empty string String (char); //Stirng('x') String (const char[]); //String("abcd") char& operator[] (int); //Accessor/Modifier char operator[] (int) const; //Accessor int capacity () const; //Max chars that can be stored (not including null terminator) int length () const; //Number of char in string String operator+ (const String&) const; //Concatenation String& operator+= (String); //Concatenation bool operator== (const String&) const; bool operator< (const String&) const; String substr (int, int) const; int findch (int, char) const; int findstr (int, const String&) const; friend std::istream& operator>>(std::istream&, String&); friend std::ostream& operator<<(std::ostream&, const String&); private: char str[STRING_SIZE]; }; String operator+ (const char[], const String&); String operator+ (char, const String&); bool operator== (const char[], const String&); bool operator== (char, const String&); bool operator< (const char[], const String&); bool operator< (char, const String&); bool operator<= (const String&, const String&); bool operator!= (const String&, const String&); bool operator>= (const String&, const String&); bool operator> (const String&, const String&); #endif

__MACOSX/string/._string-mile1.hpp.txt

string/string-mile2.hpp.txt

////////////////////////////////////////////////////////////////////////////// //File: string-interface.hpp // //Version: 1.0 //Date: Fall 2017 //Author: Dr. J. Maletic // //Description: Interface definition of String class for use with test oracle. // For use with Project 2, milestone 2, 3, 4. // // To use the supplied test oracles you will need to use this interface and namings. // You must also have all of these methods and functions defined for your string class. // // You can NOT add any attributes/members. If you do the test oracles will not work. // // You need to implement all of the methods and funcitons declared here. // #ifndef CS23001_STRING_INTERFACE_HPP #define CS23001_STRING_INTERFACE_HPP #include <iostream> //////////////////////////////////////////////////// // CLASS INV: str[length()] == 0 && // length() == capacity() && // capacity() == stringSize - 1 // // class String { public: String (); //Empty string String (char); //String('x') String (const char[]); //String("abc") String (const String&); //Copy Constructor. ~String (); //Destructor void swap (String&); String& operator= (String); //Assignment Copy. char& operator[] (int); //Accessor/Modifier. char operator[] (int) const; //Accessor int capacity () const; //Max chars that can be stored (not including null) int length () const; //Actual number of chars in string String operator+ (const String&) const; String& operator+= (String); bool operator== (const String&) const; bool operator< (const String&) const; String substr (int, int) const; int findch (int, char) const; int findstr (int, const String&) const; friend std::ostream& operator<<(std::ostream&, const String&); friend std::istream& operator>>(std::istream&, String&); private: String (int); //String of capacity n String (int, const char*); //String of capacity n and initial value void resetCapacity (int); //Sets new capacity to be n. char *str; int stringSize; //Size includes NULL terminator }; String operator+ (const char*, const String&); String operator+ (char, const String&); bool operator== (const char*, const String&); bool operator== (char, const String&); bool operator< (const char*, const String&); bool operator< (char, const String&); bool operator<= (const String&, const String&); bool operator!= (const String&, const String&); bool operator>= (const String&, const String&); bool operator> (const String&, const String&); #endif

__MACOSX/string/._string-mile2.hpp.txt

string/string.hpp.txt

//File: string-interface.hpp // //Version: 1.0 //Date: Fall 2017 //Author: Dr. J. Maletic // //Description: Interface definition of String class for Project 2, milestone 1. // // To use the supplied test oracles you will need to use this interface and namings. // You must also have all of these methods and functions defined for your string class. // // You will either have use this interface or call your methods through this interface. // // You need to implement all of the methods and funcitons declared here. // #ifndef CS23001_STRING_INTERFACE_HPP #define CS23001_STRING_INTERFACE_HPP #include <iostream> const int STRING_SIZE = 256; //The size of the array. //////////////////////////////////////////////////// // CLASS INV: str[length()] == 0 // && 0 <= length() <= capacity() // && capacity() == STRING_SIZE - 1 // // class String { public: String (); //Empty string String (char); //Stirng('x') String (const char[]); //String("abcd") char& operator[] (int); //Accessor/Modifier char operator[] (int) const; //Accessor int capacity () const; //Max chars that can be stored (not including null terminator) int length () const; //Number of char in string String operator+ (const String&) const; //Concatenation String& operator+= (String); //Concatenation bool operator== (const String&) const; bool operator< (const String&) const; String substr (int, int) const; int findch (int, char) const; int findstr (int, const String&) const; friend std::istream& operator>>(std::istream&, String&); friend std::ostream& operator<<(std::ostream&, const String&); private: char str[STRING_SIZE]; }; String operator+ (const char[], const String&); String operator+ (char, const String&); bool operator== (const char[], const String&); bool operator== (char, const String&); bool operator< (const char[], const String&); bool operator< (char, const String&); bool operator<= (const String&, const String&); bool operator!= (const String&, const String&); bool operator>= (const String&, const String&); bool operator> (const String&, const String&); #endif

__MACOSX/string/._string.hpp.txt

string/test_generic_binary_op.cpp.txt

// String class test program // // Name: XXX // Tests: XXX // #include "string.hpp" #include <cassert> #include <iostream> //=========================================================================== int main () { { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } { //------------------------------------------------------ // SETUP FIXTURE String left(X); String right(X); // TEST RESULT_TYPE result = (left OP right); // VERIFY assert(result == X); assert(left == X); assert(right == X); } // ADD ADDITIONAL TESTS AS NECESSARY std::cout << "Done testing XXX." << std::endl; }

__MACOSX/string/._test_generic_binary_op.cpp.txt

string/test_generic_ctor.cpp.txt

// String class test program // // Tests: XXX // #include "string.hpp" #include <cassert> #include <iostream> //=========================================================================== int main () { { //------------------------------------------------------ // SETUP FIXTURE // TEST String str(X); // VERIFY assert(str == YYY); } { //------------------------------------------------------ // SETUP FIXTURE // TEST String str(X); // VERIFY assert(str == YYY); } { //------------------------------------------------------ // SETUP FIXTURE // TEST String str(X); // VERIFY assert(str == YYY); } { //------------------------------------------------------ // SETUP FIXTURE // TEST String str(X); // VERIFY assert(str == YYY); } { //------------------------------------------------------ // SETUP FIXTURE // TEST String str(X); // VERIFY assert(str == YYY); } // ADD ADDITIONAL TESTS AS NECESSARY std::cout << "Done testing XXX." << std::endl; }

__MACOSX/string/._test_generic_ctor.cpp.txt

string/test_generic_member_function_return.cpp.txt

// String class test program // // Tests: XXX // #include "string.hpp" #include <cassert> #include <iostream> //=========================================================================== int main () { { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST RESULT_TYPE result = str.OP(); // VERIFY assert(str == X); assert(result == X); } // ADD ADDITIONAL TESTS AS NECESSARY std::cout << "Done testing XXX." << std::endl; }

__MACOSX/string/._test_generic_member_function_return.cpp.txt

string/test_generic_member_function_void.cpp.txt

// String class test program // // Tests: XXX // #include "string.hpp" #include <cassert> #include <iostream> //=========================================================================== int main () { { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } { //------------------------------------------------------ // SETUP FIXTURE String str(X); // TEST str.OP(); // VERIFY assert(XXX == YYY); } // ADD ADDITIONAL TESTS AS NECESSARY std::cout << "Done testing XXX." << std::endl; }

__MACOSX/string/._test_generic_member_function_void.cpp.txt