C++(56)
-
학번, 중간성적, 기말성적 입력 프로그램
#include using namespace std; #define ARRAY_SIZE 100 int main(void) { int studentID, middleScore, finalScore; int *array[ARRAY_SIZE]; int index= 0; while(true) { array[index] = new int[3]; coutmiddleScore>>finalScore; array[index][0] = studentID; array[index][1] = middleScore; array[index][2] = finalScore; index++; } cout
2022.04.14 -
배열(array)
배열(array) 배열은 거의 모든 프로그래밍 언어에서 기본적으로 제공되는 자료형이다. 배열은 동일한 타입의 데이터를 한 번에 여러 개를 만들 때 사용된다. 예를 들어 6개의 정수를 저장할 공간이 필요한 경우 다음과 같이 6개의 정수형 변수를 선언하여야한다. . int list1, list2, list3, list4, list5, list6; 그러나 배열을 통하여 다음과 같이 선언할 수 있다. int list[6]; 6개의 정수를 저장할 공간을 만든 것이다. 배열의 인덱스 배열을 사용하면 "연속적인 메모리 공간"이 할당되고 인덱스(index) 번호를 사용하여 쉽게 접근이 가능하다. C++에서의 1차원 배열 배열은 변수 이름 끝에 [ ]을 추가하여 선언한다. [ ]안의 숫자는 배열의 크기이다. int li..
2022.04.11 -
mutable
const 함수 내에서의 값의 변경을 예외적으로 허용한다. #include using namespace std; class SoSimple { private: int num1; mutable int num2; //const 함수에 대해 예외를 둔다.! public: SoSimple(int n1, int n2) :num1(n1),num2(n2) { } void ShowSimpleData() const{ cout
2022.04.10 -
static
c에서의 static 전역변수에 선언된 static 선언된 파일 내에서만 참조를 허용 함수 내에 선언된 static 한번만 초기화 되고, 지역변수와 달리 함수를 빠져나가도 소멸되지 않는다. #include using namespace std; void Counter() { static int cnt; cnt++; cout
2022.04.10 -
friend
private 로 선언된 멤버변수와 멤버함수는 클래스 내에서만 접근가능하다. class Boy { private: int height; friend class Girl; //Girl 클래스를 friend로 선언함 public: Boy(int len) : height(len) {} }; class Girl { private: char phNum[20];//전화번호 public: Girl(char* num) { strcpy(phNum, num); } void ShowYoutFriendInfo(Boy &frn) { cout
2022.04.10 -
연산자 오버로딩
#include using namespace std; class Vector2{ public: Vector2(); Vector2(float x, float y); float GetX() const; float GetY() const; private: float x; float y; }; int main(){ } Vector2::Vector2() :x(0), y(0){ } Vector2::Vector2(float x, float y): x(x), y(y) { } float Vector2::GetX() const {return x;} float Vector2::GetY() const {return y;} 위와 같은 코드가 있을때 아래의 코드는 오류를 발생한다. int main(void) { Vector2 a..
2022.04.10