|
안녕하세요 이해가 잘안가서 질문을하게되었습니다.
클래스에 있는 swap함수에 Company &x가 멀가르키는지를 모르겠습니다.
죄송합니다. 설명을 부탁합니다.
그럼 즐거운 하루되세요
#include <stdio.h>
#include <string.h>
class Company {
char name[20];
int sales;
int profit;
public:
Company (char *p =" ", int x=0,int y=0)
{
strcpy (name,p);
sales =x;
profit =y;
}
void swap (Company &x)
{
char n[20];
int s,p;
strcpy(n, x.name);
s=x.sales ;
p=x.profit ;
strcpy(x.name,name);
x.sales =sales;
x.profit = profit;
strcpy(name,n);
sales =s;
profit =p;
}
void print()
{
printf("회사명 %s \n", name);
printf("매상 %d 억원 \n",sales);
printf("이익 %d억원 \n",profit);
}
};
void main()
{
Company a("사이버 (주)", 500,39);
Company b("푸른솔 (주)",825,78);
a.swap (b);
a.print ();
b.print ();
}
|