The document discusses string manipulation and provides examples of programs and methods to:
1. Read an integer and output its binary and English representations.
2. Check if a string of numbers is valid, and if so, calculate the sum of the squared numbers.
3. Take a string and compute the sum of integers, floats, and strings within.
The document discusses string manipulation and provides examples of programs and methods to:
1. Read an integer and output its binary and English representations.
2. Check if a string of numbers is valid, and if so, calculate the sum of the squared numbers.
3. Take a string and compute the sum of integers, floats, and strings within.
Create a project named: pLab05_String_ID With ID stands for student’s identify, p is short for project Ex: If your student’s ID is 9600278, so your project name will be: pLab05_String_9600278 Pay attention to “_” (underscore) Package naming convention: Each project has one or many packages. Each package has a specific name Each Lab has one package name. Remember to name the packages as follow: labNo_ID With No is a number of each lab, ID stands for student’s identify Ex: lab01_9600278, lab02_9600278 Remember to use lowercase l Class naming convention (Files): Each package has one or many classes Each class has a specific name Remember to name the classes (classname) as follow: LabNo_ID and TestLabNo_ID With No is a number of each lab, ID stands for student’s identify Ex: Lab01_9600278, TestLab01_9600278, Lab02_9600278, TestLab02_9600278 Remember to capitalize each word L, T and L
1. Write a program to read an integer number (n>0). Write following methods:
- Print out correlative binary string of n - Print out the read of n by English Example input: 125 output: “1111101” “one two five” 2. Write a program to enter a string that has numerals. Write following methods: - Checking whether the input string is a valid string or not? - Supposing the input string is a1 a2 … an, compute square sum of numerals: a12 + a22 + … + an2. Guide: The valid string is a string which has consecutive numerals. Otherwise is invalid string Example: “123 4 4.5 7 9 9.3” is valid “23 abc 4.5 8 1.0 4” -> invalid “aa 7.8 4567 ttt” -> invalid Input: a string from keyboard Output: - If the input string is invalid, print out to console the message: "N/A"; - If the input string is valid, print out the square sum of numerals. Example: Input: “1.4 3 2 4.5 9 8 2.6” Output: valid string square sum: 30.5 --- Input “1.4 3 aba 4.5 9a7 8 2.6” Output invalid string N/A 3. Write a program to enter a string. Computing the sum of integer numbers, the sum of float numbers, the sum of strings. Example: Input: “1.4 3 abc 2 4.5 9bc 8 2.6 9 10 2.0 4.3 2a3” Output: the sum of integer numbers: 32 the sum of float numbers: 14.8 the sum of strings: “abc 9bc 2a3” 4. Write a program to enter a string. Write following methods: - Returning the sum of characters (that are not space character) of the input string - Print out the reserve string of the input string Example: Input: “abc def ght” Output: 9 “thg fed cba” - If the string’s length > 3, print out the third character of the input string. Otherwise, print out to the console the message: “N/A” - Write an algorithm to accept two strings and check whether the second string exists within the first string. For example, if the first string is “concatenation” and the second string is “cat”, the algorithm should display “Substring found at position 4 in the string”. However, if the first string is “concatenation” and the second string is “tent”, the algorithm should display “Substring not found in the string”. - How many the numeral characters, the vowel characters, the consonant characters and the special characters does the input string have? - How many words in the input string? - Print out the lower case letters of input string - Print out the upper case letters of input string - Replace letters that are identical and uninterrupted by one (ex: abcbbbcca - > abcbca) - Create a method that input a string then all remove unnescessary blanks (ex: " I go to school " "I go to school") - Create a method that input a string then count the number of presence of each letter. - Create a method that input a string and an integer n then output n letters from the right side of that string - Create a method that convert an input to title case (ex: "khoa cong nghe so" “Khoa Cong Nghe So”) - Create a method that convert an input to the English-name-like string (ex: "Nguyen Tan Thuan" "Thuan Nguyen Tan") - Create a method that reverse an input by each word (ex "Nguyen Tan Thuan" "Thuan Tan Nguyen")