Introduction to C++ Programming

Slides:



Advertisements
Similar presentations
Week 1 Algorithmization and Programming Languages.
Advertisements

Stop Doing That! Common T-SQL Anti-Patterns
Chapter 1.2 Introduction to C++ Programming
Mean Value and Rolle’s Theorem
Review- 6 Differentiation Rules
Chapter 1.2 Introduction to C++ Programming
Area between Polar Curves
Chapter 1.2 Introduction to C++ Programming
Small Business Administration Entrepreneurship Track
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Review- 7 Implicit Differentiation
Family Philanthropy and United Way
Stop Doing That! Common T-SQL Anti-Patterns
Intergration and U-Substitution
Lainie Chang Grand Canyon University January 20, 2010 TEC 542
Integration Techniques
Chapter 2 part #1 C++ Program Structure
– ELA/Reading Units 3rd grade
Stop Doing That! Common T-SQL Anti-Patterns
Training New Employees
Optimization and Parallelization of CBD models
David Taylor and Rhonda King Region 18 Education Service Center
Sect. 9-5 continued Absolute convergence and conditional convergence
COPS Digital Expansion Project
Partial Fractions Section 8-5
The muscular System This template can be used as a starter file for presenting training materials in a group setting. Sections Sections can help to organize.
Training New Employees
Training New Employees
Jackie Carpenter 3rd September 2016
Classified Evaluation System
Stop Doing That! Common T-SQL Anti-Patterns
Dr. Hatem Elaydi Fall 2014 Lead Compensator
Stop Doing That! Common T-SQL Anti-Patterns
2.1 Parts of a C++ Program.
Virtual Desktop Infrastructure Data Center
صندوق ضمانت سرمایه گذاری صنایع کوچک
Financial Update Period 6
Financial Update Period 7
Financial Update Period 4
Is Baptism Necessary for Salvation?
Financial Update Period 5
فناوری نانو در صنعت خودرو
Bell Ringer 10/8/12 Which of the following expressions will not equal 2 when x= 1? a) 1/2 (8x - 4) b) -4x + 1 c) 4x - 2 d) -4x + 6 e.) x.
Introduction to C++ Programming
Introduction To Computers & Computing [EED 301]
Financial Update Period 4
Financial Update Period 9
STUDY in CALIFORNIA Community Colleges
The Role of Brain Processes in Partisan Politics
Chapter 2: Introduction to C++.
Classified Evaluation System
Programs written in C and C++ can run on many different computers
Kapitel 4-Stufe 2 Lieblings-
Capitolo 1 – Introduction C++ Programming
Powering Africa This template can be used as a starter file to give updates for project milestones. Sections Sections can help to organize your slides.
Chapter 11 Review (Civil War)
Making graphs from data
Telling Time in Spanish
WORKFORCE DEANS’ ACADEMY
Unit I Vocabulary This template can be used as a starter file for presenting training materials in a group setting. Sections Right-click on a slide to.
Chapter 11 Review (Civil War)
Training New Employees
THESIS OFFICE ACCOMPLISHMENTS
COMPUTER ORGANIZATION
Sample PowerPoint presentation
HVAC 101 Brent Herstine May 2017
Chapter 2 part #1 C++ Program Structure
Presenter Name Presentation Date
BPKC NUMERICAL ANALYSIS ASSIGNMENT-3
Presentation transcript:

Introduction to C++ Programming Week 3 – BITE 1513 Computer Game Programming This template can be used as a starter file for presenting training materials in a group setting. Sections Right-click on a slide to add sections. Sections can help to organize your slides or facilitate collaboration between multiple authors. Notes Use the Notes section for delivery notes or to provide additional details for the audience. View these notes in Presentation View during your presentation. Keep in mind the font size (important for accessibility, visibility, videotaping, and online production) Coordinated colors Pay particular attention to the graphs, charts, and text boxes. Consider that attendees will print in black and white or grayscale. Run a test print to make sure your colors work when printed in pure black and white and grayscale. Graphics, tables, and graphs Keep it simple: If possible, use consistent, non-distracting styles and colors. Label all graphs and tables.

New Employee Orientation Type, Variables and Standard I/O Working with std namespace Using Arithmetic Operators Declaring the variables Performing Arithmetic Operations with variables Working with constants Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important. Introduce each of the major topics. To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.

Introduction C++ This is another option for an Overview slides using transitions.

Using C++ for Games There are a variety of reasons why game programmers choose the language.

It’s fast. Well-written C++ programs can be blazingly fast. One of C++’s design goals is performance. And if you need to squeeze out even more performance from your programs, C++ allows you to use assembly language—the lowest-level human-readable programming language—to communicate directly with the computer’s hardware.

C++ is a multi-paradigm language that supports different styles of programming, including object-oriented programming. Unlike some other modern languages, though, C++ doesn’t force one particular style on a programmer. It’s flexible

It’s well supported Because it is the dominant game programming language, there’s a large pool of assets available to the C++ game programmer, including graphics APIs and 2D, 3D, physics, and sound engines—all of which allow a programmer to leverage previous work to greatly speed up the process of writing a new game.

# include <header file> … void main( ) { variable declarations // comments # include <header file> … void main( ) { variable declarations …. function prototype statements } Include library files Main program block

