Data Structure
Data Structure
Fakultə: Mühəndislik
Kafedra: Kompüter və İnformasiya Texnologiyaları
İxtisas: İnformasiya texnologiyaları(İNHA)
Fərdi fəaliyyət
« Problems with string data types and solutions »
mövzusu üzrə
HESABAT
(imza,tarix)
BMU-2022
CONTENTS
I What is String?………………………………………..…....................3
Code/Explanation………………………………....………....6
Code/Explanation…………………………………………....8
Code/Explanation…………………………………………....10
Code/Explanation…………………………………………....12
Code/Explanation…………………………………………....14
Conclusion…………………………………………………………...…..16
References………………………………………………………………..16
2
I What is String ?
1.1 What is string in programming ?
In computer programming, a string is traditionally a sequence of characters, either as
a literal constant or as some kind of variable. The latter may allow its elements to be
mutated and the length changed, or it may be fixed (after creation). A string is
generally considered as a data type and is often implemented as an array data
structure of bytes (or words) that stores a sequence of elements, typically characters,
using some character encoding. String may also denote more general arrays or other
sequence (or list) data types and structures.
1.1.1What is ASCII ?
While solving string related problems sometimes we use ASCII table . Lets see
what is ASCII :
ASCII, in full American Standard Code for Information Interchange, a standard data-
encoding format for electronic communication between computers. ASCII assigns
standard numeric values to letters, numerals, punctuation marks, and other characters
used in computers.
3
1.2 How we use strings in C++?
C++ has in its definition a way to represent a sequence of characters as an object of
the class. This class is called std:: string. The string class stores the characters as a
sequence of bytes with the functionality of allowing access to the single-byte
character.
To use strings, you must include an additional header file in the source code,
the <string> library:
1) Input functions :
4
2) Capacity Functions :
capacity() - This function returns the capacity allocated to the string, which
can be equal to or more than the size of the string. Additional space is allocated
so that when the new characters are added to the string, the operations can be
done efficiently.
resize() - This function changes the size of the string, the size can be increased
or decreased.
3) Iterator Functions :
end() - This function returns an iterator to the next to the end of the string.
4) Manipulating Functions:
copy(“char array”, len, pos) - This function copies the substring in the target
character array mentioned in its arguments. It takes 3 arguments, target char
array, length to be copied, and starting position in the string to start copying.
5
II Problems related string data types
2.1 Problem No 1:
Problem No1 :
Palindrome is a sequence of characters that reads the same backwards as well as
forwards. Find out whether the given text is a palindrome. Do not forget that space is
not pronounced when reading.
Input format:
String S (|S| ≤ 1000) consists of small Latin letters and spaces. |S| means the length of
a string.
Code:
6
Inputs and outputs :
Explanation :
On these code we get our text without spaces and fill our string array with this
letters.After that we check from front and back of our string . If we face any trouble
while checking we will return FALSE. On the other hand our code will check till end
and return YES.
2.2 Problem No 2:
7
Problem 2 :
Input format:
Flowchart :
8
Code :
Explanation :
After got input , we check if our first letter or letter that previous symbol is gap we
capitalize this char.And at the end we output our capitalized string .
9
2.3 Problem No 3:
Problem 3 :
Input format:
Explanation :
First we get string .Check if it is digit we check next to it .While next to this integer is
digit we add all this digits to string. And at the end we change type of this string to
integer and add to sum_num.
10
Code:
11
2.4 Problem No 4:
Problem 4 :
Given a string . Write a C++ program to count all the vowels in a given
string.Vowels(a,e,i,o,u).
Input format:
Flowchart:
12
Code :
Explanation :
We get string using Vowel_Count function . Then we count characters that vowel
letter (a,i,e,o,u). And at the end of program we return counted value.
13
2.4 Problem No 5:
Problem 5 :
Input format:
Code :
14
Inputs and Outputs:
Input 1: Output 1:
bakuengineeringuniversity ytisrevinugnireenigneukab
Input 2: Output 2:
Nabi ibaN
Explanation :
We create same string as input . And from starting end of second string we equalate
our main strings beginning elements . At the end our string reverse.
15
Conclusion :
The ability to format and manipulate Excel character strings is extremely important
for data analysis. SQL String functions are useful for querying and manipulating
data.Also string functions used in AI based chat-bots.
As you see, strings and string type functions are one of the most important topic in
programming . Todays world most of technology branchs uses string type functions
to solve their problem.
References:
https://www.w3resource.com/cpp-exercises/string/index.php
https://www.eolymp.com/en/
https://www.w3schools.com/cpp/cpp_data_types_string.asp
https://www.geeksforgeeks.org/stdstring-class-in-c/
https://cplusplus.com/reference/string/string/
16