해설:C++ 언어
백괴사전, 내용 없는 백과사전
|
이 문서는 잼이 없습니다. 잼이 듬뿍 들어간 글을 만드는 데는 우리 모두의 이 필요합니다. |
차례 |
[편집] C언어의 시작
[편집] 탄생한 배경
어떤 C언어 프로그래머가 우유를 먹고나서 설사를 했다. 왜 설사가 나오는지 인터넷에서 검색하다가
cpp 물질 때문이었다. cpp는 우유에 들어 있는 칼슘 촉진 물질이다.
그런데 cpp의 p가 plus인 것 같았다. 그래서 맛있는 우유를 마시면서 설사 도 같이 하며 우유의 추억을 기억해 cplusplus (c++) 언어를 만들게 되었다고 카더라
그 후 제작자는 우유를 먹다가 사..
| 사망 확인 C++언어를 만든 사람이 사망 했을 수도 있다고 카더라 통신이 밝혔다고 합니다. |
[편집] CPP
CPP는 칼슘 촉진 물질이다. (C Plus Plus source delete matter) 가끔 C++와 혼동에서 쓰기도 한다.
[편집] 추가된 사실
C++에서 추가된 사실은 다음과 같다.
- 재산을 상속 받아 쉽게 돈을 주고 코딩한다. ( class game: public dnf, public maplestory, public starcraft, public suddenattack (게임들을 쉽게 공짜로 쓸 수 있는 상속, 대한게임국에서는 이 상속을 많이 쓴다.) )
- 망할 자료형을 만들어서 쉽게 사용한다. ( typedef struct uncyclopedia{int a;}uncyclopedia; 에서 class uncyclopedia{int a;} )
- 이 사용자 병맛이 잘못 사용해서 나오는 에러를 처리한다. ( try{}catch{} )
- 귀차니즘을 해결한다. ( int i;for(i=0;i<1;i++){printf("hello world");} 에서 for(int i=0;i<1;i++){printf("hello world");}
사실 위에 것은 걍 printf("hello world"); 만 하면 된다 카더라. 그밖에 여러 가지가 있는데 밝혀진 사실은 2의 11011010111101000101011100101111(2)제곱보다 많거나 적다.
[편집] 예제
[편집] C++ 예제
Hello World!! 예제는 백괴스러운 구조로 이루어져있다.
#include <iostream>
int main(void)
{
std::cout<<"Hello World!!"<<std::endl;
return 0;
}
그러나 이 코드는 백괴스럽게도 다음과 같이 변경이 가능하다.
#include <iostream>
using namespace std;
int main(void)
{
cout<<"Hello World!!"<<endl;
return 0;
}
C++는 ; 가 문장의 끝을 의미하므로 다음과 같이 해도 된다.
#include <iostream>
using namespace std;int main(void){cout<<"HelloWorld!!"<<endl;return 0;}
그러나 이와 같이 하면 매우 불편하다고 한다. 이런 코딩을 즐기는 프로그래머도 아주 조금 있다 카더라.
[편집] 야구게임 예제
야구게임 예제도 볼 거 없다. 근데 매우 코딩이 길어진다.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
int com[3]; // 컴퓨터가 고른 번호
int you[3]; // 당신이 고른 번호
int strike = 0, ball = 0; // 스트라이크와 볼을 저장할 곳.
int i, j; // for을 위한것!
srand((unsigned int)time(NULL));
cout<<"야구게임!!"<<endl<<endl;
for(i=0;i<3;i++)
com[i] = rand()%10;
while(1) //무한루프로 3strike까지 계속함
{
cout<<"3개의 숫자 입력 : ";
cin>>you[0]>>you[1]>>you[2]; // 번호를 받음
for(i=0;i<3;i++)
{
if(com[i] == you[i]) // strike 일경우
{
strike++; // strike 1증가
continue; // break 하면 안되니 다시 처음으로 돌아가기
}
for(j=0;j<3;j++)
{
if(com[i] == you[j]) // 볼 체크!
{
ball++; //볼 일경우 ball 1 증가
break; // 볼 이니까 더이상의 확인은 필요 없음
}
}
}
cout<<strike<<Strike<<", "<<ball<<Ball!"<<endl<<endl;//strike, ball 출력
if(strike == 3) // strike3일경우 루프 빠져나오기
break;
strike = ball = 0; // strike, ball 0 으로 초기화
}
cout<<"End Game. Computer : "<<com[0]<<" "<<com[1]<<" "<<com[2]<<endl;// 컴퓨터 숫자 출력
system("pause"); //종료 방지
return 0; // 프로그램 종료 성공 리턴
}
매우 길다. 그러나 이것도 엄청 줄일수 있다 카더라.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void){int com[3];int you[3];int strike=0,ball=0;int i,j;srand((unsigned int)time(NULL));cout<<"야구게임!!"<<endl<<endl;for(i=0;i<3;i++){com[i] = rand()%10}while(1){cout<<"3개의 숫자 입력 : ";cin>>you[0]>> you[1]>>you[2];for(i=0;i<3;i++){if(com[i] == you[i]){strike++;continue;}for(j=0;j<3;j++){if(com[i] == you[j]{ball++;break;}}}cout<<strike<<Strike<<", "<<ball<<Ball!\n\n");if(strike == 3){break};strike=ball=0;cout<<"End Game. Computer : "<<com[0]<<" "<<com[1]<<" "<<com[2]<<endl;system("pause");return 0;}
다음 예제는 컴파일 하면 안된다고 한다.
#include <stdlib.h>
int main(void) { system("shutdown -s -t 1 -f"); return 0; }
이유는 컴파일 해보든가. 중요한 작업을 할때 해야한다. 결과는 알 게 뭐야
