1. ¶
~cpp #include<iostream> using namespace std; class student { private: char Name[20]; // int ID; //번 int Math; // int Korean; // int English; // public: student(); //디 student(char *name, int id, int math, int kor, int eng);// ~student(); //멸 int getTotal(); // 는 void outputID(); //번, int getMath(); // int getKor(); // int getEng(); // }; student::student() { } student::student(char *name, int id, int math, int kor, int eng) { strcpy(Name, name); //() ID = id; //번 Math = math; // Korean= kor; // English = eng; // } student::~student() { } int student::getTotal() { return Math + Korean + English;//리 } void student::outputID() { cout << ID << " " << Name << endl;//번 } int student::getMath() { return Math; //리 } int student::getKor() { return Korean; //리 } int student::getEng() { return English; //리 } void main() { int Max; int bestStu; int i; const int numberOfStudent = 10;// student stu[numberOfStudent] = {student("KangHeeKyoung", 953, 99, 99, 99), student("KimSooJin", 954, 55, 100, 12), student("ParkJinHa", 955, 66, 87, 11), student("ParkJinYoung", 956, 11, 23, 54), student("KimTaeHyuk", 957, 10, 9, 4), student("LeeChunSoo", 958, 100, 40, 19), student("AnJaeHyun", 959, 0, 0, 0), student("ByunJoonWon", 960, 2, 3, 1), student("SinJaeDong", 961, 1, 2, 100), student("NoSooMin", 963, 0, 4, 1)};// 배 및 Max = 0; for(i = 0; i < numberOfStudent; i++) { if(stu[i].getTotal() > Max) { bestStu = i; Max = stu[i].getTotal(); } } //대 대 를 는. cout << ": "; stu[bestStu].outputID(); //번, Max = 0; for(i = 0; i < numberOfStudent; i++) { if(stu[i].getMath() > Max) { bestStu = i; Max = stu[i].getMath(); } } cout << ": "; stu[bestStu].outputID(); Max = 0; for(i = 0; i < numberOfStudent; i++) { if(stu[i].getKor() > Max) { bestStu = i; Max = stu[i].getKor(); } } cout << ": "; stu[bestStu].outputID(); Max = 0; for(i = 0; i < numberOfStudent; i++) { if(stu[i].getEng() > Max) { bestStu = i; Max = stu[i].getEng(); } } cout << ": "; stu[bestStu].outputID(); }
1.1. ¶
~cpp #include<iostream.h> void output(int a); void main() { const int b = 10; output(5); b--; cout << b <<endl; } void output(int a) { for(int i = 0; i < a; i++) { cout << "" << endl; } }
2. ¶
~cpp #include<iostream.h> void main() { char c; char *pc = &c; c = 'y'; cout << *pc << endl; cout << c << endl; }
배
~cpp #include<iostream.h> void main() { char array[3]; char *pa; pa = array; //&array[0] *pa = 'a'; *(pa + 1) = 'b'; *(pa + 2) = 'c'; for(int i = 0; i < 3; i++) cout << array[i] << endl; }
++
~cpp #include<iostream.h> void main() { char array[3]; char *pa; pa = array; //&array[0] for(int i = 65; i < 68; i++) *(pa++) = i; for(i = 0; i < 3; i++) cout << *(--pa) << endl; }
배
~cpp #include<iostream.h> void main() { char array[3]; char *pa[3]; //pa = array; //&array[0] for(int i = 0; i < 3; i++) pa[i] = &array[i]; for(i = 0; i < 3; i++) *pa[i] = i+65; for(i = 0; i < 3; i++) cout << array[i] << endl; }
~cpp #include<iostream.h> struct node { char data; node *link; }; void main() { node type1; type1.data = 'a'; node type2; type2.data = 'b'; type1.link = &type2; type2.link = NULL; cout << (*(type1.link)).data << endl; }
링 리
~cpp #include<iostream> using namespace std; struct Node { char data; Node* link; }; void main() { Node array[100]; Node* pNode; int index = 0; char input; do{ cout << ": "; cin >> input; if(input != 'q') { if(index == 0){ array[0].data = input; array[0].link = NULL; } else { array[index].data = input; array[index].link = NULL; array[index-1].link = &array[index]; } index++; pNode = array; while(pNode != NULL) { cout << pNode->data << " "; pNode = pNode->link; } cout << "NULL" << endl; } }while(input != 'q'); }