IP - Mod 1 - Introduction to C++, Lecture notes of Programming Paradigms

Basic Elements Of A C++ Program Object-Oriented Programming in C++ Procedural Programming – C C++ Programming and its Basic Components Program Development Lifecycle Programming Languages and its Evolution

Typology: Lecture notes

2020/2021

Available from 04/02/2022

gwen-hermo
gwen-hermo 🇵🇭

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Intermediate Programming C++ Chapter 1
1. Programming Languages and its Evolution
Computers - created to solve intricate mathematical problems
- not yet self-aware or cannot program themselves
- need the direction of human beings in order to perform a specified task
Programs tasks in computer
Algorithms step by step procedure
- functions on a very strict grammatical rules with no tolerance for ambiguity
- must be in tedious detail so that a given task may be accomplished as desired
Machine Language
Inside a computer all data are represented by the states of tiny electronic switches. These
switches which are basically microscopic transistors has 1’s and 0’s state.
The machine language of one machine differs from the machine language of the other.
Assembly Language
Mnemonics were made in order to make the machine language easy-to-remember.
- Mnemonics - as memory aids are alphabetic abbreviations for machine instruction and
- paved way for assembly languages that made the programmer’s job easier
the computer would not directly understand these mnemonics
Assembler is required to translate these mnemonics to its machine instruction counterpart.
High Level Language
closer to natural languages
compiler is needed to convert a high level language instruction into machine language
2. Program Development Lifecycle
pf3
pf4
pf5

Partial preview of the text

Download IP - Mod 1 - Introduction to C++ and more Lecture notes Programming Paradigms in PDF only on Docsity!

1. Programming Languages and its EvolutionComputers - created to solve intricate mathematical problems - not yet self-aware or cannot program themselves - need the direction of human beings in order to perform a specified task ➢ Programs – tasks in computer ➢ Algorithms – step by step procedure - functions on a very strict grammatical rules with no tolerance for ambiguity - must be in tedious detail so that a given task may be accomplished as desired Machine Language ➢ Inside a computer all data are represented by the states of tiny electronic switches. These switches which are basically microscopic transistors has 1’s and 0’s state. ➢ The machine language of one machine differs from the machine language of the other. Assembly Language ➢ Mnemonics were made in order to make the machine language easy-to-remember. - Mnemonics - as memory aids are alphabetic abbreviations for machine instruction and - paved way for assembly languages that made the programmer’s job easier ➢ the computer would not directly understand these mnemonics ➢ Assembler is required to translate these mnemonics to its machine instruction counterpart. High Level Language ➢ closer to natural languages ➢ compiler is needed to convert a high level language instruction into machine language 2. Program Development Lifecycle

Systematic approach - necessary in order to achieve the specified objectives; enables the programmer not only to solve the problem but also outline documentation on how the solution came about

  • Problem Solving Process o 1. Analyze the problem - Identify the input requirements, solution requirements, and output requirements. o 2. Design an algorithm based on the requirements. o 3. Convert the algorithm into a C++ code then check and debug the errors. o 4. Modify the program if necessary 3. C++ Programming and its Basic Components ➢ regarded as C programming language with classes together with other modern features ➢ Dennis Ritchie - at AT&T Bell Laboratories in the 1970’s ( C ) ➢ used to create and maintain the UNIX operating system up until now ➢ employed to write a variety of program but its popularity came to prominence since it is closely linked to UNIX operating system ➢ Automatic checks that is available to most high-level language is absent in C. ➢ Bjarne Stroustrup - develop C++ in the 1980’s - designed C++ as a subset of C and made C++ better than C - Lacking features on C such as a facility for classes of object-oriented programming and automatic checks were addressed in C++.
  • Procedural Programming – C ➢ a programming model which is derived from structured programming , based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply consist of a series of computational steps to be carried out. During a program’s execution, any given procedure might be called at any point, including by other procedures or itself. ➢ Structured Programming - brings clarity, straightforwardness of maintenance and reliability to a small-scale program ➢ top-down approach focuses on breaking down a big problem into smaller and understandable chunks

SOURCE : https://www.geeksforgeeks.org/differences-between-procedural-and-object-oriented- programming/

  • Basic Elements Of A C++ Program o C++ comment - //, / / o Preprocessor - provides the source file with the capabilities provided from the included header file (#include ) - provide the features for your program to communicate from the outside world (input) or to the outside world (output) - cin is for input - cout for output. - header files – ex. o Namespace - to simplify coding by combining preexisting code from different vendors - facility would guide the programmer to which vendor s/he mean - ex. , Vendor1:: abc() Vendor2:: abc() o Main() function - entry point of your program ❖ function header – summarizes the function’s interface with entire program (ex. int main ()) ❖ Function body – denote the instructions the must be executed by the computer. (ex. {..} ) ❖ Statement - Each complete instruction ❖ Semicolon - each statement must end 4. Declaring Variables and Primitive Data Types
  • Identifiers - the name that a variable would have ➢ Must begin with either a letter or an underscore and the rest of the characters may be a letter, underscore, or digit. ➢ case sensitive ➢ camel case - mix the upper case with the lowercase by using the uppercase character to indicate a word boundary ➢ Reserved words - predefined names in C++ and the programmer is not allowed to use it as names for variables

Keywords - not part of the core C++ language and are defined in headers

  • C++ datatypes ➢ the way C++ categorizes data according to the operation fit to it ➢ Before a variable would be used, it must be declared first. ➢ When a variable is declared, you are stating to the compiler, eventually the computer to allocate memory for storing the variable. ➢ Major Datatype Categories: o Simple datatype - the building blocks of structured data type o Structured datatype o Pointers Simple Datatype → the building blocks of structured data type o Integral – these are the data types without a decimal place. - so if a number with a decimal place would be assigned to it, only the whole number part would be considered. - for bool datatype - by default or be unsigned o Floating point – are data types that deal with real numbers (i.e. numbers with o decimal places) o Enumeration - are user defined datatypes
  • Assignment operator ➢ equal sign = ➢ left side operand (variable) accept whatever the evaluated value of the right hand operand (expression). Ex: int x = 10; int sum = 5 + x; ➢ not an equality operator - it does not evaluate if the left hand operand is equal with the right hand operand. 5. Arithmetic Operators, Operator Precedence and Associativity
  • Evaluating Mixed Expression

header - to make use of these functions → argument or parameter is the information that is passed to the function and the result will be the return value

6. Programming Form and Style

  • Use of blanks, semicolon, curly braces and commas o Blanks - to separate o Semicolons - used to terminate statements o Curly braces { and } - delimiting brackets ; for enclosing a body of a function o Commas - to separate items in a list
  • Syntax vs Semantics o Syntax - to determine if a statement is legal or illegal. o Semantics - give meaning to statements; there will be no warning message that is provided by the compiler Ex:
  • Naming identifiers and documentation o a named constant will be all in uppercase with an underscore as separator for different words o Self-documenting identifiers
  • Coding formatting for ease of readability o Only one statement per line. o An opening brace and a closing brace must have its own line. o All statements under a brace must be indented