Chapter 02 - C Programming From Problem Analysis to Program...

Info icon This preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Objectives In this chapter you will: Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers Explore simple data types and examine the string data type Discover how to use arithmetic operators
Image of page 2
Objectives (continued) Examine how a program evaluates arithmetic expressions Become familiar with the string Type Learn what an assignment statement is and what it does Discover how to input data into memory using input statements Become familiar with the use of increment and decrement operators
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Objectives (continued) Examine ways to output results using output statements Learn how to use preprocessor directives and why they are necessary Explore how to properly structure a program, including using comments to document a program Learn how to write a C++ program
Image of page 4
Introduction Computer program : sequence of statements designed to accomplish some task Programming : planning/creating a program Syntax : rules that specify which statements (instructions) are legal Programming language : a set of rules, symbols, and special words Semantic rule : meaning of the instruction
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Programs A C++ program is a collection of one or more subprograms, called functions A subprogram or a function is a collection of statements that, when activated (executed), accomplishes something Every C++ program has a function called main The smallest individual unit of a program written in any language is called a token
Image of page 6
Symbols Special symbols + - * / . ; ? , <= != == >=
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Symbols (continued) Word symbols Reserved words, or keywords Include: int float double char void return
Image of page 8
Identifiers Consist of letters, digits, and the underscore character ( _ ) Must begin with a letter or underscore C++ is case sensitive Some predefined identifiers are cout and cin Unlike reserved words, predefined identifiers may be redefined, but it is not a good idea
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Legal and Illegal Identifiers The following are legal identifiers in C++: first conversion payRate
Image of page 10
Data Types Data Type : set of values together with a set of operations is called a data type C++ data can be classified into three categories: Simple data type Structured data type Pointers
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Simple Data Types Three categories of simple data Integral : integers (numbers without a decimal) Floating-point : decimal numbers Enumeration type : user-defined data type
Image of page 12
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
int Data Type Examples: -6728 0 78 Positive integers do not have to have a + sign in front of them No commas are used within an integer Commas are used for separating items in a list
Image of page 14
bool Data Type bool type Has two values, true and false Manipulate logical (Boolean) expressions true and false are called logical values bool , true , and false are reserved words
Image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
char Data Type The smallest integral data type
Image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern