글 작성자: 마노링
반응형

#include <iostream.h>
#include <string.h>

/*class start {
private :  // 전용맴버
 int nai;
 double ki;
public :  // 공용맴버
 void set();
 void print();
};
void start::set(int a, doubel b=9.19) {
 nai=a;
 ki=b;
}
void start::print() {
 set();
 cout << "nai=" << nai << endl;
 cout << "ki=" << ki << endl;
}
void func(start data) {
 data.print();
 return data;
}

void main() {
 start x, y;
 // private access defined
 //x.ki=3.14; cout << "x.ki=" << x.ki << endl;
 //x.nai=10; cout << "x.nai=" << x.nai << endl;
 //x.set();
 x.set(10, 3.14);
 y.set(20, 7.14);
 x.print();
 y.print();
 x.set(30);
 func(x);
}*/
/*
class Counter {
 int value;
public:
 void set(int n) {value = n; }
 void inc() {++value;}
 void dec() {--value;}
 int val() {return value;}
};

int main() {
 Counter cnt1, cnt2;
 cnt1.set(10);
 cnt1.inc();
 cout << "cnt1 Value : " << cnt1.val() << endl;

 cnt2.set(0);
 cnt2.dec();
 cout << "cnt2 Value : " << cnt2.val() << endl;

 return 0;
}*/
/*
class Circle {
 double Radius;
public :
 double Circle_Area();
};

double Circle::Circle_Area() {
 Radius = 5.0;
 return(3.14*5.0*5.0);
}

int main() {
 Circle Cirl;
 cout << "원의 면적은 " << Cirl.Circle_Area() << "입니다" << endl; 
 return 0;
}*/
/*
class Date {
 int year, month, day;
public:
 void set_date(int y, int m, int d);
 int get_year() { return year; }
 int get_month() { return month; }
 int get_day() { return day; }
};

void Date::set_date(int m, int d, int y = 2008) {
 year = y;
 month = m;
 day = d;
}

int main() {
 Date dt;
 dt.set_date(3, 25);
 cout << dt.get_year() << "." << dt.get_month() << "." << dt.get_day() << endl;
 dt.set_date(1, 1, 2000);
 cout << dt.get_year() << "." << dt.get_month() << "." << dt.get_day() << endl;
 return 0;
}
*/
/*void func(int a, int b, int c=50) {
 cout << a << b << c << endl;
}

void main() {
 func(10, 20);
 func(10, 20, 30);
}*/
/*
class String {
 char *str;
 int len;

public:
 void set(char *cp);
 void prn();
};

void String::set(char *cp) {
 len = strlen(cp);
 str = new char[len+1];
 strcpy(str, cp);
}

void String::prn() {
 cout << "문자열 : " << str << "(" << len << ")" << endl;
}

int main() {
 String str1, str2;
 str1.set("The first string");
 str2.set("This is the second string");
 str1.prn();
 str2.prn();
 cout << "\n===================================\n";
 str1 = str2;
 str1.prn();
 str2.prn();
 return 0;
}*/
/*
class XY {
 int x, y;
public:
 void set_xy(int a, int b) { x = a, y = b; }
 int get_x() { return x; }
 int get_y() { return y; }
};

void swap(XY ob) {
 ob.set_xy(ob.get_y(), ob.get_x());
 cout << "== swap() ==\n";
 cout << "x = " << ob.get_x() << ", y = " << ob.get_y() << endl;
}

int main() {
 XY ob;
 ob.set_xy(10, 20);
 swap(ob);
 cout << "\n== Main() ==\n";
 cout << "x = " << ob.get_x() << ", y = " << ob.get_y() << endl;
 return 0;
}
*/
class String {
 char *str;
 int len;
public:
 void set(char *cp);
 void prn();
};

void String::set(char *cp) {
 len = strlen(cp);
 str = new char[len+1];
 strcpy(str, cp);
}

void String::prn() {
 cout << "문자열: " << str << "(" << len << ")\n";
}

String input() {
 char text[80];
 String temp;
 cout << "Input String : ";
 cin >> text;
 temp.set(text);
 return temp;
}

int main() {
 String str1;
 str1 = input();
 str1.prn();
 return 0;
}

반응형