[C++]명품 C++ 프로그래밍 실습문제 13장 8번
[C++]명품 C++ programming 실습문제 13장 8번
명품 C++ 프로그래밍실습문제/연습문제 /C++
#include <iostream>
#include <fstream>
using namespace std;
int *copy(int *src,int size){
int *p=NULL;
if(size<0){
throw -1;
return NULL;
}
else if(size > 100){
throw -2;
return NULL;
}
p = new int[size];
if(p==NULL){
throw -3;
return NULL;
}
else if(src ==NULL){
throw -4;
delete []p;
return NULL;
}
else{
for(int n=0; n<size ; n++)p[n] = src[n];
return p;
}
}
int main(){
int x[]={1,2,3};
try{
int *p=copy(x,3);
for(int i=0;i<3;i++){
cout <<p[i]<< ' ';
}
cout << endl;
delete []p;
}
catch(int x){
cout << "오류코드: " << x << endl;
}
return 0;
}
'C++' 카테고리의 다른 글
[C++] 명품 C++ 프로그래밍 실습문제 13장 오픈챌린지/openchallenge (3) | 2023.01.29 |
---|---|
[C++]명품 C++ 프로그래밍 실습문제 13장 10번 (0) | 2023.01.29 |
[C++]명품 C++ 프로그래밍 실습문제 13장 7번 (0) | 2023.01.29 |
[C++]명품 C++ 프로그래밍 실습문제 13장 6번 (0) | 2023.01.29 |
[C++]명품 C++ 프로그래밍 실습문제 13장 4번 (0) | 2023.01.29 |