Programming Fundamentals PDF
Document Details
Uploaded by DesirousBowenite1923
null
2017
Dr. Mustafa
Tags
Related
- Introduction to Programming - Lecture 11 - Strings PDF
- STQS1313 Computer Programming PDF
- Lecture 1: Introduction to C++ Programming and Computer Science PDF
- Chapter 1: Introduction to Computers and Programming PDF
- CS 1436.0L3 Programming Fundamentals Sample Test 1 Questions PDF
- Introduction to C++ Basics PDF
Summary
This document is a lecture on programming fundamentals, specifically focusing on C++. It covers topics like algorithms, flowcharts, software development life cycle, and simple C++ programs.
Full Transcript
Programming Fundamentals Dr. Mustafa © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. We have studied Algorithms Flowcharts Software development life cycle Simple C++ program © Copyright 2017 by Pearson...
Programming Fundamentals Dr. Mustafa © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. We have studied Algorithms Flowcharts Software development life cycle Simple C++ program © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. A single statement can print multiple lines by using newline characters. Each time the \n (newline) escape sequence is encountered in the output stream, the screen cursor is positioned to the beginning of the next line. To get a blank line in your output, place two newline characters back to back. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. The next program obtains two integers typed by a user at the keyboard, computes their sum and outputs the result using std::cout. Figure 2.5 shows the program and sample inputs and outputs. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. Data type double is for specifying real numbers, and data type char for specifying character data. Real numbers are numbers with decimal points, such as 3.4, 0.0 and –11.19. A char variable may hold only a single lowercase letter, a single uppercase letter, a single digit or a single special character (e.g., $ or *). Types such as int, double and char are called fundamental types. Fundamental-type names are keywords and therefore must appear in all lowercase letters. Appendix C contains the complete list of fundamental types. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. A variable name is any valid identifier that is not a keyword. An identifier is a series of characters consisting of letters, digits and underscores ( _ ) that does not begin with a digit. C++ is case sensitive—uppercase and lowercase letters are different, so a1 and A1 are different identifiers. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. Declarations of variables can be placed almost anywhere in a program, but they must appear before their corresponding variables are used in the program. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. A prompt it directs the user to take a specific action. A cin statement uses the input stream object cin (of namespace std) and the stream extraction operator, >>, to obtain a value from the keyboard. Using the stream extraction operator with std::cin takes character input from the standard input stream, which is usually the keyboard. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. When the computer executes an input statement that places a value in an int variable, it waits for the user to enter a value for variable number1. The user responds by typing the number (as characters) then pressing the Enter key (sometimes called the Return key) to send the characters to the computer. The computer converts the character representation of the number to an integer and assigns (i.e., copies) this number (or value) to the variable number1. Any subsequent references to number1 in this program will use this same value. Pressing Enter also causes the cursor to move to the beginning of the next line on the screen. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. In this program, an assignment statement adds the values of variables number1 and number2 and assigns the result to variable sum using the assignment operator =. ◦ Most calculations are performed in assignment statements. The = operator and the + operator are called binary operators because each has two operands. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. std::endl is a so-called stream manipulator. The name endl is an abbreviation for “end line” and belongs to namespace std. The std::endl stream manipulator outputs a newline, then “flushes the output buffer.” ◦ This simply means that, on some systems where outputs accumulate in the machine until there are enough to “make it worthwhile” to display them on the screen, std::endl forces any accumulated outputs to be displayed at that moment. ◦ This can be important when the outputs are prompting the user for an action, such as entering data. © Copyright 2017 by Pearson Education, Ltd. All Rights Reserved. Using multiple stream insertion operators (