[[연습1]]
#include <iostream>
using namespace std;
void plunsTen(int *a, double *d);
void plusTen(int &a, double &d);
int main()
{
int a;
double d;
cout << "정수 입력 : ";
cin >> a;
cout << "실수 입력 : ";
cin >> d;
plunsTen(&a, &d);
cout << "\n변환결과 : " << a << ", " << d << endl;
plusTen(a, d);
cout << "\n변환결과 : " << a << ", " << d << endl;
return 0;
}
void plunsTen(int *a, double *d)
{
cout << "pointer!!!\n";
*a += 10;
*d += 10;
}
void plusTen(int &a, double &d)
{
cout << "\nrefference!!!\n";
a += 10;
d += 10;
}
[[연습2]]
#include <iostream>
using namespace std;
void swap(int &a, int &b);
void swap(char *c1, char *c2);
int main()
{
int a, b;
cout << "\n정수 두개 입력 : ";
cin >> a >> b;
swap(a, b);
cout << "교환 결과 : " << a << ", " << b << endl;
char c1, c2;
cout << "\n문자 두개 입력 : ";
cin >> c1 >> c2;
swap(&c1, &c2);
cout << "교환 결과 : " << c1 << ", " << c2 << endl;
return 0;
}
void swap(int &a, int &b)
{
cout << "Refference Swap\n";
int temp;
temp = a;
a = b;
b = temp;
}
void swap(char *c1, char *c2)
{
char temp;
cout << "Pointer Swap\n";
temp = *c1;
*c1 = *c2;
*c2 = temp;
}
[[연습3]]
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
struct Student
{
int no;
char name[10];
char phone[20];
};
void menu();
void input(Student &Rst);
void output(Student &Rst);
int main()
{
menu();
return 0;
}
void menu()
{
Student st;
while(1)
{
system("cls");
cout << "1. Call Input\n";
cout << "2. Call Output\n";
cout << "3. Call exit\n";
int sel;
cout << "Select menu : ";
cin >> sel;
switch(sel)
{
case 1:
input(st);
break;
case 2:
output(st);
break;
case 3:
cout << "\n\t\tExit Program\n\n";
exit(0);
}
cout << "Press any key if U continue\n\n";
getch();
}
}
void input(Student &Rst)
{
system("cls");
cout << "번호 : ";
cin >> Rst.no;
cout << "이름 : ";
cin >> Rst.name;
cout << "전화번호 : ";
cin >> Rst.phone;
}
void output(Student &Rst)
{
cout << "\n\nRefference Output\n\n";
cout << "\t번 호 : " << Rst.no << endl;
cout << "\t이 름 : " << Rst.name << endl;
cout << "\t전화번호 : " << Rst.phone << endl << endl;
}