10 String_manipulation method instruction 2 1 variant

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

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

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

Иконка файла материала 10 String_manipulation method instruction 2 1 variant.doc

Methodological Instructions

Theme: String manipulation 2 lesson

Objective: 10.4.1.2 use procedures and functions for string manipulation

Assessment criteria

·        can define string data; String and char;

·        uses string functions to solve problems

·        applies string procedures to solve problems

Basic Level:

From a grade 7–9 course, students have knowledge and programming skills.

Key words and phrases:

Use of appropriate subject specific terminology on the topic in the study of new content

String, processing strings, insert substring, delete symbols, string length determination, copying symbols, determining the position.

The function differs from the procedure in that the procedure..., while the function....

In order to determine the length of a string...

To insert a substring in a string, we apply…

П. Practical tasks

  1. Write a function to remove all trailing blanks from the right end of a string. Assume the prototype is

    void trimRight(char a[]);

  1. Write a function to remove all leading blanks from the left end of a string. Assume the prototype is

    void trimLeft(char a[]);

  1. Write a function to add extra blanks to the right end of a string to make it at least length n. If the string is already n characters or longer, do not change the string. Assume the prototype is

    void padRight(char a[], int n);

  1. Write a function to add extra blanks to the left end of a string to make it at least length n. If the string is already n characters or longer, do not change the string. Assume the prototype is

    void padLeft(char a[], int n);

  1. Write a function to center a string by adding blanks to the front and back. If the string is already n characters or longer, do not change the string. If an odd number of blanks have to be added, put the extra blank on the right. You can use the functions in the previous problems (padRight and padLeft) to solve this problem. Assume the prototype is

    void center(char a[], int n);

  1. Write a function which returns true if the string parameter is a palindrome. A palindrome is any "word" which is the same forward and backward, eg, "radar", "noon", "20011002", ... The function should return false if the argument is not a palindrome. Assume the prototype is

    bool isPalindrome(char a[]);

  1. Write a function which shortens a string to n characters. If the string is already shorter than n, the function should not change the string. Assume the prototype is

    void truncate(char a[], int n);

  1. Write a function which capitalizes the first letter in every word. Assume the first letter is any letter at the beginning or preceded by a blank. All other letters should be turned into lowercase. You can use the library toupper and tolower functions. Assume the prototype is

    void capitalizeWords(char a[]);

  1. Write a function, capitalize, which changes the first letter of the argument string to uppercase. You can use the library toupper function which works on one char. Note that the toupper function returns a value without changing its parameter. Assume the prototype is

    void capitalize(char a[]);

  1. Write a function, isAlpha, which returns true if all characters in the parameter are alphabetic (ie, if there are no non-alphabetic characters), and false otherwise. You can use the library isalpha function to test the individual characters. If there are no characters in the argument, this function should succeed. Assume the prototype is

    bool isAlpha(char a[]);

  1. Write a function, reverse, which reverses the characters in the argument. Assume the prototype is

    void reverse(char a[]);

  1. Write a function, count, which counts the occurrences in the first argument, a, of the single character which is the second argument, c. Assume the prototype is

    int count(char a[], char c);

For example,

    i = count("abracadabra", 'a');

would return 5.

  1. Write a function, count, which counts the occurrences in the first argument, a, of the characters in the second argument, b. Assume the prototype is

    int count(char a[], char b[]);

For example,

    i = count("abracadabra", "bax");

would return 7.

  1. Write a function, deleteChar, which deletes any occurrence in the first argument, a, of the single character which is the second argument, c. Assume the prototype is

void deleteChar(char a[], char c);

 

 

Visual Aids and Materials.

1.    Slides

2.    Procedures and functions of working with strings: http://pas1.ru/stringfunction

3.    http://purecodecpp.com/archives/920

4.    http://cs.stmarys.ca/~porter/csc/ref/c_cpp_strings.html

5.    https://www.w3resource.com/cpp-exercises/basic/index.php          

6.    https://web.stanford.edu/class/archive/cs/cs106b/cs106b.1132/handouts/08-C++-Strings.pdf

7.    https://cal-linux.com/tutorials/strings.html

8.    https://www.cs.fsu.edu/~myers/cop3014/hw/hwpractice.html


9.    Скачано с www.znanio.ru