Created
November 4, 2014 02:09
-
-
Save wkentaro/f1fc0fa901f9c52c1fcb to your computer and use it in GitHub Desktop.
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() | |
{ | |
std::cout << "Hello, World!"; | |
} |
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() | |
{ | |
std::cout << "Hello, World! "; | |
std::cout << "I'm a C++ program"; | |
} |
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 <stdio.h> | |
int main() | |
{ | |
float ax,ay,az , bx,by,bz , cx,cy,cz; | |
ax = 2; | |
ay = 1; | |
az = -2; | |
bx = 1; | |
by = 1; | |
bz = 1; | |
cx = ax + bx; | |
cy = ay + by; | |
cz = az + bz; | |
printf("C = %f %f %f\n" , cx , cy , cz); | |
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 <stdio.h> | |
class C3DVec { | |
private: | |
public: | |
float x, y, z; | |
}; | |
int main() | |
{ | |
C3DVec vA, vB, vC; | |
vA.x = 2; | |
vA.y = 1; | |
vA.z = -2; | |
vB.x = 1; | |
vB.y = 1; | |
vB.z = 1; | |
vC.z = vA.x + vB.x; | |
vC.y = vA.y + vB.y; | |
vC.z = vA.z + vB.z; | |
printf("C = %f %f %f\n" , vC.x , vC.y , vC.z); | |
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 <stdio.h> | |
//関数vAdd , vSetもクラスに含めます。アクセスは当然publicで | |
class C3DVec{ | |
private: | |
public: | |
float x , y , z; | |
C3DVec operator+(C3DVec v2) | |
{ | |
C3DVec vRet; | |
//v1は自分の値を使えばよいので、引数はv2だけでよくなる。 | |
vRet.x = x + v2.x; | |
vRet.y = y + v2.y; | |
vRet.z = z + v2.z; | |
return vRet; | |
} | |
void vSet(double ix , double iy , double iz) | |
{ | |
//メンバ変数の名前とダブらないように引数をix,iy,izとする。 | |
//自分のメンバ変数の値をセットすればよいので戻り値は必要ない | |
x = ix; | |
y = iy; | |
z = iz; | |
} | |
}; | |
int main() | |
{ | |
C3DVec vA , vB , vC; | |
vA.vSet(2 , 1 , -2); | |
vB.vSet(1 , 1 , 1 ); | |
// vC = vA.operator+(vB); | |
vC = vA + vB; | |
printf("C = %f %f %f\n" , vC.x , vC.y , vC.z); | |
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 <vector> | |
#include <iostream> | |
int main() | |
{ | |
std::vector<int> array; | |
for (int i=0; i<10; i++) { | |
array.push_back(i); | |
} | |
for (int i=0; i<10; i++) { | |
std::cout << array[i] << std::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
// operating with variables | |
#include <iostream> | |
using namespace std; | |
int main () | |
{ | |
// declaring variables: | |
int a, b; | |
int result; | |
// process: | |
a = 5; | |
b = 2; | |
a = a + 1; | |
result = a - b; | |
// print out the result: | |
cout << result; | |
// terminate the program: | |
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
// initialization of variables | |
#include <iostream> | |
using namespace std; | |
int main () | |
{ | |
int a=5; // initial value: 5 | |
int b(3); // initial value: 3 | |
int c(2); // initial value: 2 | |
int result; // initial value undetermined | |
a = a + b; | |
result = a - c; | |
cout << result; | |
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> | |
#include <string> | |
int main() | |
{ | |
// std::string mystring; | |
// mystring = "This is a sting"; | |
std::string mystring ("This is a string"); | |
std::cout << mystring; | |
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> | |
const double pi = 3.14159; | |
const char newline = '\n'; | |
int main() | |
{ | |
double r = 5; | |
double circle; | |
circle = 2 * pi * r; | |
std::cout << circle; | |
std::cout << newline; | |
} |
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> | |
#define PI 3.14159 | |
#define NEWLINE '\n' | |
int main() | |
{ | |
double r = 5; // radius | |
double circle; | |
circle = 2 * PI * r; | |
std::cout << circle; | |
std::cout << NEWLINE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment