Introduction to Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Programming

Description:

Title: Introduction to Programming Subject: Review Lecture Author: Muhammad Haseeb Khan Last modified by: umer.farooq Created Date: 1/10/2003 8:17:08 AM – PowerPoint PPT presentation

Number of Views:139
Avg rating:3.0/5.0
Slides: 39
Provided by: Muham93
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Programming


1
Introduction to Programming
  • Lecture 45

2
Assignment Operator
A B
3
Class Matrix
  • const Matrix operator ( const Matrix m )

4
Assignment Operator
( A B ) C
5
Self Assignment
A A
6
Class Matrix
  • const Matrix Matrix operator ( const
    Matrix m )
  • if ( m ! this)
  • if ( numRows ! m.numRows numCols !
    m.numCols )
  • delete elements
  • elements new ( double ) m.numRows
  • for ( int i 0 i lt m.numRows i
    )
  • elements i new double
    m.numCols

7
Class Matrix
  • numRows m.numRows
  • numCols m.numCols
  • for ( int i 0 i lt numRows i )
  • for ( int j 0 j lt numCols j )
  • elements i j
    m.elements i j
  • return this

8
Addition Operator
9
Addition Operator
A B
Both A and B are Matrices
10
Class Matix
  • Matrix Matrix operator ( Matrix m ) const
  • // Check for conformability
  • if ( numRows m.numRows numCols
    m.numCols )
  • Matrix temp ( this )
  • for ( int i 0 i lt numRows i )
  • for ( int j 0 j lt numCols j )
  • temp.elements i j
    m.elements i j
  • return temp
  • Matrix temp ( this )
  • return temp

850
11
Operator
12
Operator
A B
13
Class Matrix
  • const Matrix Matrix operator ( Matrix m
    )
  • this this m
  • return this

14
Class Matrix
  • Matrix Matrix operator ( double d ) const
  • Matrix temp ( this )
  • for ( int i 0 i lt numRows i )
  • for ( int j 0 j lt numCols j )
  • temp.elements i j d
  • return temp

15
Class Matrix
  • Matrix operator ( double d , Matrix m )
  • Matrix temp ( m )
  • for ( int i 0 i lt temp.numRows i
    )
  • for ( int j 0 j lt temp.numCols
    j )
  • temp.elements i j
    d
  • return temp

1300
16
Operator
17
Class Matrix
  • Matrix Matrix operator ( const Matrix m )
  • Matrix temp ( numRows , m.numCols )
  • if ( numCols m.numRows )
  • for ( int i 0 i lt numRows i )
  • for ( int j 0 j lt m.numCols j
    )
  • temp.elements i j 0.0
  • for ( int k 0 k lt numCols k
    )
  • temp.elements i j
    elements i k m.elements k j
  • return temp

18
Class Matrix
  • Matrix Matrix operator ( double d ) const
  • Matrix temp ( this )
  • for ( int i 0 i lt numRows i )
  • for ( int j 0 j lt numCols j )
  • temp.elements i j d
  • return temp

19
Matrix / d Check d 0 ?
20
ltlt Insertion Operator
gtgt Extraction Operator
21
Where m is an object of the class Matrix
cin gtgt m
22
Class Matrix
  • istream operator gtgt ( istream is , Matrix
    m )
  • m.input ( is )
  • return is

23
Class Matrix
  • ifstream operator gtgt ( ifstream is , Matrix
    m )
  • m.input ( is )
  • return is

24
Class Matrix
  • ostream operator ltlt ( ostream os , Matrix
    m )
  • m.output ( )
  • return os
  • ofstream operator ltlt ( ofstream os , Matrix
    m )
  • m.output ( os )
  • return os

25
  • main ( )
  • Matrix m ( 3 , 3 )
  • m.output ( )

26
Template for Matrix Class
27
Rules for Programming
  • Sequences
  • Decisions
  • Loops

28
Variable
Variable is a name for a value
29
Pointer
  • Pointer is the address
  • of a location in the
  • memory

30
Arrays
31
Decisions
Or if ( condition
) statement ( s ) else if ( condition
) statement ( s )
if ( condition ) statement ( s )
Or if ( condition
) statement ( s ) else statement
( s )
32
Repetition Structure
  • There are three kinds of Loops in C Language
  • while
  • do while
  • for

33
Classes and Objects
34
Classes and Objects
  • Object.member

35
Garbage Collection
36
Truth Table
37
  • Structured Query Language
  • SQL

38
  • Optimizer
Write a Comment
User Comments (0)
About PowerShow.com