Foundations of Programming Part I
Upcoming SlideShare
Loading in...5
×
 

Foundations of Programming Part I

on

  • 458 views

 

Statistics

Views

Total Views
458
Slideshare-icon Views on SlideShare
449
Embed Views
9

Actions

Likes
1
Downloads
0
Comments
0

2 Embeds 9

http://acm.vnit.ac.in 7
http://localhost 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Foundations of Programming Part I Foundations of Programming Part I Presentation Transcript

    • Jayesh Joy Meher Anand
    • The Hardware
      • Programming – Making hardware perform an action in a desired way
      • Digital circuits are binary, they can understand only 0 and 1
      • Modern day processors are made from transistors, millions of them
      • Work in time of the order of 10 -9 seconds
    • Evolution of Programming Languages
      • Machine language – consists of 0s and 1s only
      • Very hard to read and debug
      • Time consuming
      • Low level language
      • Platform dependent
    • Evolution (contd...)
      • Assembly language – consists of mnemonics and opcodes
      • Ex:- MOV A,B
      • Better readability but not sufficient
      • Hard to debug but better than machine code
      • Low level language
      • Platform dependent
    • Evolution (contd...)
      • High level languages – English-like constructs, definitions, declarations.
      • Easier to read, debug and maintain
      • Ex- C, C++, C#, Java etc.
      • Platform independent
    • The Hello World Program
      • #include<iostream>
      • using namespace std;
      • //This is my first program
      • int main()‏
      • {
        • cout<<”Hello, World!”<<endl;
        • return 0;
      • }
    • Explanation
      • Program execution starts from main(), also known as PROGRAM ENTRY POINT
      • cout<< prints the text following it on to the screen
      • endl is equivalent to the Enter key on the keyboard. Starts off at the next line, the next time.
      • Blindly include the blue parts in the code for now
    • Data
      • Programs can take in data, operate on it and give an output
      • Data is stored in variables.
      • Each variable is of a certain “Data Type”
      • Primitive (or standard) data types –
        • Integers (int)‏
        • floating point (real) numbers (float)‏
        • Characters (char)‏
    • Declarations
      • Tell the machine that you want to create a variable of a particular data type
      • Assign a name to a particular variable
      • Assign a value to it and start using it
      • Example declaration – Declare an integer variable with the name 'apples' and assign a value 40 to it
      • int no_of_apples;
      • no_of_apples=40;
    • Input
      • Take in data from the user (keyboard) while the program is running
      • cin>> operator instructs machine to take in input from user
    • Example program
      • Example 1
    • Operators
      • Basic Arithmetic: +, -, /, *, %
        • Can be used for operations on int & float values.
      • Bitwise: & (and) , | (or) , ^ (xor)‏
      • Relational and Logical: <, >, <=, >=, ==, !=, && (and) , || (or) , ! (not)‏
      • Sign: -, +
      • Increment and Decrement: ++, --
    • Hierarchy of Operators
      • () []
      • ! ~ ++ -- + - (all are unary operators)‏
      • * / %
      • + -
      • << >>
      • < <= > >=
      • == !=
    • Hierarchy of Operators (contd.)
      • &
      • ^
      • |
      • &&
      • ||
      • ?:
      • = += -= *= /= %= &= ^= |= <<= >>=
      • ,
    • Control flow
      • The following statements are used to control the order in which statements are executed:
        • Selection statements:
          • if, if else, switch
        • Iterative Loops:
          • while, do while, for
    • Selection Statements
      • Used to choose which statements to execute based on certain conditions
      • Example 2
      • Example 3
      • Example 4
    • Flow Chart Yes No Entry Exit number>=0 Take input into number Print on screen “number is non-negative”
    • Iterative Loops
      • Perform repetitive tasks
        • If we want to perform certain tasks for a certain number of times or until a certain condition is met.
        • Three types of loops are used:
          • while (example 5)
          • do while (example 6)
          • for (example 7)
    • Nested Loops
      • Example 8