Skip to content

Commit 46ed5b2

Browse files
committed
Section 08: Added Output
1 parent 4348d02 commit 46ed5b2

6 files changed

+204
-9
lines changed

08_strings/01_string_basic.cpp

+45-4
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ int main(){
3838
// Taking Input -------------------------------------------------
3939

4040
char ch1[100]; // character
41-
cout << "Enter elements for character array: ";
41+
cout << "Enter elements for 1D character array: ";
4242
cin >> ch1;
43+
// cin.getline(ch1, 100);
4344
cout << ch1 << "\n\n";
4445

4546

4647
string str1; // string
4748
cout << "Enter elements for string: ";
4849
cin >> str1;
50+
// getline(cin, str1);
4951
cout << str1 << "\n\n";
5052

5153
cin.get(); // to consume extra "\n"
5254

5355

5456
char ch2[10][100]; // 2D character Array (10 Rows)
55-
cout << "Enter character array (Row-1): ";
57+
cout << "Enter 2D character array (Row-1): ";
5658
cin.getline(ch2[0], 100);
5759
cout << ch2[0] << endl;
58-
cout << "Enter character array (Row-2): ";
60+
cout << "Enter 2D character array (Row-2): ";
5961
cin.getline(ch2[1], 100);
6062
cout << ch2[1] << "\n\n";
6163

@@ -69,4 +71,43 @@ int main(){
6971
cout << str2[1] << endl;
7072

7173
return 0;
72-
}
74+
}
75+
76+
/*
77+
OUTPUT:
78+
79+
c1: Hi
80+
c1[0]: H
81+
c1[1]: i
82+
83+
s0: Hi
84+
s0[0]: H
85+
s0[1]: i
86+
87+
s1: 0x7ffe6cd70620
88+
s1[0]: Shyam
89+
s1[1]: Ram Sharma
90+
s1[1][0]: R
91+
s1[1][1]: a
92+
s1[1][3]: m
93+
94+
s2: 0x7ffe6cd70660
95+
s2[0]: first row
96+
s2[1]: second row
97+
98+
Enter elements for 1D character array: Hello
99+
Hello
100+
101+
Enter elements for string: Hello
102+
Hello
103+
104+
Enter 2D character array (Row-1): Ravi Sharma
105+
Ravi Sharma
106+
Enter 2D character array (Row-2): Aksh Verma
107+
Aksh Verma
108+
109+
Enter your string (Row-1): Ravi Sharma
110+
Ravi Sharma
111+
Enter your string (Row-2): Aksh Verma
112+
Aksh Verma
113+
*/

08_strings/02_string_class.cpp

+56-1
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,59 @@ int main(){
125125
cout << endl;
126126

127127
return 0;
128-
}
128+
}
129+
130+
/*
131+
OUTPUT:
132+
133+
s0:
134+
s1: Hello
135+
s2: Hello World
136+
s3: Hello World
137+
s4: Hello World
138+
s5: abcd
139+
140+
s5: string length- 4
141+
142+
s0 is an Empty string
143+
144+
s0: I love c++
145+
s0: I love c++and javascript
146+
147+
s0: I love c++and javascript
148+
s0: length before removing- 24
149+
s0:
150+
s0: length after removing- 0
151+
152+
Comparing string lexically: s1: apple | s2: mango
153+
s1.compare(s2): -1
154+
s2.compare(s1): 1
155+
s1.compare(s1): 0
156+
157+
s1: apple | s2: mango
158+
s1<s2: mango is lexicographic greater than apple
159+
160+
s1: apple
161+
s1[3]: l
162+
163+
s1: I want to have orange juice
164+
index of 'orange': 15
165+
166+
s1: I want to have orange juice
167+
s1: I want to have juice
168+
169+
170+
Using FOR loop: I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
171+
172+
FOR loop (using 'auto): I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
173+
174+
175+
Using Iterator: I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
176+
177+
Iterator (using auto): I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
178+
179+
180+
FOR EACH loop: I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
181+
182+
FOR EACH loop (using 'auto'): I, ,w,a,n,t, ,t,o, ,h,a,v,e, , ,j,u,i,c,e,
183+
*/

08_strings/03_sorting.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int main(){
2222

2323
string s[100];
2424

25+
cout << "Enter Strings: \n";
2526
for(int seq=0; seq <= totalStr-1; seq++){
2627
getline(cin,s[seq]);
2728
}
@@ -33,4 +34,26 @@ int main(){
3334
cout << s[seq] << endl;
3435
}
3536
return 0;
36-
}
37+
}
38+
39+
/*
40+
OUTPUT:
41+
42+
Enter total number of strings: 6
43+
44+
Enter Strings:
45+
Amandeep Verma
46+
deep
47+
aman
48+
Govind
49+
Arvind
50+
Bhim Gupta
51+
52+
After Sorting:
53+
aman
54+
deep
55+
Arvind
56+
Govind
57+
Bhim Gupta
58+
Amandeep Verma
59+
*/

08_strings/04_tokenization_using_strtok.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ int main(){
2424
cout << ptr << endl;
2525
}
2626
return 0;
27-
}
27+
}
28+
29+
/*
30+
OUTPUT:
31+
32+
Today
33+
is
34+
a
35+
rainy
36+
day
37+
*/

08_strings/05_designing_string_tokeniser.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,14 @@ int main(){
5151
cout << ptr << endl;
5252
}
5353
return 0;
54-
}
54+
}
55+
56+
/*
57+
OUTPUT:
58+
59+
Today
60+
is
61+
a
62+
rainy
63+
day
64+
*/

08_strings/06_string_challenge_sort_variation.cpp

+57-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,60 @@ int main(){
110110
}
111111

112112
return 0;
113-
}
113+
}
114+
115+
/*
116+
OUTPUT:
117+
Case1:
118+
Enter total no of strings: 3
119+
120+
Enter strings (Eg: 28 12 89):
121+
28 12 899 44
122+
17 65 456 78
123+
56 71 598 12
124+
125+
Enter column number for sorting: 3
126+
Want to Reverse string (true/false): false
127+
Enter Comparision Type (numeric/lexicographic): numeric
128+
129+
After sorting:
130+
17 65 456 78
131+
56 71 598 12
132+
28 12 899 44
133+
134+
Case2:
135+
Enter total no of strings: 4
136+
137+
Enter strings (Eg: 28 12 89):
138+
17 65
139+
44 56
140+
32 47
141+
88 05
142+
143+
Enter column number for sorting: 1
144+
Want to Reverse string (true/false): true
145+
Enter Comparision Type (numeric/lexicographic): numeric
146+
147+
After sorting:
148+
88 05
149+
44 56
150+
32 47
151+
17 65
152+
153+
Case3:
154+
Enter total no of strings: 3
155+
156+
Enter strings (Eg: 28 12 89):
157+
121 45
158+
129 68
159+
120 48
160+
161+
Enter column number for sorting: 1
162+
Want to Reverse string (true/false): false
163+
Enter Comparision Type (numeric/lexicographic): lexicographic
164+
165+
After sorting:
166+
120 48
167+
121 45
168+
129 68
169+
*/

0 commit comments

Comments
 (0)