You are on page 1of 69

p 


   

 
 
   

|
p    
     

! p   
! "    

!  
  
!  
 
  #
!   
!   
!    
 
 
!    

m
 
Topics 
! 
$
%      
 &     '
 
! 
   
!   
   
 
!   

!   
! '      
   
!      
!  ' ( )
    *
! 
   ( +  *
! )",   
! %      
  - 
! ' #   (
# *
!     ,./)0     (#   
*

h
 
These information slides give a summary of what is on the course webpage. You are responsible of
reading all of the info on that site.

Text Book 

1   2p3345  (p4%67* !  


p33



   

 ",    89p4",
         p4

:
  ;  (p4<%6=*    


4

:# #       #  & 



   4

Webpage  ))  )  )


)
+ '  ,p>,?   )

 ' # 
 4@    
   #   ,p>,?    '  4

Grading
! Midterm1: 25% ; Midterm2: 25% ; Final: 30% ; Homeworks: 20%
! ; '   (=*   
 A
    

  
 4
! ; ' B ' # 
'   &(6 
  
 ' #'
 6C*4
! Passing grade You must have 40 or higher in your total average and 30 or higher in the final
exam, in order to pass the course!

›
0 ;
Dab Schedule ;  C % D =

; '  
        ' #     ' 
' #A  ' #     4    
     4

:   ' 


   
  

 ' (    
*4

  &              ,p>,?  


  
       ' 4

†
5 ' #
! Through Sucourse only. Anything else will be ignored/deleted.

! Dabel your homework as


! studentid-FirstnameDastname-hw3.zip
! CC6<% "E%'64-
Failure to do so will lose you points.

! Write your name inside the files as well

! Do not use unknown or uncommon file types that we may not be


able to open (
    -    *4

! You may submit your homework multiple times, and you may also
submit late (see below), so make all your submissions there.

â
5 ' #
! Date penalty: Each late day is 10pt off and no homeworks will be
accepted after 2 days in order for the Tas to start grading on time.
Check SUCOURSE for exact due dates for a particular homework.

! Any missing files in your submission (even std. libraries etc.) will
lose you points.

! For complete submission requirements, check the website!


"    


   
You will be responsible from the style/practice
guidelines listed here for all future homeworks/projects.

å
  
;  '   '   
      )  
 
! 7%<F
! :   

4G  


 
! 64 H
!  '  '   )     

       


       
 H

*
"   5
"   5 >  '
     
 
 
p    
,  


   
 

 
 

|
8, ;   5 p 
p 
! How much?: Enough for someone to be able to understand/modify
your code in the future

! When?: Comment when first writing, then as you test and seal code

! You must use sufficient comments as illustrated in the next slide in


each of your homework submissions from now on (penalty: up to
20pts over a 100pts-homework)

! Slide 13 show some different comment styles, but the fact that you
must use comments for each program unit remains unchanged:

!     (I6% *
! 

  $ 
 (IC%6 *
! 
  (I6 *
! 
  (I6 *

||
8, ;   5 p 
p 
/******************************************************************************
Purpose: ;  p # 4
Usage:
#  4
Author: 1  : # On the top (program)
Date: ))C
Any known bugs: ' #   
     
References:  
       
4
******************************************************************************/
...
int totalTime; //total time of the songs in CD in seconds For simple comments
... and variable
/*****************************************************************************
explanations
This function computes the remaining length in the CD, after
writing all the songs in the input file.
Input: ...
Returns: ...
*****************************************************************************/
int RemainingDength(....) For multiline
{ comments and
... major section
} headings

/*****************************************************************************/
/************* Process Input and Format Output *********************/
/*****************************************************************************/
int ctr; //counter for ...

|m
! 
 
 
"   5 
. p   
% .     
! 
>'  ))  %     
! ?
  9 ))
- %  "  
! 8/J ;,.;J.,8 ))
%  
  

! 44
  8/J ;,.;J.,8K6
! ,    G 

