Document Details

GodlikeClavichord9430

Uploaded by GodlikeClavichord9430

D. S. Malik

Tags

C++ programming computer programming variables input statements

Summary

These notes cover fundamental C++ programming concepts, specifically focusing on placing data into variables. They discuss assignment statements and input/read statements. The notes are geared towards undergraduate-level students.

Full Transcript

STQS1313 COMPUTER PROGRAMMING Adapted from C++ Programming: From Problem Analysis to Program Design, 8th edition by D. S. Malik TOPIC 2: Basic elements of C++ (Part C) Putting Data into Variables In C++, data can be placed into a variable using two ways:  assignment statement (from previous s...

STQS1313 COMPUTER PROGRAMMING Adapted from C++ Programming: From Problem Analysis to Program Design, 8th edition by D. S. Malik TOPIC 2: Basic elements of C++ (Part C) Putting Data into Variables In C++, data can be placed into a variable using two ways:  assignment statement (from previous section)  input (read) statements. Assignment statement 1) Recall that this assignment statement takes the following form: variable = expression; 2) For example: int counter; counter = 5; or of course you can simply do int counter = 5; Input (read) statement 1) When the computer gets the data from the keyboard, the user is said to be acting interactively. 2) Here, you will learn how to put data into variables from the standard input device, using C++’s input (or read) statements. 3) This can be accomplished via the use of cin and stream extraction operator >>, with the syntax: cin >> variable1 >> variable2...;  input (read) statement 4) Example: Suppose that miles is a variable of type double. Further suppose that you want to insert the value 73.65 into miles. Using an input statement, you can write your code as follows: #include using namespace std; int main() { double miles; cout > miles; cout inches; cout

Use Quizgecko on...
Browser
Browser