Programming Methodology by Anh Duong

Embed Size (px)

Citation preview

  • 8/3/2019 Programming Methodology by Anh Duong

    1/12

    Programming Methodology

    By:

    Anh Duong

  • 8/3/2019 Programming Methodology by Anh Duong

    2/12

  • 8/3/2019 Programming Methodology by Anh Duong

    3/12

    Programming Methodology

    By:

    Anh Duong

    Online:< http://cnx.org/content/col10450/1.1/ >

    C O N N E X I O N S

    Rice University, Houston, Texas

  • 8/3/2019 Programming Methodology by Anh Duong

    4/12

    T h i s s e l e c t i o n a n d a r r a n g e m e n t o f c o n t e n t a s a c o l l e c t i o n i s c o p y r i g h t e d b y A n h D u o n g . I t i s l i c e n s e d u n d e r t h e

    C r e a t i v e C o m m o n s A t t r i b u t i o n 2 . 0 l i c e n s e ( h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 2 . 0 / ) .

    C o l l e c t i o n s t r u c t u r e r e v i s e d : A u g u s t 2 2 , 2 0 0 7

    P D F g e n e r a t e d : M a r c h 1 9 , 2 0 1 0

    F o r c o p y r i g h t a n d a t t r i b u t i o n i n f o r m a t i o n f o r t h e m o d u l e s c o n t a i n e d i n t h i s c o l l e c t i o n , s e e p . 5 .

  • 8/3/2019 Programming Methodology by Anh Duong

    5/12

    T a b l e o f C o n t e n t s

    1 I n t r o d u c t i o n

    1 . 1 P C A r c h i t e c t u r e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    2 B a s i c C + +

    I n d e x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    A t t r i b u t i o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

  • 8/3/2019 Programming Methodology by Anh Duong

    6/12

    i v

  • 8/3/2019 Programming Methodology by Anh Duong

    7/12

    C h a p t e r 1

    I n t r o d u c t i o n

    1 . 1 P C A r c h i t e c t u r e

    1 . 1 . 1 c o m p u t e r a r c h i t e c t u r e

    1

    1 . 1 . 1 . 1 C o m p u t e r H a r d w a r e

    A c o m p u t e r m a y b e d i v i d e d i n t o s i x l o g i c a l u n i t s .

    I n p u t U n i t

    O b t a i n i n f o r m a t i o n f r o m i n p u t d e v i c e s : k e y b o a r d s a n d m o u s e d e v i c e s .

    P l a c e t h e i n f o r m a t i o n a t t h e d i s p o s a l o f t h e o t h e r u n i t s t o b e p r o c e s s e d .

    O u t p u t U n i t

    T a k e i n f o r m a t i o n t h a t h a s b e e n p r o c e s s e d .

    P l a c e i t o n o u t p u t d e v i c e s : d i s p l a y e d o n s c r e e n s , p r i n t e d o n p a p e r .

    M e m o r y U n i t

    R A M ( r a n d o m a c c e s s m e m o r y ) i s v o l a t i l e , s t o r e s p r o g r a m a n d d a t a .

    R O M ( r e a d o n l y m e m o r y ) i s n o n - v o l a t i l e , c o n t a i n s f u n d a m e n t a l i n s t r u c t i o n s .

    A r i t h m e t i c a n d L o g i c U n i t ( A L U )

    P e r f o r m a l l t h e a r i t h m e t i c a n d l o g i c o p e r a t i o n s : a d d i t i o n , s u b t r a c t i o n , c o m p a r i s o n , e t c . .

    C P U

    T e l l t h e i n p u t u n i t w h e n i n f o r m a t i o n s h o u l d b e r e a d i n t o t h e m e m o r y u n i t .

    T e l l t h e A L U w h e n i n f o r m a t i o n f r o m t h e m e m o r y s h o u l d b e u s e d i n c a l c u l a t i o n s .

    T e l l t h e o u t p u t u n i t w h e n t o s e n d i n f o r m a t i o n f r o m t h e m e m o r y u n i t t o c e r t a i n o u t p u t d e v i c e s .

    S e c o n d a r y S t o r a g e .

    P e r m a n e n t s t o r a g e a r e a s f o r p r o g r a m s a n d d a t a : m a g n e t i c t a p e s , m a g n e t i c h a r d d i s k s , o p p y d i s k , C D

    R O M

    1

    T h i s c o n t e n t i s a v a i l a b l e o n l i n e a t < h t t p : / / c n x . o r g / c o n t e n t / m 1 5 0 3 9 / 1 . 1 / > .

    1

  • 8/3/2019 Programming Methodology by Anh Duong

    8/12

    2

    C H A P T E R 1 . I N T R O D U C T I O N

    1 . 1 . 1 . 2 C o m p u t e r S o f t w a r e

    A c o m p u t e r p r o g r a m : s e t o f i n s t r u c t i o n s u s e d t o o p e r a t e a c o m p u t e r t o p r o d u c e a s p e c i c r e s u l t .

    C o m p u t e r p r o g r a m m i n g : w r i t i n g c o m p u t e r p r o g r a m s .

    P r o g r a m m i n g l a n g u a g e s : l a n g u a g e s u s e d t o c r e a t e c o m p u t e r p r o g r a m s .

    M a c h i n e L a n g u a g e s

    E x a m p l e : 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0

    T h e l o w e s t l e v e l o f c o m p u t e r l a n g u a g e s .

    P r o g r a m s c o n s i s t o f e n t i r e l y o f 1 s a n d 0 s .

    P r o g r a m s c a n c o n t r o l d i r e c t l y t o t h e c o m p u t e r ' s h a r d w a r e .

    M a c h i n e l a n g u a g e i n s t r u c t i o n s c o n s i s t o f t w o p a r t s :

    I n s t r u c t i o n p a r t ( o p c o d e ) i s t h e l e f t m o s t g r o u p o f b i t s a n d t e l l s t h e c o m p u t e r t h e o p e r a t i o n t o b e

    p e r f o r m e d .

    A d d r e s s p a r t s p e c i e s t h e m e m o r y a d d r e s s o f t h e d a t a t o b e u s e d i n t h e i n s t r u c t i o n .

    A s s e m b l y L a n g u a g e s

    E x a m p l e :

    L O A D B A S E P A Y

    A D D O V E R P A Y

    S T O R E G R O S S P A Y

    P e r f o r m t h e s a m e t a s k s a s m a c h i n e l a n g u a g e s , b u t u s e s y m b o l i c n a m e s f o r o p c o d e s a n d o p e r a n d s .

    A n a s s e m b l y l a n g u a g e p r o g r a m m u s t b e t r a n s l a t e d i n t o a m a c h i n e l a n g u a g e p r o g r a m .

    T r a n s l a t i o n p r o g r a m ( a s s e m b l e r ) M a c h i n e l a n g u a g e p r o g r a m A s s e m b l y l a n g u a g e p r o g r a m

    M a c h i n e l a n g u a g e s a n d a s s e m b l y l a n g u a g e s a r e c a l l e d l o w - l e v e l l a n g u a g e s s i n c e t h e y a r e c l o s e s t t o

    c o m p u t e r h a r d w a r e .

    H i g h - l e v e l P r o g r a m m i n g L a n g u a g e s

    C r e a t e c o m p u t e r p r o g r a m s u s i n g i n s t r u c t i o n s t h a t m u c h e a s i e r t o u n d e r s t a n d : E n g l i s h - l i k e i n c l u d e d

    w i t h m a t h e m a t i c a l n o t a t i o n s .

    P r o g r a m s w r i t t e n i n h i g h - l e v e l l a n g u a g e s m u s t b e t r a n s l a t e d i n t o a l o w l e v e l l a n g u a g e u s i n g a p r o g r a m

    c a l l e d a c o m p i l e r .

    E a c h l i n e i n a h i g h - l e v e l l a n g u a g e p r o g r a m i s c a l l e d a s t a t e m e n t .

    E x : R e s u l t = ( F i r s t + S e c o n d ) * T h i r d .

    A p p l i c a t i o n a n d S y s t e m S o f t w a r e

    A p p l i c a t i o n s o f t w a r e : p e r f o r m p a r t i c u l a r t a s k s r e q u i r e d b y t h e u s e r s .

    S y s t e m s o f t w a r e : m u s t b e a v a i l a b l e t o a n y c o m p u t e r s y s t e m t o o p e r a t e . T h e m o s t i m p o r t a n t s y s t e m

    s o f t w a r e i s t h e o p e r a t i n g s y s t e m ( M S - D O S , U N I X , M S W I N D O W S , M S W I N D O W S N T )

    M u l t i t a s k i n g s y s t e m s : o p e r a t i n g s y s t e m s a l l o w u s e r t o r u n m u l t i p l e p r o g r a m s .

  • 8/3/2019 Programming Methodology by Anh Duong

    9/12

    C h a p t e r 2

    B a s i c C + +

    3

  • 8/3/2019 Programming Methodology by Anh Duong

    10/12

    4

    I N D E X

    I n d e x o f K e y w o r d s a n d T e r m s

    K e y w o r d s a r e l i s t e d b y t h e s e c t i o n w i t h t h a t k e y w o r d ( p a g e n u m b e r s a r e i n p a r e n t h e s e s ) . K e y w o r d s

    d o n o t n e c e s s a r i l y a p p e a r i n t h e t e x t o f t h e p a g e . T h e y a r e m e r e l y a s s o c i a t e d w i t h t h a t s e c t i o n . E x .

    a p p l e s , 1 . 1 ( 1 ) T e r m s a r e r e f e r e n c e d b y t h e p a g e t h e y a p p e a r o n . E x . a p p l e s , 1

    Aa r c h i t e c t u r e , 1 . 1 . 1 ( 1 )

    Cc o m p u t e r , 1 . 1 . 1 ( 1 )

  • 8/3/2019 Programming Methodology by Anh Duong

    11/12

    A T T R I B U T I O N S 5

    A t t r i b u t i o n s

    C o l l e c t i o n : P r o g r a m m i n g M e t h o d o l o g y

    E d i t e d b y : A n h D u o n g

    U R L : h t t p : / / c n x . o r g / c o n t e n t / c o l 1 0 4 5 0 / 1 . 1 /

    L i c e n s e : h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 2 . 0 /

    M o d u l e : " c o m p u t e r a r c h i t e c t u r e "

    B y : A n h D u o n g

    U R L : h t t p : / / c n x . o r g / c o n t e n t / m 1 5 0 3 9 / 1 . 1 /

    P a g e s : 1 - 2

    C o p y r i g h t : A n h D u o n g

    L i c e n s e : h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 2 . 0 /

  • 8/3/2019 Programming Methodology by Anh Duong

    12/12

    P r o g r a m m i n g M e t h o d o l o g y

    T h i s c o u r s e p r o v i d e s s t u d e n t s w i t h m e t h o d o l o g y i n p r o g r a m m i n g , u s i n g C + + i n a l m o s t e x a m p l e s .

    A b o u t C o n n e x i o n s

    S i n c e 1 9 9 9 , C o n n e x i o n s h a s b e e n p i o n e e r i n g a g l o b a l s y s t e m w h e r e a n y o n e c a n c r e a t e c o u r s e m a t e r i a l s a n d

    m a k e t h e m f u l l y a c c e s s i b l e a n d e a s i l y r e u s a b l e f r e e o f c h a r g e . W e a r e a W e b - b a s e d a u t h o r i n g , t e a c h i n g a n d

    l e a r n i n g e n v i r o n m e n t o p e n t o a n y o n e i n t e r e s t e d i n e d u c a t i o n , i n c l u d i n g s t u d e n t s , t e a c h e r s , p r o f e s s o r s a n d

    l i f e l o n g l e a r n e r s . W e c o n n e c t i d e a s a n d f a c i l i t a t e e d u c a t i o n a l c o m m u n i t i e s .

    C o n n e x i o n s ' s m o d u l a r , i n t e r a c t i v e c o u r s e s a r e i n u s e w o r l d w i d e b y u n i v e r s i t i e s , c o m m u n i t y c o l l e g e s , K - 1 2

    s c h o o l s , d i s t a n c e l e a r n e r s , a n d l i f e l o n g l e a r n e r s . C o n n e x i o n s m a t e r i a l s a r e i n m a n y l a n g u a g e s , i n c l u d i n g

    E n g l i s h , S p a n i s h , C h i n e s e , J a p a n e s e , I t a l i a n , V i e t n a m e s e , F r e n c h , P o r t u g u e s e , a n d T h a i . C o n n e x i o n s i s p a r t

    o f a n e x c i t i n g n e w i n f o r m a t i o n d i s t r i b u t i o n s y s t e m t h a t a l l o w s f o r P r i n t o n D e m a n d B o o k s . C o n n e x i o n s

    h a s p a r t n e r e d w i t h i n n o v a t i v e o n - d e m a n d p u b l i s h e r Q O O P t o a c c e l e r a t e t h e d e l i v e r y o f p r i n t e d c o u r s e

    m a t e r i a l s a n d t e x t b o o k s i n t o c l a s s r o o m s w o r l d w i d e a t l o w e r p r i c e s t h a n t r a d i t i o n a l a c a d e m i c p u b l i s h e r s .