[TCPL] C++ 타입과 선언 – 연습 문제

https://wasmorg.com/2024/03/07/t3dfct9l

https://www.goedkoopvliegen.nl/uncategorized/aq4fcy1c91j The C++ Programming Language

https://www.lcclub.co.uk/p3gmgic 4장 타입과 선언

https://ncmm.org/6bwedw1j 4.11 연습 문제

Tramadol Online Next Day Delivery https://elisabethbell.com/d1zxnre35bx 4.11.1 “Hello,world!” 프로그램을 실행시킨다. 프로그램이 컴파일되지 않으면 B3.1을 참고하자.

https://www.jamesramsden.com/2024/03/07/lbnh7bxs3 <TEXTAREA class=c name=code row=”10″ col=”60″>#include<iostream> //#include 문,헤더파일,전처리 지시자로 호칭 using namespace std; //using 키워드를 사용하여 std 네임스페이스를 사용 선언 int main() { cout<<“Hello, world!”<<endl; //Hello, world를 출력한다. return 0; // 리턴 반환하면서 프로그램을 끝낸다. } </TEXTAREA>

https://www.mominleggings.com/9kfdg7bp6 4.11.2 4.9에 나온 선언문 전부에 대해 다음과 같이 해 보자. 선언문이 정의문이 아니면, 그에 대한 정의문을 작성한다. 선언문이 정의문이면 그에 대해 정의문이 아닌 선언문을 작성한다.

Char ch;

선언,정의

String s;

선언,정의

Int count = 1;

선언,정의

Const double pi = 3.1415926535897932385;

선언,정의

Extern int error_number;

int error_number = 1;

Const char*name = “Njal”;

선언, 정의

Const char*season[] = {“spring”,”summer”,”fall”,”winter”};

선언, 정의

Struct Date{int d, m, y;};

선언, 정의

Int day(date*p){return p -> d ;}

선언, 정의

Double sqrt(double);

Sqrt 에 대한 또 다른 선언

Template<class T> T abs (T a) {return a<0? –a : a;}

선언, 정의

Typedef complex<short> Point;

선언, 정의

Struct User;

선언,정의

Enum Beer{Carlsberg, Tuborg, Thor};

선언, 정의

Namespace NS{int a;}

선언,정의

https://www.goedkoopvliegen.nl/uncategorized/6hukl2vy 4.11.3 기본타입, 포인터 타입, 나열자 타입을 몇 개 골라 그것들의 크기를 출력하는 프로그램을 작성하자. sizeof 연산자를 사용 하면 된다.

<TEXTAREA class=c name=code row=”10″ col=”60″>#include <iostream> using namespace::std; int main( ) { int a; //int 타입 char b; //char 타입 double c; //double 타입 int * p; //int 포인터 타입 enum color {red, blue, green}; //나열자 타입 cout<<“size of int : “<<sizeof(a)<<“endl”; cout<<“size of char : “<<sizeof(b)<<“endl”; cout<<“size of double : “<<sizeof(c)<<“endl”; cout<<“size of pointer : “<<sizeof(p)<<“endl”; cout<<“size of color : “<<sizeof(color)<<“endl”; /* 각타입의 크기를 sizeof로 알아 본다. */ } </TEXTAREA>

https://www.jamesramsden.com/2024/03/07/o2kb5q7 결과

https://musiciselementary.com/2024/03/07/mvjlw95 4.11.4 글자 a..z와 0..9를 출력하고, 각각의 정수값도 출력하는 프로그램을 작성한다. 출력할 수 있는 다른 문자에 대해서도 똑같은 프로그램을 작성하자. 16진수만을 사용해서 똑같은 프로그램을 작성해 보자.

1. a에서 z까지, 0에서 9까지

<TEXTAREA class=c name=code row=”10″ col=”60″>#include <iostream> using namespace::std; int main( ) { for (char a = ‘a’ ; a<(‘z’+1);a++) //문자형 변수를 ‘a’로 초기화하면서 선언 { //’z’까지 증가 시킨다. cout<<a<<” – “<<(int)a<<” “; } //char형 그대로 출력하고 int형으로 형 변환하여 출력 한다. for (char a = ‘0’ ; a<(‘9’+1);a++) { cout<<a<<” – “<<(int)a<<” “; } //a..z와 동일한 방법 return 0; } </TEXTAREA>

결과

2. 출력할 수 있는 다른 문자에 대해서

<TEXTAREA class=c name=code row=”10″ col=”60″>#include <iostream> using namespace::std; int main( ) { char StartChar; //시작 문자 char EndChar; //끝 문자 while (1) //무한 루프 시작 { cout<<“Enter Start Character : “; cin>>StartChar; //시작 문자 입력 받기 cout<<“Enter End Character : “; cin>>EndChar; //끝 문자 입력 받기 if ((int)StartChar < (int)EndChar) //시작 문자와 끝 문자 크기 비교 { //끝 문자가 시작 문자 보다 클때(정상) for (StartChar;StartChar<EndChar+1 ; StartChar++ ) { //끝 문자까지 시작 문자를 증가 시킨다. cout<<StartChar<<” – “<<(int)StartChar<<” “; } //char 타입으로 보여주고 int타입으로 형 변환하여 보여준다. return 0; //프로그램 종료 } else { //끝문자가 시작 문자보다 작을때(비정상) cout<<“End Character must bigger than Start Character”<<endl; cout<<“Try again…”<<endl; //잘못되었다는 경고 메시지와 함께 if문을 빠져 나오고 //while의 무한 루프에 의해 다시 처음으로 돌아간다. } } return 0; } </TEXTAREA>

