Last active
October 20, 2015 03:05
-
-
Save minhoolee/34001293c565414d06ff to your computer and use it in GitHub Desktop.
MVRT Vision Trainings Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// “Prototypes” help the compiler identify functions that are in the file | |
int sum (int a, int b); | |
double diff (double a, double b); | |
int main () | |
{ | |
std::cout << sum (1, 2) << "\n"; | |
std::cout << diff (5.2, 2.7) << "\n"; | |
} | |
int sum (int a, int b) | |
{ | |
return (a + b); | |
} | |
double diff (double a, double b) | |
{ | |
return (a - b); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main () | |
{ | |
int processId = 123456; | |
// Note: upper case | |
int* pid = NULL; | |
pid = &processId; | |
std::cout << processId << "\n"; | |
std::cout << pid << "\n"; | |
std::cout << *pid << "\n"; | |
std::cout << &pid << "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
// Similar to Java's class | |
// Note: C++ has classes too, which we'll talk about later | |
struct Human | |
{ | |
int age; | |
std::string name; | |
}; | |
int main () | |
{ | |
Human bob; | |
bob.age = 15; | |
bob.name = "Bob Loblaw lobs law bombs while blogging on his law blog"; | |
Human* sally; | |
sally->age = 18; | |
sally->name = "Sally Kim"; | |
std::cout << "Bob's age: " << bob.age << "\n"; | |
std::cout << "Sally's age: " << sally->age << "\n"; | |
std::cout << "Bob's name: " << bob.name << "\n"; | |
std::cout << "Sally's age: " << sally->name << "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main () | |
{ | |
const int PIXELS_PER_INCH = 640; | |
// PIXELS_PER_INCH = 1280; // ERROR | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConstantVariables { | |
private final int PIXELS_PER_INCH = 640; | |
public static void main (String[] args) { | |
// PIXELS_PER_INCH = 1280; // ERROR | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int signalId = 123; // “global variable”, “field” | |
int main () | |
{ | |
int signalId = 456; // “local variable” | |
std::cout << signalId << "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
int main () | |
{ | |
std::string phrase = "Hello World"; | |
std::cout << phrase << "\n"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
int main () | |
{ | |
// 1 byte is 8 bits | |
// 16 bits (–32,768 to 32,767) | |
short twoBytes = 0; | |
// 32 bits (–2,147,483,648 to 2,147,483,647) | |
long fourBytes = 0; | |
// 64 bits (–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) | |
// Depends on the compiler and machine | |
long long int eightBytes = 0LL; | |
// 32 bits | |
std::string word = "Hello World"; | |
// Size in bytes depends on number and types of elements | |
int integerArray[3] = {0, 1, 2}; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main () | |
{ | |
// 1 byte is 8 bits | |
// 32 bits (–2,147,483,648 to 2,147,483,647) | |
int fourBytes = 0; | |
// 32 bits (Positive or Negative: 1.40129846432481707e-45 to 3.40282346638528860e+38) | |
float fourBytesDecimal = 0.0f; | |
// 64 bits (Positive or Negative: 4.94065645841246544e-324d to 1.79769313486231570e+308d) | |
double eightBytesDecimal = 0.0f; | |
// 8 bits | |
char singleLetter = 'a'; | |
// 1 bit (True or False) | |
bool isTrue = false; | |
// wchar_t is a primitive data type, but don't use it because it's not very portable | |
// Also void data type, but variables cannot be of type void | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment