Skip to content

Commit 088f93a

Browse files
Create README.md
1 parent a658d75 commit 088f93a

File tree

1 file changed

+159
-0
lines changed
  • Design_Principles/SOLID/SRP/USECASE2

1 file changed

+159
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# ArrayListManager Example
2+
3+
This repository contains a simple C++ program that demonstrates the functionality of the `ArrayListManager` class, which splits strings based on a given delimiter. The program takes input strings, applies the delimiter, and stores the resulting substrings in a vector. Several test cases are provided to showcase how different input strings and delimiters are handled.
4+
5+
## Table of Contents
6+
7+
- [Introduction](#introduction)
8+
- [How It Works](#how-it-works)
9+
- [Class Definition](#class-definition)
10+
- [Test Cases](#test-cases)
11+
- [Compilation and Execution](#compilation-and-execution)
12+
- [Output](#output)
13+
- [Contributing](#contributing)
14+
- [License](#license)
15+
16+
## Introduction
17+
18+
The `ArrayListManager` class splits input strings into substrings based on a specified delimiter. If the string contains the delimiter, it will be divided into separate substrings and returned as a vector. Otherwise, the original string is stored as a single element in the vector.
19+
20+
This example program showcases the use of the class with different strings and delimiters, demonstrating how the class handles both valid and edge cases.
21+
22+
## How It Works
23+
24+
1. **Input**: The user provides a string and a delimiter (e.g., ',', '|', ';').
25+
2. **Processing**: The `ArrayListManager::AddString` function splits the string based on the delimiter and returns a vector of substrings.
26+
3. **Output**: The program prints each substring from the resulting vector.
27+
28+
## Class Definition
29+
30+
### `ArrayListManager`
31+
32+
```cpp
33+
class ArrayListManager {
34+
public:
35+
std::vector<std::string> AddString(std::string inputString, char delimiter) {
36+
std::vector<std::string> list;
37+
if (inputString.empty()) {
38+
return list;
39+
}
40+
if (inputString.find(delimiter) != std::string::npos) {
41+
std::stringstream ss(inputString);
42+
std::string value;
43+
while (getline(ss, value, delimiter))
44+
list.push_back(value);
45+
} else
46+
list.push_back(inputString);
47+
return list;
48+
}
49+
};
50+
```
51+
The AddString function does the following:
52+
53+
- If the input string is empty, it returns an empty vector.
54+
- If the string contains the delimiter, it splits the string and stores each substring into the vector.
55+
- If the delimiter is not present, the entire input string is added to the vector as a single element.
56+
57+
## Test Cases
58+
59+
The program includes 10 test cases to demonstrate the versatility of the ArrayListManager class with different input strings and delimiters.
60+
61+
Example Test Cases
62+
1. Input: "apple,banana,cherry", Delimiter: ','
63+
2. Input: "red|green|blue", Delimiter: '|'
64+
3. Input: "1;2;3;4", Delimiter: ';'
65+
4. Input: "Hello, world!", Delimiter: ' '
66+
5. Input: "", Delimiter: ','
67+
6. Input: "1-2-3-4-5", Delimiter: '-'
68+
7. Input: "car;bus;train;plane", Delimiter: ';'
69+
8. Input: "1", Delimiter: ','
70+
9. Input: "1,2,3,4,5,6,7,8,9,10", Delimiter: ','
71+
10. Input: "cat,dog,bird", Delimiter: ' '
72+
73+
Each test case will print the resulting list of substrings.
74+
75+
## Compilation and Execution
76+
77+
### Steps to compile and run the code:
78+
1. Ensure you have a C++ compiler installed (e.g., g++).
79+
2. Download or clone the repository.
80+
3. Compile the code using the following command:
81+
82+
```
83+
bash
84+
g++ -o array_list_manager array_list_manager.cpp
85+
```
86+
4. Run the program:
87+
```
88+
bash
89+
./array_list_manager
90+
```
91+
92+
## Output
93+
94+
The program outputs the following for each test case:
95+
```
96+
List 1:
97+
apple
98+
banana
99+
cherry
100+
101+
List 2:
102+
red
103+
green
104+
blue
105+
106+
List 3:
107+
1
108+
2
109+
3
110+
4
111+
112+
List 4:
113+
Hello,
114+
world!
115+
116+
List 5:
117+
118+
List 6:
119+
1
120+
2
121+
3
122+
4
123+
5
124+
125+
List 7:
126+
car
127+
bus
128+
train
129+
plane
130+
131+
List 8:
132+
1
133+
134+
List 9:
135+
1
136+
2
137+
3
138+
4
139+
5
140+
6
141+
7
142+
8
143+
9
144+
10
145+
146+
List 10:
147+
cat,dog,bird
148+
```
149+
150+
## Contributing
151+
152+
Contributions are welcome! If you have any suggestions or improvements, feel free to open an issue or submit a pull request.
153+
154+
## License
155+
156+
This project is licensed under the MIT License - see the LICENSE file for details.
157+
```
158+
This `README.md` file provides a clear explanation of the program, including how to compile and run it, as well as examples of its output for various test cases.
159+
```

0 commit comments

Comments
 (0)