Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.

Similar presentations


Presentation on theme: "Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for."— Presentation transcript:

1 Chad’s C++ Tutorial Demo Outline

2 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for creating large-scale applications. C++ is a superset of the C language. (Thanks Google) We use programing languages such as C++ because a computer can only understand machine, code consisting of ones and zeros. Programming in ones and zeros would be far too tedious. This is where the compiler comes in, it translates C++ into machine. It is also important to know that the compiler starts compiling a main.cpp file(This doesn’t mean it will always be called “main”) first, and code is always executed from top to bottom.

3 2. Console Out Syntax: std::cout

4 3. Data Types int = Whole Numbers float = Decimal Numbers double = More decimal places than a float bool = true or false/1 or 0 char = A character, use ‘ not “(Ex: ‘c’) string = “A set of characters”

5 4. Variables Variables provide us with a named storage for all data types. Our programs will be able to manipulate these variables at any time(Unless they are constant).

6 5. Console In Syntax: std::cin

7 6. Strings A string is a data type containing a series of characters. Must #include Show.length() function.

8 7. Constants Adding the “const” operator before a Data Type or class(when creating an Object) will create a constant Variable or Object. This means the program will no longer be able to change the value of the Variable once it's been declared, doing so will result in an error when compiling.

9 8. Arithmetic Operators = Assignment Operator + Addition Operator - Subtraction Operator * Multiplication Operator / Division Operator % Modulo Operator

10 9. Compound Assignment Operator Adding an = after an Arithmetic Operator will add/subtract/divide/multiply the defined value by itself. Syntax: int a = 5; a += 10; Output: A would be equal to 15.

11 10. Increment and Decrement Operators ++ Adds 1 to a variable -- Subtracts 1 from a variable These can be placed before or after a variable’s name, though after is most common. You Should be able to complete Chapter 1-1 now.

12 11. Relation Operators == Is equal to != Is not equal to < Less than > Greater than <= Less than or equal to >= Greater than or equal to

13 12. Logical Operators ! Not operator(Goes before variable name) && And operator || Or operator

14 13. Comma Operator The Comma Operator can be use to separate two or more expressions.

15 14. sizeof Operator Calling the “sizeof()” function will determine the size of a variable.

16 15. Conditional Statements You can use conditional statements to test certain conditions using the Relation Operators we learned about earlier. “If” statements are used to execute code if the condition(s) is/are true. “else” statements are used after an “if” statement to execute code if the condition is false. Alternatively if you wanted to test another condition you could use a “else if” statement. You Should be able to complete Chapter 1-2 now.

17 16. For Loop For Loops are most commonly used for executing the same code a specific number of times. A for loop’s parameters are divided into three parts. The first part which allows you to create a starting variable. The second part after the first “;” is where a condition, based off your starting variable is placed. The third part after the second “;” is where an increment statement is placed. You could do something simple like “x++” if you only wanted to execute the loop 9 times, or “x = x + 3” if you only wanted to execute the loop twice. This works because the condition is checked every time the loop is executed. When the condition is false, the code will be ignored by the compiler. Syntax: for(int x = 1; x<10; x++){ }

18 17. While Loop A while loop can be used like an if statement. If the condition is true the code in the loop will execute until the condition becomes false. In most if not all cases, you’ll want to include some kind of increment statement in your while loop that will eventually make your condition false. This is important because If you make an infinite loop your program will end up crashing.

19 18. Do While Loop Unlike “for” and “while” loops, a Do While Loop will execute its code one then check the condition to decide whether or not it will execute again. These are useful because they are guaranteed to execute at least once. You Should be able to complete Chapter 1-3 now.

20 19. Switch/Case Statements A switch statement allows you to test a list of values for one constant such as an integer. The variable being tested is called the Switch, and the possible values being tested is called a Case. After a case is executed you’ll want to Break, telling your program to stop testing other values. You can also include the optional Default case which acts like an “else” statement and executes itself if all cases are false. Keep in mind that the default case should(But doesn’t have to) appear at the end of a Switch statement and no “break” is needed. You Should be able to complete Chapter 1-4 now.


Download ppt "Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for."

Similar presentations


Ads by Google