Professional Documents
Culture Documents
By the end of this courseware, the student is expected to: 1. Understand object-oriented programming and its applications. 2. Recognize the different control structures of C++. 3. Create C++ programs based on certain requirements. 4. Demonstrate the ability to modify and debug C++ programs.
Lesson 1
Fifth Generation: AI problem-solving based on constraints or rules that have been declared in the program
Lesson 2
C++ Overview
the BIN folder of your Turbo C++ installation folder, run TC (the one with the MS-DOS icon). 2. On the screen, press Alt+O and choose Directories. In the Directories dialog box, you can configure where the directories of files can be found, such as source files and others.
typing the lines of code, press F2 to save. For this sample, name the program cool.cpp and then press Alt+F9 to compile. 5. Press Ctrl+F9 to run your program (or click Run > Run).
Lesson 3
L3: IDE
TechFactors, Inc.
L3: IDE
The Turbo C++ IDE
Like the graphical user interface (GUI) in office applications, the integrated development environment (IDE) makes programming easier because instead of having to manually code the commands so that MS-DOS will be able to execute your programs, it offers you
L3: IDE
The Main Menu
L3: IDE
The Main Menu (contd.)
Lesson 4
C++ Basics
TechFactors, Inc.
Functions
All C++ programs need at least one function for it to execute properly: the main() function. main() is always called first during program execution. If a program is executed on its own and it does not have a main() function anywhere on it, it will not run at all!
Functions
In the diagram, f1(), f2(), fn(), and main() are the functions. Even if f1() up to fn() are missing, as long as main() is present, the program will still compile and run assuming that all the codes inside the main() function can stand on their own and are not crossreferencing to other functions.
Statements
comprise the bulk of codes found in a function instructional codes that tell the computer to do a certain action upon its execution a semicolon (;) signifies the end of any statement the declaration of a variable in a function is also considered as a statement since the entire line of code ends with a semicolon
Comments
lines of code that are not executed during the program used either to give a brief labeling and explanation to lines of codes or to temporarily disable lines of code during the development phase
Comments (contd.)
Two kinds of comments that C++ utilizes: Single-line Comment a double slash (//) at the beginning of a line of code disables the entire statement and considers it merely as a comment Multi-line Comment several lines of code can be disabled by placing the code block between a slash-asterisk (/*) and an asterisk-slash (*/)
Keywords
reserved words in a programming language that have specific uses (e.g., executing a command) examples: if, do-while, and switch statements main() getch(), and clrscr() functions
TechFactors, Inc.
user input then places whatever the input is on the variable int1 (which was declared to be an int data type in the line int int1;)
cout << int1; displays
Constants
Like variables, constants also act like containers which are userdefined and are given initial values. However, the values of constants can never change or be changed.
Constants (contd.)
Two ways to declare constants:
1.
By declaring a statement under the preprocessor directives and making use of the command #define. This yields a constant declaration, e.g., #define standardAge 18, where standardAge is the constant name and 18 is the declared value. By declaring a statement under the global declarations and making use of the const command. This yields a constant declaration, e.g., const int standardAge = 18;, where int is the data type for the constant, standardAge is the constant name, and 18 is the declared value. Note that the whole statement ends with a semicolon.
2.
Operators
Operators are symbols that execute a corresponding action during the program. In C++, there are several categories of operators, each having a unique feature. Assignment Operator (=) assigns a value to an operand
Operators (contd.)
Mathematical Operators (+, -, *, /, %) addition (+), subtraction (-), multiplication (*), division (/), and modulo operator (%) which is like the division operator but instead of giving the quotient, it yields the remainder
Operators (contd.)
Increment (++) and Decrement Operators ( - - ) increase and decrease the original values assigned to them by 1 example: a++; will yield an equivalent result to a=a+1; a --; is the same as a=a1;
Operators (contd.)
Relational Operators (==, !=, >, <, >=, <=) perform a comparison test between variables and constants Logical Operators (&&, ||, !) further expand the relational operators since they add more control to it