CH03_ PROGRAMMING
본 자료는 6페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
해당 자료는 6페이지 까지만 미리보기를 제공합니다.
6페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

CH03_ PROGRAMMING에 대한 보고서 자료입니다.

본문내용

= {1,2,3,4,5}, B[] = {6,7,8,9,10}, n = 0;
cout<<"A[] = {1,2,3,4,5}"< cout<<"B[] = {6,7,8,9,10}"< cout< copy(A,B,5);
return 0;
}
void copy(int *A, int *B, int n)
{
int *C = NULL, i;
C = B;
B = A;
A = C;
cout<<"A[] = {";
for(i = 0;i < n; i++){
if(i == n-1)
cout< else
cout< }
cout<<"}"< cout<<"B[] = {";
for(i = 0;i < n; i++){
if(i == n-1)
cout< else
cout< }
cout<<"}"< }
10. 배열 A[]에서 주어진 숫자를 탐색하여 숫자를 가리키는 포인터를 반환하는 다음과 같은 원형을 가지는 함수를 작성하고 테스트하라.
#include
#define MAX_SIZE 10
using namespace std;
void print(int *A, int size);
int *search(int *A, int n);
int main ()
{
int a[MAX_SIZE] = {1,2,3,4,5,6,7,8,9,10}, n =0, *ps = NULL;
print(a,MAX_SIZE);
cout<<"탐색할 수를 입력하시오 : ";
cin>>n;
ps = search(a,n);
if(*ps == -1){
cout<<"못찾았습니다."< }
else{
cout<<"찾았습니다 : "<<*ps< }
return 0;
}
int *search(int *A, int n)
{
int x = -1;
for(int i = 0;i < MAX_SIZE;i++){
if(*A+i == n){
return A+i;
}
}
return &x;
}
void print(int *A,int size)
{
cout<<"A[] = { ";
for(int i = 0;i < size;i++){
cout< }
cout<<"}"< }
11. 실수값들이 저장되어 있는 double형 배열 A{]에서 평균값, 최대값, 전체의 합을 계산하여 포인터 인수를 통하여 반환하는 함수 get_stat(double A[], double *p_avg, double *p_max, double *p_sum)을 구현하라.
#include
#define MAX_SIZE 10
using namespace std;
void get_stat(double A[], double *p_avg, double *p_sum, double *p_max);
int main ()
{
double a[MAX_SIZE] = {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.3}, sum = 0, avg = 0, max = 0;
double *p_sum = ∑
double *p_avg = &avg;
double *p_max = &max;
cout<<"A[] = { ";
for(int i = 0;i < MAX_SIZE;i++){
cout< }
cout<<"}"< get_stat(a,p_avg,p_sum,p_max);
cout<<"총합 : "< cout<<"총 평균 : "< cout<<"최대값 : "< return 0;
}
void get_stat(double A[], double *p_avg, double *p_sum, double *p_max)
{
for(int i = 0;i < MAX_SIZE;i++){
*p_sum += A[i];
if(*p_max < A[i]){
*p_max = A[i];
}
}
*p_avg = (*p_sum) / MAX_SIZE;
}
12. 간단한 철자 교정 프로그램을 작성하여 보자.
#include
#define SIZE 100
using namespace std;
void ChangeText(char *str, int size);
int main()
{
char input[SIZE];
cin.getline(input, SIZE);
cout<<" 입력문 : "< ChangeText(input, SIZE);
cout<<" 변경문 : "< }
void ChangeText(char *str, int size)
{
int i;
if(str[0] >= 'a' && str[0] <= 'z')
str[0] = str[0] - 32;
for(i=0; i if(str[i] == NULL){
if(str[i-1] != '.'){
str[i] = '.';
str[i+1] = NULL;
}
break;
}
}
}
13. 간단한 “찾아 바꾸기” 기능을 구현하여 보자.
#include
#define SIZE 81
using namespace std;
int main()
{
char str[SIZE], tmp[SIZE];
char findStr[SIZE], replaceStr[SIZE];
char* pStr;
cout<<"문자열을 입력하시오: ";
cin.getline(str, 81);
cout<<"찾을 문자열: ";
cin.getline(findStr,81);
cout<<"바꿀 문자열: ";
cin.getline(replaceStr,81);
pStr = strstr(str, findStr);
if(findStr == NULL)
cout<<"입력하신 문자열을 찾을 수 없습니다."< strncpy(tmp, str, (pStr-str));
tmp[pStr-str] = NULL;
strcat(tmp, replaceStr);
strcat(tmp, pStr+strlen(findStr));
strcpy(str, tmp);
cout<<"결과: "< return 0;
}

키워드

  • 가격2,300
  • 페이지수19페이지
  • 등록일2014.11.04
  • 저작시기2012.4
  • 파일형식한글(hwp)
  • 자료번호#945473
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니