Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

DIVISION OF CAGAYAN DE ORO CITY

CAGAYAN DE ORO NATIONAL HIGH SCHOOL-JUNIOR HS


LEARNING ACTIVITY SHEET (LAS)
GRADE 8 STE
C++ PROGRAMMING
==================================================================================================

Name __________________________________ Grade & Sec ______________ Date ______________ Score__

cin in C++ (User Input)

You have already learned that cout is used to output (print) values. Now we will use cin to get user input.
cin is a predefined variable that reads data from the keyboard with the extraction operator (>>).

The cin object in C++ is an object of class iostream. It is used to accept the input from the standard input
device i.e. keyboard. It is associated with the standard C input stream stdin. The extraction operator (>>) is
used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin
which is entered using the keyboard.

Good To Know
cout is pronounced "see-out". Used for output, and uses the insertion operator (<<)
cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)

Program 1: Below is the C++ program to implement cin object:

Program 2:
The user can input a number, which is stored in the variable x. Then we print the value of x:
DIVISION OF CAGAYAN DE ORO CITY
CAGAYAN DE ORO NATIONAL HIGH SCHOOL-JUNIOR HS
LEARNING ACTIVITY SHEET (LAS)
GRADE 8 STE
C++ PROGRAMMING
==================================================================================================

Program 3:
Multiple inputs using the extraction operators(>>) with cin. Below is the C++ program to take multiple user inputs:

Program 4:
The user must input two numbers. Then we print the sum by calculating (adding) the two numbers:

Exercises:
A. Write the missing item to complete the code.

1. Use the correct keyword to get user input, stored in the variable x:

2. Fill in the missing parts to print the sum of two numbers (which is
put in by the user):
DIVISION OF CAGAYAN DE ORO CITY
CAGAYAN DE ORO NATIONAL HIGH SCHOOL-JUNIOR HS
LEARNING ACTIVITY SHEET (LAS)
GRADE 8 STE
C++ PROGRAMMING
==================================================================================================

You might also like