Professional Documents
Culture Documents
Target By the end of this learning guide module, the students should be able to: 1
Hook Every time you use the computer, you are using some form of input and output. 2
From your previous lessons about computers, remember that input can come from
devices such as your mouse, keyboard, joysticks or controllers while output is
sent to your device screens or printers.
When you log in to your accounts, you input your username and password and
only then will the website output the pertinent information you want to access.
When playing games, you input your username and the game displays it as you
play. When using Google, you input your keywords then the site outputs the
websites relevant to your search. There are many different ways in which you use
input and output.
CS 2 Page 1 of 6
Ignite C++ handles input and output through a stream. Streams are a source or 15
destination of characters and are a mode of means of data transmission.
Input stream: The flow of the data is from the user/device (ex. keyboard) to the
main memory. This topic will be discussed in the next lesson.
Output stream: The flow of the data is from the main memory to the user/device
(ex. display screen).
The Input/output (I/O) features of C++ are in a library called iostream. To use the
functionality of this library, we need to include the iostream header at the top of
the the code.
Output:
Hello World!
CS 2 Page 2 of 6
The insertion operator (<<) can also be used multiple times in one statement to
concatenate or combine multiple things to output.
Output:
This is going to print as a single line
Using multiple cout statements doesn’t necessarily mean you will display
multiple lines of output. For example, if you run the following code, you will
only get one line of output.
Output:
Hello World!Have a nice day!
Notice that there is no space between World! and Have. This is because text
inside quotation marks is displayed as is, so if there is no space indicated in the
text, there will also be no space in the output.
If you want to display multiple lines of output, you can use the endl keyword to
separate your text with a line break. The endl keyword signifies the end of the
line. You may also use the new-line character ( \n ) to insert a new line. The
new-line character is placed inside the double quotation marks.
Output:
Hello World!
Have a nice day!
See you later!
CS 2 Page 3 of 6
It is usually considered good programming practice to add endl or \n to the end
of your display lines.
You may also choose to use multiple insertion operators (<<) in a single line of
code to display multiple output lines.
Output:
Hello World!
Have a nice
day!
To print the values of variables, you simply place the variable name after the
insertion operator WITHOUT quotation marks.
Output:
I am 13 years old.
I am age years old.
The first line displays the contents of the variable age while the second line
literally takes the word age and prints it as is.
CS 2 Page 4 of 6
Navigate 8
Exercises
1.
2.
3.
4.
Part 2. Write a code snippet that will display the following expected output.
Declare variables as needed. You may test your code on an IDE or online
compiler.
CS 2 Page 5 of 6
Knot Summary: 4
a
TA – time allocation suggested by the teacher
b
ATA- actual time allocation spent by the student (for information purposes only)
1. Albarico, J.M. (2013). THINK Framework. Based on Ramos, E.G. and N. Apolinario. (n.d.)
Science LINKS. Quezon City: Rex Bookstore Inc
2. THINK icons and blue car images by Clker-Free-Vector-Images from Pixabay
3. Basic Input/Output. (n.d.). Retrieved July 13, 2020 from
http://www.cplusplus.com/doc/tutorial/basic_io/
4. Basic Input Output (n.d.). Retrieved July 13, 2020 from https://www.geeksforgeeks.org/basic-
input-output-c/
5. Gaddis, T., & Manna, M. M. (2015). Chapter 2 Introduction to C++. In Starting out with C++:
From control structures through objects. Harlow, Essex: Pearson Education Limited.
CS 2 Page 6 of 6