Explanations

This is a comment

It tells the program to call the specific library in order to display the output and making the program work perfectly Including Other Files The next line in the program is a preprocessor directive. You know this because the line begins with the # symbol. #include <iostream> The preprocessor runs before the compiler does its thing and substitutes text based on various directives. In this case, the line involves the #include directive, which tells the preprocessor to include the contents of another file. iostream, is part of the standard library, because it contains code to help us display output (<) and greater than (>) characters to tell the compiler to find the file where it keeps all the files that came with the Compiler. It called a header file.

All symbols in that namespace will become visible without adding the namespace prefix. A symbol may be for instance a function, class or a variable. When you make a call to using namespace <some_namespace>; all symbols in that namespace will become visible without adding the namespace prefix. A symbol may be for instance a function, class or a variable. E.g. if you add using namespace std; you can write just cout instead of std::cout when calling the operator cout defined in the namespace std. This is somewhat dangerous because namespaces are meant to be used to avoid name collisions and by writing using namespace you spare some code, but loose this advantage. A better alternative is to use just specific symbols thus making them visible without the namespace prefix. Eg:

E.g. if you add using namespace std; you can write just cout instead of std::cout when calling the operator cout defined in the namespace std. When you make a call to using namespace <some_namespace>; all symbols in that namespace will become visible without adding the namespace prefix. A symbol may be for instance a function, class or a variable. E.g. if you add using namespace std; you can write just cout instead of std::cout when calling the operator cout defined in the namespace std. This is somewhat dangerous because namespaces are meant to be used to avoid name collisions and by writing using namespace you spare some code, but loose this advantage. A better alternative is to use just specific symbols thus making them visible without the namespace prefix. Eg:

The next line marks the beginning of the function. { And the very last line of the program marks the end of the function. } The next line marks the beginning of the function. { And the very last line of the program marks the end of the function. } All functions are delimited by a pair of curly braces, and everything between them is part of the function. Code between two curly braces is called a block and is usually indented to show that it forms a unit. The block of code that makes up an entire function is called the body of the function.

meaning it’s literally the characters between the quotes. “Hello World!” is a string—a series of printable characters. Technically, it’s a string literal, meaning it’s literally the characters between the quotes. Displaying Text through the Standard Output The first line in the body of main() displays Game Over!, followed by a newline, in the console window. std::cout << “Game Over!” << std::endl; “Game Over!” is a string—a series of printable characters. Technically, it’s a string literal, meaning it’s literally the characters between the quotes. cout is an object, defined in the file iostream, that’s used to send data to the standard output stream. In most programs (including this one), the standard output stream simply means the console window on the computer screen.

We use the output operator (<<) to send the string to cout We use the output operator (<<) to send the string to cout. We use std to prefix cout to tell the compiler that I mean cout from the standard library. Displaying Text through the Standard Output We use the output operator (<<) to send the string to cout. We use std to prefix cout to tell the compiler that I mean cout from the standard library. Std is a namespace. You can think of a namespace as an area code—it identifies the group to which something belongs. You prefix a namespace using the scope resolution operator (::). We send std::endl to the standard output. endl is defined in iostream and is also an object in the std namespace. Sending endl to the standard output acts like pressing the Enter key in the console window

The first line of the function ends with a semicolon (;) The first line of the function ends with a semicolon (;). That’s because the line is a statement—the basic unit controlling the execution flow.

Returning a Value from main() The last statement in the function returns 0 to the operating system. return 0;

Working with the std Namespace Because it’s so common to use elements from the std namespace, two different methods for directly accessing these elements. This will save you the effort of using the std:: prefix all the time, plus it will make your code a bit cleaner. // Game Over 2.0 // Demonstrates a using directive #include <iostream> using namespace std; int main() { cout << “Game Over!” << endl; return 0; }

Working with the std namespace // Game Over 3.0 // Demonstrates using declarations #include <iostream> using std::cout; using std::endl; int main() { cout << “Game Over!” << endl; return 0; }

Data Types Data Type C++ Keyword Bits Range integer int 16 -32768 to 32767 long integer long 32 -4294967296 to 429496725 short integer short 8 -128 to 127 insigned int unsigned 0 to 65535 character char 0 to 225 floating point float approximately 6 digits double floating point double 64 approximately 12 digits

Using Arithmetic Operators Meaning - Subtraction (also unary minus) + Addition * Multiplication ? Divison % Modulus divison -- Decrement ++ Increment

Arithmetic Operators Example More Examples: http://www.cplusplus.com/doc/tutorial/operators/

Declaring Variables All variables in a program must be declared prior to their use. The declaration takes the general form variable_type variable-list; Examples int a, b , c: short small_number; long big-number; char ch; double amout, rate

Initializing Variables int m, n = 10; double rate, total = 0.0; char response = ‘n’; char colour[6] = “green”;

Logical Operators Operator Meaning && Logical AND || Logical OR ! Logical NOT x y X || y X && y True False

Escape Sequences Code Meaning \a Audible bell \t Horizontal tab \b Backspace \\ Backslash \f Form feed \’ Single quote \n New line \” Double quote \r Carriage return \0 Null ASCII 0

Input/Output

Input/Output