Chapter 0 시작전 몸풀기 연습문제
0-1 다음 문장의 의미는 무엇인가요?
3+4; 7이라는 결과를 나타내는 부수효과가 없는 표현식
0-2 실행하면 다음과 같은 출력을 하는 프로그램을 작성해보세요.
This (") is a quote, and this (\) is a backslash.
// chapter0-2.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<< "This (\") is a quote, and this (\\) is a backslash." << endl;
return 0;
}
0-3 문자열 리터럴 "\t"는 탭문자를 나타내는데, c++ 구현시스템마다 다른 방식으로 탭을 표현합니다. 여러분의 구현시스템이 어떻게 탭을 표시하는지 시험해 보세요.
// 한문자의 차이를 표시한다.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "테스트\t입니다."<<endl;
return 0;
}
0-4 실행하면 그 출력으로 Hello, world ! 프로그램 소스 코드를 출력하는 프로그램을 작성해보세요.
// chapter0-4.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char OutPutData[256];
fstream inoutfile("chapter0-4.cpp",ios::in|ios::out);
if(inoutfile.fail())
{
cout << "파일 열기 실패" << endl;
exit(1);
}
while(!inoutfile.eof())
{
inoutfile.getline(OutPutData,sizeof(OutPutData));
cout << OutPutData << endl;
}
inoutfile.close();
return 0;
}
0-5. 이 프로그램이 올바른가요? 왜 그런가요? 혹은, 왜 그렇지 않은가요?
#include <iostream>
int main() std::cout << "Hello, world!" << std::endl;
-> 에러 ! main ()에 블록이 없다.
0-6. 이 프로그램이 올바른가요? 왜 그런가요? 혹은, 왜 그렇지 않은가요?
#include <iostream>
int main() {{{{{{ std::cout << "Hello, world!" << std::endl; }}}}}}
-> 이상없다.
0-7. 이 프로그램은 어떤가요?
#include<iostream>
int main()
{
/* 이것은 여러 라인에 걸친 주석입니다.
왜냐하면, /*과 */를 시작 및 종료 표시로 사용하기 때문입니다.
*/
std::cout <<"does this work?" <<std::endl;
return 0;
}
-> 에러! 주석중간에 */가 있어서 거기서 주석이 끝나버린다.
0-8. 그렇다면 이 프로그램은 어떤가요?
#include <iostream>
int main()
{
// 이것은 /*나 */를 사용하는 대신
// 각 라인의 시작부분에 //를 사용하여
// 여러 라인에 걸치게 한 주석입니다.
std::cout <<"does this work?" <<std::endl;
return 0;
}
-> 이상없다!
0-9 온전한 프로그램으로서 가장 짧은 프로그램을 작성해보세요.
-> return 0; 생략
int main(){}
0-10. 공백문자가 들어갈수있는 모든 부분에 개행문자를 넣어 Hello, world!를 다시 작성해 보세요.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello\nWorld!\n" <<endl;
return 0;
}