Chapter 02

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

Info iconThis preview shows pages 1–16. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ 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 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 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 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 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 Symbols • Special symbols + - * / . ; ? , <= != == >= Symbols (continued) • Word symbols − Reserved words, or keywords − Include: • int • float • double • char • void • return 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 Legal and Illegal Identifiers • The following are legal identifiers in C++: − first − conversion − payRate 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 Simple Data Types • Three categories of simple data − Integral : integers (numbers without a decimal) − Floating-point : decimal numbers − Enumeration type : user-defined data type int Data Type • Examples:-6728 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 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 char...
View Full Document

This note was uploaded on 04/09/2008 for the course CS 150 taught by Professor Kanneko during the Spring '08 term at Old Dominion.

Page1 / 80

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

This preview shows document pages 1 - 16. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online