"C ++ shortcut tutorial" reading notes - Chapter 11 - Class (Part 4)

xiaoxiao2021-03-18  204

// - "C shortcut tutorial" reading notes - Chapter 11 - Class (Part 4) // - Chapter 11 - Class // - 03/15/2006 Wed.//--computer LAB / / - Liwei

// - Program # 4 queuq # include usingspace std;

INT size = 3;

Class Queue {Int Sloc, Rloc; Int WHO;

PUBLIC: INT Q [3]; Queue (int ID); ~ queue (); void qput (int i); int rt QGet ();};

Queue :: queue (int ID) {rloc = Sloc = -1; q [0] = 0; WHO = ID; cout << "queue" << WHO << "Initialized./N";

}

Queue :: ~ queue () {cout << "Queue" << WHO << "DESTROYED./N";

Void queue :: qput (int i) {if (sloc == size) {cout << "Queue is full./N"; return;} Sloc ; Q [Sloc] = i;

}

INT Queue :: qget () {if (rloc == size) {cout << "queue underflow./N"; return 0;} rloc ; return q [rloc];

}

INT main () {Queue A (1), B (2); A.QPUT (10); B.QPut (19);

A.QPUT (20); B.QPut (1);

A.QPUT (999); B.QPut (999);

COUT << a.Qget () << "; cout << a.qu () <<"; cout << a.Qget () << "/ n ========== / N "; cout << B.Qget () <<" "; cout << B.Qget () <<"; cout << B.QGet () << "/ n";

COUT << A.Q [0] << '<< B.Q [0] << endl; return 0;

转载请注明原文地址:https://www.9cbs.com/read-129889.html

New Post(0)