!  ))'''4 4
) )
 )
 J
 )   4
   
 
     '    
R R 


% ' # (  *,


  )
   
 ' #
      
   4
% .  
  JL
%   
  ' #    
4R


"   5 
   444
% %    MN
! MN      
!  
         
  

! '  
  
#  

% ,  
  MN
! , MN 
 %     '      
! , MN      
  

 (KOP.,8p0 O33*M
444
N

 

 (KOP.,8p0 O33*
M
444


"   5 
p 1


"   5 
p 
+
)Q' '
 Q)

)Q' 
   Q)
 K64O
64K4O
4K O

)Q' 
   Q)
 K64O
64K4O
4K O

|
"   5 
p 
% %  
  

 
! +   
 # '  
   

%   


   
KCO  K6
K%%% %% O K( 33QC*3( 33Q=*O
)), 33 %%     ))   
 #  
 


Do not confuse compactness with programming efficiency.


A prime example for efficient programming is to move out unneccessary code out of
loops etc., so that no extra computation is done.
Compactness refers to how short your code is. You don¶t want to make your program
unnecessarily long (e.g. two if statements inside one another, even if you could
test for both at once, just as clearly) but not so compact that it is cryptic: rule is to
put only as much code on one line as it is still clearly understandable.


"   5 
p    
%     
 
! ?  '   '    
R     
   '     $
  ' #4

% p    
44:    '

#     
  4  
    
4

  

R R
 R   
R  R
 R 


  R  R  



|*
"   5 
p    
% > A

! :'   'H
! Add comments as you understand the code, for your sake and others in
the future.

%  A  '  
! :  '  ' 

R 44 $%    

R  
   '    ( +      
;)> *       '  ( 
    *   '    
 #  '  

R 1      ( *


4 4     
4

m
 
 p 0 #

?  
5  p46

m|
 

  
   #  
   
     (    *  
 4  
 
     
 
 '
  
  'G
 


! G
 S 4T 
R
   
           

! G    
    
  
    
   
44G   =466B
G  1,"

! G G  G   


  #  

R 44
   '             
 
     

! G G  G    


 $
 ' 
mm
 

! G
   
   
          
 
! G         
  
! G L  
   '          
  
      

 >


  
  !
!
"
 
     


    mh


G 
+    
   

> 
  
' 



     
 '  
J J 4

;    


  
G   =466B
G  8/ U6
G   ?>8 ;V       V


, 
    G 
    G  
   
  
G   =466B

 
     


   K=466BO

1  

   
      
  
'   p 

  '4


p W0 #
;   
          
  
    
 ( 44 4
*4

; 
    $
 ( 4$*4

;  #
 
 $
       
 
  
   48       4


  

m
    
8  
      '
   

  
44
  . - (444*M
444
££ R  R
 RRR


R


  
% +  #    
   '  
   (      ' 
  
  *
6*remove all this debug code (e.g. cout¶s)
R ;
' #   '     '
(     *

*make them conditional to a program variable. 9  



R  
!
 RRR


R


% ;      debug 6      

 
  '     ' 4
% ; 
S( *T  ('      *H
% 5'             
 4
  ' 
     $
      
 

    
        (   
   *      
  )  

  '
  
 4;
      
  
 $
4

m*
  
=*or similarly you can turn them off. 9  

€ R  
 RRR


R


%
*Best: 
   
 '  
 
    on top of
the program  
 Proj./Settings....

>R  "#$%&
 RRR


R
>R

h
    )?  
:'        (
   *  
  (- *
! +     '   
 #  
#

   
 '
    
 

 
 
4     
 4

! >
     '    
  
 
(  
 *'           

     
 
    
 4

!  2pB4:
   S
 
   T 
Project/Settings
Build/Set Active Configuration
Choose Debug mode or Optimize (Release mode)

h|
    )?  
!  2pB4:
   S
 
   T 
Project/Settings
Build/Set Active Configuration
Choose Debug mode or Optimize (Release mode)

!  2 7 
  1  p   8  ( 
  
*

hm
hh
 
 
 ,     


 
 
 ,  ?     


  !
   ! 2 B4
=*or similarly you can turn them off. 9  

€ R  
 RRR


R

*Best: 
   
 '  
 
    
on top of the program  
 Proj./Settings....

>R  "#$%&

 '() 
>R


 
 
     
2 B4

h
  
>R  "#$%&
 RRR


R
>R

! This code will only be compiled if the _DEBUG flag is set during compilation

R _DEBUG is a standard preprocessor directive which is defined in the DEBUG


configuration, but not defined in the Release configuration.

R '    
    


- if the _DEBUG prep. directive is defined, it will remove the #ifdef commands and
include the lines between them (cout << p->Info;) in your program.

- if the _DEBUG prep. directive is NOT defined, the preprocessor will remove the
#ifdef commands AND the lines between them (cout << p->Info;) out of your
program. So your program will be as if you have never written those lines (no extra
tests done etc.)


  
:
   '   
 
 
! :
       
 
    $
)  )444
J1,"'  
! > 
    'SG   5>?;1"T 
4      
££
 R R*

  +
#define SHORTDBG
//#define MAJORDBG
...

#ifdef SHORTDBG

PPSQQQ2  KSPP PP O
#endif

#ifdef MAJORDBG

PPSQQQ2  KSPP PP O

PPSQQQ2  KSPP PP O

PPSQQQ2 KSPPPP O
444
#endif
h*
  
% 1  
 #   R R   

J1,"

>R  "#$%&
> R "$& ££,R-. R 
    R

££> R/01$& ££,R-. R 


    R

>R

;'          


 4 A  
5>?;1" 8X>?1"4 
     ' A   
 
 ' A   4

›
 
 >   
 # |  # |

 $
     


   


     

$     %&%& & &' &    


  
 

›|
 
 >     
 # |  # |

 $
  


   


     

$       %&%& & &' 




  


 

›m
   
      
% ,    

#
     ( 44

  )
  
 *

>  
   
  


   !!  !



"

          


 
   4
         
   (   *4
           

€ 
"
#$% !!   

›h
  
   
%      


#      ( 44
     *

%   



#     ( 44'

    
*

% +(    


4*'  Y
! + '  
      
 ' #    - 
   

››
  
   
% ;    
  V V      
 

 .1,"   
 S
 V 

#define .1," ))S. T


#include P
 Z

%      
   .1,"   
      4

ݠ
 
 
   ?  
2 B4

݉
  
   %% 

   
( )   &   + ,& ,     + +-  .
+& 
 &,/

££"#$%& R* R
R**

>R
  


i  &0 . %&%& & &'   1/

2 i   
   &  '   0 3   3 
3 3 &   4  '& 0        3   %&&     
-     &    &- &%&     &

2 i     + 0    &  -       




›
 4%% 

 4
444
G .1,"

G  assert(exp) ((** ))    

G 
444

G  assert(exp) (*((exp) || (_assert(#exp, __FIDE__, __DINE__), 0) *

G )Q.1,"Q)

Note: In this and the next 2 slides, you dont need to understand how this code works
exactly; but understand the idea of how NDEBUG is checked and used in assert.h
(called by cassert).

݌
 
 >    


 # |  # |

 $
     


   


     

 &5% '  5% 77 $ &5%0 $$8i $$0 $$ i.$$0 


99 & 5%&   & &   5  &  
&& &
66
66

›*
 
 >     


 # |  # |

 $
  


   


     

 &5% ' 

66 66

†
   + #6)
      + #6)
> !
 &
>  

  &  


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
(  ! & ! ) !  * 

)


 
 
 

+
!, - .!
/
,0$0011#
 ,!.!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
!!) !& ! 2! !3
.!


 !
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

)! 4
56
4
7

†|
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
& 
!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
)! & 
6

  
!) 


!
1

>  /8 9

 ! *
   
/8 9!!
> /8 94   
  *
> /8 90 &! 
  *
> 

> /8 94



 ! *
   
/8 9!!
!
: * !&&
! 
! !/8 94: 
> 

4!


> /8 90



 ! *
  /8 90   
!
: * !&&
! 
! !/8 90:  
!
!

> 


!
 1

!
:;  .
!!
:


†m
 
 p 0 # 
4

5  p46

9 
+   

†h
5  " 
    
  
    

    4(8 
 '
 

     
   4*

  '   JpJ5  ' T


4T
   
 
 
 T
4T' A   
    4

G  JpJ5
G  JpJ5

L4

L4

G 

†›
8

; G  
    
'
   

> R %0# 2232

 
      
 ' 
  
   %0# ,R  ',R 3,R

;
   &    '
'   p33
 41'  H

††
 :;45 5<5

†â
 :;45 5<5

†
†å
0 #
p 
 $
       
  

   4

  $
  
       4
!           %  


8#     



! 444

†*
   
8
4    
p  
 #   
!
   $
S
 #   T
 S
  
 T
!   '  ( $
)9 )L
R 44 4
 4
! . 

! 1!    444

,   
! p    $
( 44'*'   
!    
(  ' #*
!         $
( $
)9 L*
! p
! i R


 R R      R



:
 
  
    41'  ' 

 #      '4

â

  
( *0   

;     #


   #     
  
 # (      %
 *4

 
                   

       #     
 4
+ 
     #    
(
   L* &        #  
          45'   $
 
   
          
  4

  '           (


 
 
 *

#'
    '  # ' 
      
   
 
     4
â|
     
 
( *0   
  
! 
    
    
   
  
  4
!    -     
!    
   #

!              
   
  
!       
  
 $
 
 #
       
 ' #$ 4

  
! 0
    (      *!
  
 ! '
!     ')
  
  
 ' ' #4
âm
? 

 
( *0    ? 

      #      ' 4 9   
 
   #    ( 
     
# * &        #        
    45'   $
    
    
      
  4  '        
   (
  
 *

#'
    ' 
 # '       
   

      4

(*   ; 


   
 # 
  
  '    
  '
#%
'     % 
    # '   
   
 
    
     
  49      VpV        
  p  4:   
     
     4;  ' 
         
     
   
  #

' 4

Advanced Note:    '


#    4'  %
   
    
 
 
   '  '  ' [  
#%   
 ' 

         '
     
  '( *   #4;  '  4
âh
8
  
  
2p33    
? 2p33 4
    
      


   4
!  # 
R 9< )1 # 
! ?    # 
R 9C
!    966
!    %966
!    96
! ? 
  p %96
R (  8 .     *

!  
   
R 2  ' '
R +
' '
R @
#'

R p    
R p
#

â†
   $
> 
%  
   

  
! :
 
'  
 # 
  
R Tools/Options/Dirs/Source Files

'  4 4
  #  
   
        A

% 5'  #  '  


   
 
     $

 H
R   
 
 
  
  '     
 
( 44p )p  )p 6)p )*'     $
    
 ( 44
p )p  )p ) $
)  )*4;  '
#'  
 
   '    

    -4

R    
 # 
 ( 

#    * '   
   
 #   

   $
  
 
   ' #     
  
4

Your submitted project must open, find all necessary files, and build with a few clicks!

ââ
 
  )
8
4  
  )

   
!  )  ) 
R Z4) 
! ; '  (
PP  * A 

    
  4

      


!  )  ) 
R P4) 4
! ; S 4T ST(      '  ' 

    *'      
 ( '6*4

â
How to Redirect Output
Right click on Project, choose properties, Debugging properties under
Configuration Properties. Add ³>out.txt´ to Command Arguments to
redirect Standard output that normally goes to the DOS window
(black) to out.txt in Project directory, as shown below (see Fig. 5)
Fig.5. How to redirect output in VS 2008.

âå
â*