본문내용
----------------------"<
}
};
int main()
{
Stack s;
try{
s.push(3);
s.display();
s.push(4);
s.display();
s.pop();
s.display();
s.pop();
s.display();
s.pop();
//s.display();
}
catch(char *e)
{
cout<
}
return 0;
}
4. 성적을 처리하는 클래스 ProcessScore를 작성하라.
#include
using namespace std;
class ProcessScore{
double average;
public:
ProcessScore(int *p, int index)
{
int tmp=0;
for(int i=0; i< index; i++)
{
if((*p) < 0) throw "IllegalScoreException";
tmp+= *p;
p++;
}
average = tmp / 5.0;
}
void display()
{
cout<<"평균 점수는 : "<
}
};
int main()
{
int score[5]={10,20,-30,40,50};
try{
ProcessScore p(score, 5);
p.display();
}
catch(char *e)
{
cout<
}
return 0;
}
5. 숫자를 저장하고 있는 배열을 받아서 지정된 숫자를 찾는 SearchArray를 작성하라.
#include
using namespace std;
class NotFound
{
public:
void display(){cout<<"NotFound"<
};
class SearchArray
{
int index;
int *ptr;
public:
SearchArray(int *p, int i)
{
ptr = p;
index = i;
}
void searchNum(int num)
{
int *tmp = ptr;
for(int i=0; i< index ; i++){
if(*tmp == num)
{
cout<
break;
}
tmp++;
}
if(i == index) throw NotFound();
}
void display()
{
int *p = ptr;
cout<<"배열에 저장된 값은... " <
for(int i=0; i< index ; i++)
{
cout<<"["<<*p<<"] ";
p++;
}
cout<
}
};
int main()
{
int input=0;
int s[10]={11,22,33,44,55,66,77,88,99,111};
SearchArray sa(s, 10);
try{
sa.display();
cout<<"찾을 값을 입력하세요 : ";
cin>>input;
sa.searchNum(input);
}
catch (NotFound& e)
{
e.display();
}
return 0;
}
};
int main()
{
Stack s;
try{
s.push(3);
s.display();
s.push(4);
s.display();
s.pop();
s.display();
s.pop();
s.display();
s.pop();
//s.display();
}
catch(char *e)
{
cout<
return 0;
}
4. 성적을 처리하는 클래스 ProcessScore를 작성하라.
#include
using namespace std;
class ProcessScore{
double average;
public:
ProcessScore(int *p, int index)
{
int tmp=0;
for(int i=0; i< index; i++)
{
if((*p) < 0) throw "IllegalScoreException";
tmp+= *p;
p++;
}
average = tmp / 5.0;
}
void display()
{
cout<<"평균 점수는 : "<
};
int main()
{
int score[5]={10,20,-30,40,50};
try{
ProcessScore p(score, 5);
p.display();
}
catch(char *e)
{
cout<
return 0;
}
5. 숫자를 저장하고 있는 배열을 받아서 지정된 숫자를 찾는 SearchArray를 작성하라.
#include
using namespace std;
class NotFound
{
public:
void display(){cout<<"NotFound"<
class SearchArray
{
int index;
int *ptr;
public:
SearchArray(int *p, int i)
{
ptr = p;
index = i;
}
void searchNum(int num)
{
int *tmp = ptr;
for(int i=0; i< index ; i++){
if(*tmp == num)
{
cout<
}
tmp++;
}
if(i == index) throw NotFound();
}
void display()
{
int *p = ptr;
cout<<"배열에 저장된 값은... " <
{
cout<<"["<<*p<<"] ";
p++;
}
cout<
};
int main()
{
int input=0;
int s[10]={11,22,33,44,55,66,77,88,99,111};
SearchArray sa(s, 10);
try{
sa.display();
cout<<"찾을 값을 입력하세요 : ";
cin>>input;
sa.searchNum(input);
}
catch (NotFound& e)
{
e.display();
}
return 0;
}
소개글