Presentation is loading. Please wait.

Presentation is loading. Please wait.


Similar presentations

Presentation on theme: "COMPUTER SCIENCE I C++ INTRODUCTION"— Presentation transcript:


2 LANGUAGES There are 3 types of Computer Languages 1. Machine Language Only language that the computer directly understands. “Natural language” of the computer Defined by the hardware design (Machine-dependant) Generally consists of strings of numbers (Ultimately 0’s and 1’s) Instructs computers to perform elementary operations - One at a time Cumbersome for humans (or computer science students) Example : +1300042774 +1400593419 +1200274027

3 LANGUAGES (CONTINUED) 2. Assembly Language English-like abbreviations representing elementary computer operations Clearer to humans Incomprehensible to computers!!! -Translator programs (Assemblers) convert Assembly to Machine Language Example : LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

4 LANGUAGES (CONTINUED) 3. High-level languages Similar to everyday English, use common mathematical notations Single statements accomplish significant tasks - Assembly languages requires many instructions to accomplish simple tasks Translator Programs(Compilers) Convert high-level language to machine language Interpreter programs, directly execute high-level language programs Example : grossPay = basePay + overTimePay

5 HISTORY OF C++ This is an extension of C, it was developed in the early 1980’s by Bjarne Stroustrup (Bell Laboratories) Originally “Spruces up” C! … C++ Provides capabilities for object-orientated programming Objects : reusable software components - they Model items in the real world Object-oriented programs - easy to understand, correct, and modify C++ facilitates structured and disciplined approach to computer program design

6 C++ STANDARD LIBRARY C++ Programs are built from pieces called classes and functions C++ standard library are rich collections of existing classes and functions C++ is a “Building block approach” to creating programs KEY IDEA is SOFTWARE REUSE!!!

7 PHASES OF C++ PROGRAMS 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute

8 BASICS OF C++ ENVIROMENT Input/output - cin Standard input stream Normally keyboard - cout Standard output stream Normally computer screen - cerr Standard error stream Display error messages

9 PRINTING A LINE OF TEXT Comments - Document programs - Improve program readability - Ignored by compiler - Single-line comment Begin with // - Block comment Begin with /* Closes with */ // is best for one line, but when doing a heading to identify whose program this particular program is… Use block comment!!!

10 C++ Preprocessor directives - Processed by preprocessor before compiling - Begins with # List of Standard Libraries (you won’t need all of these) but its good to go through and read the libraries for now.

11 PRINTING A LINE (CONTINUED) Standard output stream object - std : : cout - “connected” to screen - << Stream insertion operator Value to right (right operand) inserted into output stream Namespace - std : : - specifies using name that belongs to namespace std - std : : removed through use of using statements using namespace std;

12 ESCAPE CHARACTERS C++ Escape Characters - \ - Indicates “special” character output

13 VARIABLES -Locations in memory where value can be stored -Common data types -int – integer numbers -char – characters -double – floating point numbers -Declare variables with name and data type before use -int integer1; -int number2; -int sum; -Can declare several variables of same type in one declaration -Comma separated list -int integer1, number2, sum;

14 VARIABLES Variable names Valid identifiers - Series of characters (letters, digits, underscores) - Cannot begin with digit - Case sensititve

15 SIMPLE PROGRAMS Input stream object - >> (stream extraction operator) used with std :: cin Waits for user to input value, then press Enter (Return) key Stores values invariable to right of operator - convert value to variable data type - = (assignment operator) - assigns value to variable - binary operator (two operands) Example : sum = variable1 + variable2;

16 ARITHMETIC Arithmetic Calculations - * Multiplications - / Division Integer division truncates remainder - 7 / 5 evaluates to 1 - % Modulus operator returns remainder - 7 % 5 evaluates to 2

17 ARITHMETIC Rules of operator precedence Operators in parentheses evaluated first Nested/embedded parentheses - Operators in innermost pair first Multiplication, division, modulus applied next Operators applied from left to right Addition, subtraction applied last

18 DECISION MAKING : EQUALITY AND RELATION OPERATORS if Structure Make decision based on truth or falsity of condition If condition met, body executed Else, body not executed Equality and relational operators Equality operators same level of precedence Relational operators same level of precedence Associate left to right if (x == 1) { // do work } else { // do something else }



Similar presentations

Ads by Google