Last active
October 26, 2015 21:53
-
-
Save minhoolee/a7dbc4163a2952eabf92 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> | |
using namespace std; | |
class Box | |
{ | |
public: | |
double length; // Length of a box | |
double breadth; // Breadth of a box | |
double height; // Height of a box | |
}; | |
int main( ) | |
{ | |
Box Box1; // Declare Box1 of type Box | |
Box Box2; // Declare Box2 of type Box | |
double volume = 0.0; // Store the volume of a box here | |
// box 1 specification | |
Box1.height = 5.0; | |
Box1.length = 6.0; | |
Box1.breadth = 7.0; | |
// box 2 specification | |
Box2.height = 10.0; | |
Box2.length = 12.0; | |
Box2.breadth = 13.0; | |
// volume of box 1 | |
volume = Box1.height * Box1.length * Box1.breadth; | |
cout << "Volume of Box1 : " << volume <<endl; | |
// volume of box 2 | |
volume = Box2.height * Box2.length * Box2.breadth; | |
cout << "Volume of Box2 : " << volume <<endl; | |
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 <iostream> | |
using namespace std; | |
class Line | |
{ | |
public: | |
void setLength( double len ); | |
double getLength( void ); | |
Line(double len); // This is the constructor | |
private: | |
double length; | |
}; | |
// Member functions definitions including constructor | |
Line::Line( double len) | |
{ | |
cout << "Object is being created, length = " << len << endl; | |
length = len; | |
} | |
void Line::setLength( double len ) | |
{ | |
length = len; | |
} | |
double Line::getLength( void ) | |
{ | |
return length; | |
} | |
// Main function for the program | |
int main( ) | |
{ | |
Line line(10.0); | |
// get initially set length. | |
cout << "Length of line : " << line.getLength() <<endl; | |
// set line length again | |
line.setLength(6.0); | |
cout << "Length of line : " << line.getLength() <<endl; | |
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 <iostream> | |
using namespace std; | |
class Box | |
{ | |
public: | |
double length; // Length of a box | |
// Member functions declaration | |
double getLength(void); | |
void setLength( double len ); | |
}; | |
// Member functions definitions | |
double Box::getLength(void) | |
{ | |
return length; | |
} | |
// Main function for the program | |
int main( ) | |
{ | |
Box Box1; // Declare Box1 of type Box | |
Box Box2; // Declare Box2 of type Box | |
double volume = 0.0; // Store the length of a box here | |
// box 1 specification | |
Box1.setLength(6.0); | |
// box 2 specification | |
Box2.setLength(12.0); | |
// length of box 1 | |
length = Box1.getLength(); | |
cout << "Length of Box1 : " << length << endl; | |
// length of box 2 | |
length = Box2.getLength(); | |
cout << "Length of Box2 : " << length << endl; | |
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 <iostream> | |
using namespace std; | |
class Polygon { | |
protected: | |
int width, height; | |
public: | |
void set_values (int a, int b) | |
{ width=a; height=b;} | |
}; | |
class Rectangle: public Polygon { | |
public: | |
int area () | |
{ return width * height; } | |
}; | |
class Triangle: public Polygon { | |
public: | |
int area () | |
{ return width * height / 2; } | |
}; | |
int main () { | |
Rectangle rect; | |
Triangle trgl; | |
rect.set_values (4,5); | |
trgl.set_values (4,5); | |
cout << rect.area() << '\n'; | |
cout << trgl.area() << '\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 <iostream> | |
using namespace std; | |
class printData | |
{ | |
public: | |
void print(int i) { | |
cout << "Printing int: " << i << endl; | |
} | |
void print(double f) { | |
cout << "Printing float: " << f << endl; | |
} | |
void print(char* c) { | |
cout << "Printing character: " << c << endl; | |
} | |
}; | |
int main(void) | |
{ | |
printData pd; | |
// Call print to print integer | |
pd.print(5); | |
// Call print to print float | |
pd.print(500.263); | |
// Call print to print character | |
pd.print("Hello C++"); | |
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 <iostream> | |
using namespace std; | |
class Box | |
{ | |
public: | |
double getVolume(void) | |
{ | |
return length * breadth * height; | |
} | |
void setLength( double len ) | |
{ | |
length = len; | |
} | |
void setBreadth( double bre ) | |
{ | |
breadth = bre; | |
} | |
void setHeight( double hei ) | |
{ | |
height = hei; | |
} | |
// Overload + operator to add two Box objects. | |
Box operator+(const Box& b) | |
{ | |
Box box; | |
box.length = this->length + b.length; | |
box.breadth = this->breadth + b.breadth; | |
box.height = this->height + b.height; | |
return box; | |
} | |
private: | |
double length; // Length of a box | |
double breadth; // Breadth of a box | |
double height; // Height of a box | |
}; | |
// Main function for the program | |
int main( ) | |
{ | |
Box Box1; // Declare Box1 of type Box | |
Box Box2; // Declare Box2 of type Box | |
Box Box3; // Declare Box3 of type Box | |
double volume = 0.0; // Store the volume of a box here | |
// box 1 specification | |
Box1.setLength(6.0); | |
Box1.setBreadth(7.0); | |
Box1.setHeight(5.0); | |
// box 2 specification | |
Box2.setLength(12.0); | |
Box2.setBreadth(13.0); | |
Box2.setHeight(10.0); | |
// volume of box 1 | |
volume = Box1.getVolume(); | |
cout << "Volume of Box1 : " << volume <<endl; | |
// volume of box 2 | |
volume = Box2.getVolume(); | |
cout << "Volume of Box2 : " << volume <<endl; | |
// Add two object as follows: | |
Box3 = Box1 + Box2; | |
// volume of box 3 | |
volume = Box3.getVolume(); | |
cout << "Volume of Box3 : " << volume <<endl; | |
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 <iostream> | |
int main() | |
{ | |
using namespace std; | |
// Declare an array with 10 elements | |
int Marks [10]= {1,2,3,4,5,6,7,8,9,0}; | |
// Print out the memory address of an array name | |
cout << Marks << endl; | |
// Print out the memory address of a first element of an array | |
cout << &Marks[0] << endl; | |
// Print out value of the first element by dereferencing a array name | |
cout << *Marks << endl; | |
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 <iostream> | |
int main() | |
{ | |
using namespace std; | |
// Declare an integer variable and initialize it with 99 | |
unsigned short int myInt = 99; | |
// Declare and initialize a pointer | |
unsigned short int * pMark = 0; | |
// Print out a value of myInt | |
cout << myInt << endl; | |
// Use address-of operator & to assign memory address of myInt to a pointer | |
pMark = &myInt; | |
// Dereference a pMark pointer with dereference operator * and set new value | |
*pMark = 11; | |
// show indirectly a value of pMark and directly the value of myInt | |
cout << "*pMark:\t" << *pMark << "\nmyInt:\t" << myInt << endl; | |
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 <iostream> | |
int main () | |
{ | |
int processId = 123456; | |
int* pid = NULL; | |
pid = &processId; | |
// Value | |
std::cout << processId << "\n"; | |
// Address | |
std::cout << pid << "\n"; | |
// Value | |
std::cout << *pid << "\n"; | |
// Address | |
std::cout << &pid << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment