-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustom_String_Class.h
More file actions
89 lines (63 loc) · 2.55 KB
/
Custom_String_Class.h
File metadata and controls
89 lines (63 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Created by tarek on 4/5/2024.
#ifndef PROJECT_CUSTOM_STRING_CLASS_H
#define PROJECT_CUSTOM_STRING_CLASS_H
#include <iostream>
using namespace std;
// Custom_String_Class definition
class Custom_String_Class {
private:
char *str; // Pointer to the character array that holds the string
public:
// Default constructor
Custom_String_Class();
// Constructor that takes a C-style string
Custom_String_Class(char * s);
// Constructor that takes a C++ string
Custom_String_Class(const string& s);
// Overloaded addition operator for concatenating two strings
Custom_String_Class operator+(const Custom_String_Class& s);
// Overloaded assignment operator for C-style strings
Custom_String_Class& operator=(const char *);
// Overloaded equality operator for comparing two strings
bool operator==(const Custom_String_Class& s2) const;
// Overloaded inequality operator for comparing two strings
bool operator!=(const Custom_String_Class& s2) const;
// Overloaded subscript operator for accessing characters in the string
char operator[](int) const;
// Overloaded stream insertion operator for outputting the string
friend ostream& operator<<(std::ostream& out, const Custom_String_Class& c){
out << c.str;
return out;
}
// Overloaded stream extraction operator for inputting the string
friend istream& operator>>(istream& is, Custom_String_Class& obj) {
char* buffer = new char[256];
is.getline(buffer, 256);
obj = Custom_String_Class(buffer);
delete[] buffer;
return is;
}
// Function to get the C-style string
char * getSTR() const;
// Function to change the case of a character
char reverseCase(char c);
// Function to display the string
void display() const;
// Function to find a substring in the string
bool find(Custom_String_Class& s);
// Function to get the length of the string
int strlength () const;
// Function to compare two strings
int strcompare (const Custom_String_Class& s) const;
// Function to copy a string
char* strcpy(char*,const char*);
// Function to concatenate a string
char* strcat(char*,const char*);
// Function to get the length of a C-style string
static int strlen(const char*);
// Function to convert the C-style string to a C++ string
string toString();
// Destructor
~Custom_String_Class();
};
#endif //PROJECT_CUSTOM_STRING_CLASS_H