You are on page 1of 16

AZƏRBAYCAN RESPUBLİKASI TƏHSİL NAZİRLİYİ

Bakı Mühəndislik Universiteti

Fakultə: Mühəndislik
Kafedra: Kompüter və İnformasiya Texnologiyaları
İxtisas: İnformasiya texnologiyaları(İNHA)

Hesabat qəbul edilir:


Qiymət (Bal)
kafedranın baş müəllimi

Həsənov Əli Vahid


(imza,tarix) (S.A.A)

Fənn: « Data Strukturu »

Fərdi fəaliyyət
« Problems with string data types and solutions »
mövzusu üzrə

HESABAT

2 kurs tələbəsi : Şirinov Nəbi Namiq


(S.A.A)

(imza,tarix)

BMU-2022
CONTENTS

I What is String?………………………………………..…....................3

1.1. What is string in programming?.......………........………..…........3

1.1.1 What is ASCII ?.....................................................................3

1.2. How we use string in C++? ………………….....………...............4

1.2.1 String functions in C++ ……………………………………..4

II Tasks related to string data type ...………................…..…..……....….6

2.1. Problem N1………………………………………….….....….6

Code/Explanation………………………………....………....6

2.2. Problem N2………………………………………….…......….8

Code/Explanation…………………………………………....8

2.3. Problem N3………………………………………….……...........10

Code/Explanation…………………………………………....10

2.4. Problem N4………………………………………….………...….12

Code/Explanation…………………………………………....12

2.5. Problem N5………………………………………….………...….14

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.2.1 String functions in C++.

1) Input functions :

getline() - This function is used to store a stream of characters as entered by


the user in the object memory.

push_back() - This function is used to input a character at the end of the


string.

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.

length() - This function finds the length of the string.

3) Iterator Functions :

begin() - This function returns an iterator to the beginning of the string.

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.

swap() - This function swaps one string with another

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 :

We have string input . Capitalize all words’ first letter.

Input format:

We get string input .

Inputs and Outputs:


Input 1: Output 1:
baku engineering university Baku Engineering University
Input 2: Output 2:
world cup World Cup

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 :

Given a string . Find sum of all integer inside it .

Input format:

One line: string type input.

Inputs and Outputs:


Input 1: Output 1:
Baku Eng1neer1ng University 2022 2024
Input 2: Output 2:
World Cup 2022-2026 4048

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:

String type input consist of vowels.

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 :

Given a string . Write a C++ program to reverse a given string.

Input format:

String type input .

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

You might also like