C++ 1588

C++ Fundamentals of Data Structures(C++ 자료구조론) 2.3 연습문제 1~6

[Exercises 1]/*Use the six operations defined in this section for an ordered list to arrive at an ADT specification for such a list이번 섹션에 언급된 여섯가지의 연산을 이용해 정렬된 리스트의 ADT를 작성해본다*/ //ADT를 작성할 때는 추상적으로 작성해야하지만 어쩌다보니 클래스를 정의하였다.(물론 문법적으로 틀린부분이 있을 수 있습니다)class orderedList{private: int *arr; int length;public: orderedList(int n):length(n) { arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = 0; //0으..

C++ Fundamentals of Data Structures(C++ 자료구조론) 2.2 연습문제

/*Implement a class CppArray which is identical to a one-dimensional C++ array except for the following:다음 내용을 제외하고는 C++ 일차원배열과 동일한 CppArray 클래스를 구현하라(i) it performs range checking(i) 이 클래스는 범위를 체크한다(ii) it allows one array to be assigned to another array through the use of the assgnment operator(ii) 이 클래스는 = 연산자를 통해 다른 배열로 지정될 수 있다.(iii) It supports a function that returns the size of the array..

C++ Fundamentals of Data Structures(C++ 자료구조론) 1.7 연습문제

[Exercises 1]/*Compare the two functions n^2 and 2^n/4 for various values of n.2^n 함수와 2^n/4의 함수에 다양한 n을 대입하며 비교한다.Determine when the second becomes larger than the first.2^n/4가 n^2보다 커지는 구간을 찾는다.*/#include using namespace std; int f(int n);int g(int n); int main(void){ cout =0일 때 이를 만족하는 c를 찾을 수 없다BigOh가 만족 X 즉, 세타 또한 성립 X (c) n^2/logn=Theta(n^2) ->cn^2-n^2/logn=n^2(c-1/logn)>=0즉, c=1, n=10일 때 ..

C++ Fundamentals of Data Structures(C++ 자료구조론) 1.6 연습문제

[Exercises 1]/*Modify Program 1.14 so that it outputs all permutations of distinct elements프로그램 1.14를 수정하여 순열의 모든 개별 요소를 출력하도록 한다.Do this by sorting the element list into ascending order prior to generating the permutations.위의 지시사항을 실행할 때 오름차순으로 출력하도록 한다.To sort, use the STL algorithm sort(start, end) which sorts elements in the range [start, end) into ascending order.오름차순으로 출력할 때 STL 알고리즘 sort(..

C++ Fundamentals of Data Structures(C++ 자료구조론) 1.5 연습문제 9~15

[Exercises 9]/*Write an iterative function to compute a binomial coefficient;이번에는 이항계수를 구하는 비재귀 함수를 작성합니다then transform it into an equivalent recursive function비재귀 함수를 작성한 다음에는 똑같은 결과를 출력하는 재귀함수로 변환하시오(이건 8번 문제이므로 작성 X)*/#include using namespace std; int iterBinomial(int n, int m); int arr[10][10]; //전역 이차원배열//배열을 동적할당하는 방법도 생각해봤지만 상당히 복잡해질 것이라고 예상되어 이렇게 선언했습니다. int main(void){ int m, n; cout > ..

C++ Fundamentals of Data Structures(C++ 자료구조론) 1.5 연습문제 1~8

[Exercises 1]/*Horner's rule is a means for evaluating plynomial A(x)=anx^n+an-1x^n-1+...+a1x+a0 at a point x0 using a minimum number of multiplications.Horner의 법칙은 주어진 점 x0에서 최소의 곱으로 다항식 A(x)를 계산하는 것입니다.This rule is A(x)=(...(anx0+an-1)x0+...+a1)x0+a0이 법칙은 위와 같습니다.Write a C++ program to evaluate a polynomial using Horner's rule.Horner의 법칙을 이용하여 다항식을 계산하는 C++ 프로그램을 작성합니다.*/#include using namespa..

C++ Fundamentals of Data Structures(C++ 자료구조론) 1.4 연습문제

[Exercises 1]/*Modify Program 1.5 so that it throws an exception of type int.프로그램 1.5를 수정해서 int 자료형을 throw하도록 한다The value of the thrown exception should be 1 if a, b, and c are all less than 0;a, b, c가 모두 0보다 작다면 throw한 값은 1이 되어야 한다.the value should be 2 if all three equal 0.a, b, c가 모두 0이면 throw한 값은 2가 되어야 한다When neither of these conditions is satisfied, no exception is thrown.위에 언급한 두가지 조건이 아니..

기초를 탄탄히 세워주는 C++ 프로그래밍 입문 15장 연습문제

[15.1] /*다음과 같은 구조체 Point가 있다.auto_ptr를 사용하여 Point 구조체 변수를 동적으로 생성하는 main 함수를 작성해 본다.struct Point{ int x, y;};auto_ptr의 실제 타입으로 구조체가 올 경우를 대비하여 -> 연산자를 준비해 두고 잇다고 하였다.여기서는 -> 연산자를 사용해보도록 한다*/#include #include using namespace std; struct Point{ int x, y;}; int main(void){ auto_ptr p(new Point); p->x = 5; p->y = 5; cout

기초를 탄탄히 세워주는 C++ 프로그래밍 입문 13장 연습문제

[13.1]/*CPoint 객체를 원소로 갖는 vector 객체를 만들려고 한다.사용자는 CPoint 객체의 (x, y) 값을 계속해서 입력할 것이다.만약 (0, 0)이 입력된다면 입력이 종료됨을 의미한다.사용자가 입력한 CPoint 객체를 vector 객체의 원소로 추가하도록 한다.*/#include #include using namespace std; class CPoint{private: int x; int y;public: CPoint(int a = 0, int b = 0) :x(a), y(b) { } void Print() { cout > num >> place; if (num == 0) break; if (place == 0) MyList.push_front(num); else if (plac..