Docsity

Concepto de Lenguaje C++, Ejercicios de Ingeniería

Vista previa parcial del texto

¡Descarga Concepto de Lenguaje C++ y más Ejercicios en PDF de Ingeniería solo en Docsity!

C++

Beginners to Advance www.genial-code.com

Programming!

Objectives

  • Become familiar with the basic components of a C++ program, including functions, special symbols, and identifiers
  • Explore simple data types
  • Discover how to use arithmetic operators
  • Examine how a program evaluates arithmetic expressions

Objectives (continued)

  • 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 4

The Basics of a C++ Program

  • Function: collection of statements; when executed, accomplishes something - May be predefined or standard
  • 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 5

Special Symbols

  • Special symbols
        • /. ; 7 ? , <= != ==

      =

Reserved Words (Keywords)

  • Reserved words, keywords, or word symbols
    • Include:
      • int
      • float
      • double
      • char
      • const
      • void
      • return 8

Identifiers (continued)

  • The following are legal identifiers in C++:
    • first
    • conversion
    • payRate 10

Whitespaces

  • Every C++ program contains whitespaces
    • Include blanks, tabs, and newline characters
  • Used to separate special symbols, reserved words, and identifiers
  • Proper utilization of whitespaces is important
    • Can be used to make the program readable 11

Simple Data Types

  • Three categories of simple data
    • Integral: integers (numbers without a decimal)
    • Floating-point: decimal numbers
    • Enumeration type: user-defined data type 13

Simple Data Types (continued)

  • Integral data types are further classified into nine categories: C++ Programming: From Problem Analysis to Program Design, Fourth Edition 14

int Data Type

  • Examples:
    • 6728 0 78
    • 763
  • Positive integers do not need a + sign
  • No commas are used within an integer
    • Commas are used for separating items in a list C++ Programming: From Problem Analysis to Program Design, Fourth Edition 16

bool Data Type

  • bool type
    • Two values: true and false
    • Manipulate logical (Boolean) expressions
  • true and false are called logical values
  • bool, true, and false are reserved words C++ Programming: From Problem Analysis to Program Design, Fourth Edition 17

Floating-Point Data Types

  • C++ uses scientific notation to represent real numbers (floating-point notation) C++ Programming: From Problem Analysis to Program Design, Fourth Edition 19

Floating-Point Data Types

(continued)

  • float: represents any real number
    • Range: - 3.4E+ 38 to 3.4E+ 38 (four bytes)
  • double: represents any real number
    • Range: - 1.7E+ 308 to 1.7E+ 308 (eight bytes)
  • On most newer compilers, data types double and long double are same C++ Programming: From Problem Analysis to Program Design, Fourth Edition 20