C++/Fundamentals of Data Structures in C++(Horowitz) 47

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.위에 언급한 두가지 조건이 아니..