• Like
Foundations of Programming Part II
Upcoming SlideShare
Loading in...5
×

Foundations of Programming Part II

  • 191 views
Uploaded on

 

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
191
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Jayesh Joy Meher Anand
  • 2. Recap
    • Display using cout<< , read input using cin>>
    • Declare variables of different types
    • Control flow:
      • if, else if, else
      • switch case
      • for
      • while
  • 3. Arrays
    • Collection of variables of the same data type
    • Saves trouble of remembering ‘n’ number of related variables of the same type
    • Name and size of array given during declaration
    • Eg:- int apples[10] – Creates a set of 10 integers. The set is called apples
    • Indices vary between 0 and n-1.
    • apples[0], apples[1] … apples[8], apples[9]
  • 4. Multidimensional arrays
    • 2-D arrays are similar to matrices in mathematics
    • Referencing as follows: m [x] [y]
    • x -> Row no.
    • y -> Column no.
    • Declaration:- int m [10][20] ;
      • 10 rows, 20 columns
  • 5. Example
  • 6. Structures
    • Limitations of array – set of variables of same type
    • Structures used to overcome this limitation
    • Eg:- struct student {
    • string name;
    • int age;
    • float marks[10];
    • };
  • 7. Structures (contd…)
    • Example declaration:- student stdnt1;
    • Access variables using ‘.’ operator
    • Ex:- stdnt1.name , stdnt1.marks[2]
  • 8. Functions
    • Segment of code designed to accomplish a certain task
    • Similar to mathematical functions
    • Takes in some input, does some computation and gives some output
    • Why use functions?
      • Avoid repetitions
      • Easier to read and fix
  • 9. Functions (contd…)
    • A function may take in parameters and may return a value
    • The type of each parameter has to be specified
    • The type of the return value must also be specified
  • 10. Function declarations
    • int func ( int a, float b )
    • {
    • //Some computation to be performed here
    • return x; //’x’ is of type integer
    • }
    • void return type is used when the function does not return anything
    • void print_hello ()
    • { cout<<“HELLO”; }
  • 11. Example
  • 12. Principles of Recursion
    • Analogous to recurrence relations in mathematics
    • Solution depends on solutions to smaller instances of the same problem
    • It also means that a function can call itself
    • Ex:- Factorial (n) = ( Factorial (n-1) ) * n
    • Here Factorial (n) is a problem and Factorial (n-1) is a smaller sub-problem
  • 13. Example