At the end of this lesson, you will be able to:
understand how to parse a string
Write the code in Python that creates an empty list of integers called "list_of_int". It then does the following:
adds 5 to the end of the list
then adds 3 at the beginning of the list
removes the element at the end of the list
then adds 4 to the end of the list
then adds 2 to the beginning of the list
then inserts 7 at index 2
Do the above in C++.
lists
a string is just an array of characters
sometimes it is useful to split a sentence read from the user into a list of words.
in Python:
you can read a string directly into a list of strings / words
in C++:
you need to iterate over each character in a string and check if there is a space.
use aString.length()
build each word and push it onto the list of strings / words
if there is a space, start a new word
see the code using iterators below:
we will not use iterators. Just treat the string as an array of characters and iterator over it with a loop.
Create a program called “String Parser” that asks the user to enter a sentence. The program will then call a function that accepts the user's sentence as a string and returns a list of the words in the sentence. The words will then get displayed, one per line without any spaces.
Ensure the main() function catches any "bad" user input so that only "valid" input is passed to the function.
Note: The top-down design should be for the entire program. There should be a flowchart for each function.
in groups of 2, do the following on the board for today's daily assignment:
Top-Down Design
Flow Chart
Pseudocode
Test Cases
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
recreate the same program in C++