Week 4

Today we will:

Implementation of header files

matrix multiplication in C++

 

Header Files

  • Header files are used in OOP for C++, to blue print structures.
  • When creating class structures c++ you will need to use a header file for other files to reference.
  • They describe the class structure, not how.

 

Why do we use them?
  • From C programming, uses similar compile methods for its program.

 

How we do it?
  • First two lines and last line are the same in all your files

 

img_7256

 

#ifndef EXAMPLE_H

#define EXAMPLE_H

  • If the header file hasn’t been defined move to the second line and define the thing.

 

  • Rest of the statement describes what we expect to see in the class.
  • Inside the class example there will be a number of private and public things.

 

#endif 

  • End of the header file

 

 

Example in .cpp

 

img_7257

 

 

  • Set and get name.

 

Test. cpp File

  • include all of the libraries from the previous sections

int main 

  • what the complier looks for, so we must star with it.

 

img_7258

  • Create a string called uName
  • Instantiate an example – Make an object of that class
  • Then we ask what the user’s name is
  • User provides name and we hold it in the holding variable
  • Then we send a message out saying Hello and the name that was stored.

Matrix Multiplication

img_7259

 

 

  • Take some input and some output

int main()

   float sniperPositions[1][4]4, firstPositionTransition[4][4], hold[1][4];

  • Instantiation of 3 float matrices 
  • hold matrices needs to be the same as the sniperPosition. 
  • Next four lines is all the values for the safe areas different areas
  • Next lines are for all the values possible.

 

img_7260

for(int …..

 

}

  • Making hold value 0 each time

 

for (int i=0 ….

 

}

 

  • Printing out the initial safe values for the snipper locations (as a way to compare to )

 

img_7261

 

for(int ….

 

}

  • Refer to the position in the holding matrix and we add to that position the first value in sniper position with the first position transition value. (Doing the matrix multiplication)

 

 

running the code

screen-shot-2016-10-25-at-11-30-36

screen-shot-2016-10-25-at-11-33-51