Introduction to Programming Lecture 14 Code calculate Salary

![Code calculate. Salary ( int sal [ ] [ 2 ] , int lucky Code calculate. Salary ( int sal [ ] [ 2 ] , int lucky](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-2.jpg)
![Code else { if ( sal [ i ] [ 0 ] <= 10000 Code else { if ( sal [ i ] [ 0 ] <= 10000](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-3.jpg)
![Code else { if ( sal [ i ] [ 0 ] <= 20000 Code else { if ( sal [ i ] [ 0 ] <= 20000](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-4.jpg)
![Code else { sal [ i ] [ 1 ] = sal [ i Code else { sal [ i ] [ 1 ] = sal [ i](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-5.jpg)

![if ( gross. Salary > sal [ i ] [ 0 ] && net. if ( gross. Salary > sal [ i ] [ 0 ] && net.](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-7.jpg)
![Code void locate. Unlucky. Individual ( int sal [ ] [ 2 ] , Code void locate. Unlucky. Individual ( int sal [ ] [ 2 ] ,](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-8.jpg)
![Code void display. Output ( int sal [ ] [ 2 ] , int Code void display. Output ( int sal [ ] [ 2 ] , int](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-9.jpg)











![Declaring pointers int *ptr , x , a [ 10 ] ; Declaring pointers int *ptr , x , a [ 10 ] ;](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-21.jpg)








![Array int a [ 10 ] ; Starting Address of Array a 1 2 Array int a [ 10 ] ; Starting Address of Array a 1 2](https://slidetodoc.com/presentation_image_h2/cd469604560f5f9ab50ea479c562ac20/image-30.jpg)
- Slides: 30
Introduction to Programming Lecture 14
Code calculate. Salary ( int sal [ ] [ 2 ] , int lucky [ ] , int num. Emps ) { for ( i = 0 ; i < num. Emps ; i ++ ) { // net. Salary = gross. Salary – tax if ( sal [ i ] [ 0 ] <= 5000 ) { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] ; }
Code else { if ( sal [ i ] [ 0 ] <= 10000 ) { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] - 0. 05*sal [ i ] [ 0 ] ; }
Code else { if ( sal [ i ] [ 0 ] <= 20000 ) { sal [ I ] [ 1 ] = sal [ I ] [ 0 ] - 0. 1 * sal [ I ] [ 0 ] ; }
Code else { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] - 0. 15 * sal [ i ] [ 0 ] ; } }
if ( gross. Salary > sal [ i ] [ 0 ] && net. Salary < sal [ i ] [ 1 ] ) This logic will fail
Code void locate. Unlucky. Individual ( int sal [ ] [ 2 ] , int lucky [ ] , int num. Emps ) { int i , j ; int gross. Salary , net. Salary ; } } for ( i = 0 ; i < num. Emp ; i ++ ) { gross. Salary = sal [ i ] [ 0 ] ; net. Salary = sal [ i ] [ 1 ] ; for ( j = 0 ; j < num. Emp ; j ++ ) { if ( gross. Salary > sal [ j ] [ 0 ] && net. Salary < sal [ j ] [ 1 ] ) { lucky [ i ] = 1 ; } }
Code void display. Output ( int sal [ ] [ 2 ] , int lucky [ ] , int num. Emps ) { for ( i = 0 ; i < num. Emp ; i ++ ) { if ( lucky [ i ] == 1 ) { cout<< “Employee No. ” << i+1 << “ is unlucky, Gross Salary = ” << sal [ i ] [ 0 ] << “ Net Salary = ” << sal [ i ] [ 1 ] << “n” ; } } }
Pointers
Pointers Location x 60000 Address of x 10
Declaring Pointer to Integer int *myptr ; myptr is pointer to an integer
Declaring Pointers double *x ; char *c ;
Example int *ptr ; int x ; x = 10 ; ptr = &x ;
Dereferencing Operator * *ptr is read as “The value of what ever ptr points to”
z = *ptr * 2 ;
Initializing Pointers ptr = &var ; ptr = 0 ; ptr = NULL ; 0 and NULL points to nothing
Example main ( ) { int num. Emp ; …. funct ( &num. Emp ) ; …. } void funct ( int *num. Emp ) { cin >> *num. Emp ; }
Declaring pointers int *ptr 1 , *ptr 2 , *ptr 3 ;
Declaring pointers int *ptr , x ;
Declaring pointers int *ptr , x , a [ 10 ] ;
Bubble Sort 5 1 1 5 3 2 3 3 5 3 6 6 4 2 2 5 4 6 8 8 9 9 6 9 2 4 8 9 4 8
Swapping
Swap temp = x ; x=y; y = temp ;
Example main ( ) { int x = 10 , y = 20 , * yptr , * xptr ; yptr = &y ; xptr = &x ; swap ( yptr , xptr ) ; }
Example swap ( int *yptr , int *xptr ) { ……… }
const int *const myptr = &x ; myptr is a constant pointer to an integer
const int x = 10 ;
const int *myptr = &x ; myptr is a pointer to a constant integer
Array int a [ 10 ] ; Starting Address of Array a 1 2 3 4 5 6 7 8 9 10