2_Computer Science Grade 10 String_manipulation presentation 1 variant

  • pptx
  • 02.05.2020
Публикация на сайте для учителей

Публикация педагогических разработок

Бесплатное участие. Свидетельство автора сразу.
Мгновенные 10 документов в портфолио.

Иконка файла материала 2_Computer Science Grade 10 String_manipulation presentation 1 variant.pptx

String manipulations

Learning objectives

10.4.1.2 use procedures and functions for string manipulation

Statement of the situation:
When making a banner, it was decided to convert part of the word into capital letters (CorelDRAW).

Questions:
What ways can you solve this problem?
How do you think in text editors what will happen as a result of pressing Shift + F3 or

The term string generally means an ordered sequence of characters, with a first character, a second character, and so on, and in most programming languages such strings are enclosed in either single or double quotes. In C++ the enclosing delimiters are double quotes. In this form the string is referred to as a string literal and we often use such string literals in output statements when we wish to display text on the screen for the benefit of our users. For example, the usual first C++ program displays the string literal "Hello, world!" on the screen with the following output statement:

cout << "Hello, world!" << endl;

Types of Strings

String Literals:
“Hello World”
“xyz 123 *&^#$!”

C-style strings:
char s[20];

C++ class string;
string s;


6

Literal String


To create a variable containing a literal string:
char s[] = “Hello World”;

char s[] means an array of characters;
This variable cannot be changed, i.e., the following will generate a syntax error:

char s[] = “Hello World”;
s = “Goodbye World”; // Syntax Error

7

null Character

Literal strings end in a null character: ‘\0’. (Character ‘\0’ has ASCII code 0.)
char s[] = “Hello World”;

s[0] equals ‘H’;
s[1] equals ‘e’;
. . .
s[8] equals ‘r’;
s[9] equals ‘l’;
s[10] equals ‘d’;
s[11] equals ‘\0’;

literalString2.cpp

cout << s << endl;

i = 0;
while(s[i] != '\0')
{
cout << s[i] << ",";
i++;
}
cout << endl;

cout << "s[" << i << "] = " << int(s[i]) << endl;

> literalString2.exe
Hello World
H,e,l,l,o, ,W,o,r,l,d,
s[11] = 0

ascii2.cpp

...
i = 0;
while(s[i] != '\0')
{
cout << setw(4) << s[i] << ",";
i++;
}
cout << endl;

i = 0;
while(s[i] != '\0')
{
cout << setw(4) << int(s[i]) << ",";
i++;
}
cout << setw(4) << int(s[i]);
cout << endl;
...

> ascii2.exe
Hello World
H, e, l, l, o, , W, o, r, l, d,
72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0
>

...
i = 0;
while(s[i] != '\0')
{
cout << setw(4) << int(s[i]) << ",";
i++;
}
cout << setw(4) << int(s[i]);
cout << endl;
...

Research work (10 minutes)

Reflection

In pairs, explain to your partner one thing that you have understood really well.
Then ask them a question about one thing you would like an answer to.
Can you answer your partner’s question?.