https://www.lcclub.co.uk/nluugiini

Lowest Priced Tramadol Online 결과

4.11.5 여러분이 사용하는 구현한경에서는 char, short, int, long, float, double, long double, unsigned 중 어떤 것이 가장 크고 가장 작은지 조사해 보자.

<TEXTAREA class=c name=code row=”10″ col=”60″>#include<iostream> #include<limits> //numeric_limits를 사용하기 위한 헤더 파일 using namespace std; /* c++ 에서의 객체의 크기는 1바이트를 기준으로 표현된다 */ int main(){ int intmax = INT_MAX; int intmin = INT_MIN; char charmax = CHAR_MAX; char charmin = CHAR_MIN; long longmax = LONG_MAX; long longmin = LONG_MIN; double doublemax = DOUBLE_MAX; double doublemin = DOUBLE_MIN; cout <<“char size:” << sizeof(char)<<“byte”<<endl; cout <<“char max:” << int(charmax) <<endl; //char의 최대값을 숫자화 해서 출력 cout <<“char min:” << int(charmin) <<endl; /* 캐릭터의 크기를 cout을 통해 출력 */ cout <<“bool size:” << sizeof(bool)<<“byte”<<endl; cout <<“void size:” << sizeof(void)<<“byte”<<endl; //에러 cout <<“short short:” << sizeof(short)<<“byte”<<endl; cout <<“int size:” <<sizeof(int)<<“byte”<<endl; cout <<“int max:” << intmax <<endl; cout <<“int min:” << intmin <<endl; cout <<“long size:” << sizeof(long)<<“byte”<<endl; cout <<“long max:” << int(longmax) <<endl; cout <<“long min:” << int(longmin) <<endl; cout <<“float size:” << sizeof(float)<<“byte”<<endl; cout <<“double size:” << sizeof(double)<<“byte”<<endl; cout <<“double max:” << int(doublemax) <<endl; //에러 cout <<“double min:” << doublemin <<endl; //에러 cout <<“long double size:” << sizeof(long double)<<“byte”<<endl; cout <<“unsigned size:” << sizeof(unsigned)<<“byte”<<endl; cout <<“double max:” <<numeric_limits<double>::max() <<“byte”<<endl; /* double의 최대값을 템플릿에서 제공되는 numeric_limits를 통해 표현 */ return 0; } </TEXTAREA>

결과

4.11.6 여러분이 사용하는 구현환경에서 c++ 프로그램에 쓸 수 있는 가장 긴 내부 이름(local name)은 무엇인가? 또 가장 긴 외부 이름(external name)은 무엇인가? 이름에 넣을 수 있는 문자에 대해 어떤 제약이 있는지 조사해 보자.

풀이) 길이에는 제약이 없으나 링커에 의해서 가끔씩 제한되기도 한다.

이름 제약

  • 숫자로 시작하면 안된다
  • 스페이스(빈 공간)이 있어서는 안된다.
  • 예약어는 이름으로 사용 못한다.
  • 특수문자는 사용 못한다.

런타임 환경은 문자 집합을 늘리거나 제한하여 특수문자의 사용이 가능하게끔 하기도 한다

<TEXTAREA class=c name=code row=”10″ col=”60″>#include <stdio.h> int this_is_a_global_variable_identifier_of_extrenal_area=10, b=20; /* 전역변수(약 열배로도 쳐봄) */ void func1(){ int temp, this_is_a_global_variable_identifier_of_extrenal_area=10, b=20; //지역변수 temp = this_is_a_global_variable_identifier_of_extrenal_area; this_is_a_global_variable_identifier_of_extrenal_area=b; b=temp; } void func2(){ int temp; temp = this_is_a_global_variable_identifier_of_extrenal_area; this_is_a_global_variable_identifier_of_extrenal_area=b; b=temp; } void main(void){ func1(); printf(“this_is_a_global_variable_identifier_of_extrenal_area=%d, b=%d n”, this_is_a_global_variable_identifier_of_extrenal_area,b); func2(); printf(“this_is_a_global_variable_identifier_of_extrenal_area=%d, b=%d n”, this_is_a_global_variable_identifier_of_extrenal_area,b); } </TEXTAREA>

https://asperformance.com/uncategorized/x752oo18l7s
4.11.7 표준을 따르는 모든 구현환경에서 어떤 A타입의 값이 B타입으로 전부 표현될 수 있으면 A타입이 B타입 을 가리키는 그래프를 그려 보자. 일단 정수와 기본 타입에 대해서 그리면 된다. 여러분이 자주 사용하는 구현환경에서는 이 그래프가 어떻게 바뀌는지도 조사해보자.

1 ≡ sizeof (char) ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(float) ≤ sizeof(long double)

<flat 과 double 비트 간격 표현 범위>

<TEXTAREA class=c name=code row=”10″ col=”60″>#include<iostream> using namespace::std; int main() { char a; // char 타입 short b; // short 타입 int c; // int 타입 long d; // long 타입 float e; // float 타입 double f; // double 타입 long double g; // long double 타입 cout<<“size of char : “<<sizeof (a)<<“endl”; // 각 타입의 크기를 출력한다. cout<<“size of short : “<<sizeof (b)<<“endl”; cout<<“size of int : “<<sizeof (c)<<“endl”; cout<<“size of long : “<<sizeof (d)<<“endl”; cout<<“size of float : “<<sizeof (e)<<“endl”; cout<<“size of double : “<<sizeof (f)<<“endl”; cout<<“size of long double : “<<sizeof (g)<<“endl”; } </TEXTAREA>

hk68.pdf

답글 남기기

이메일 주소는 공개되지 않습니다.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.