Основы языка программирования C++ с применением объектно-ориентированного программирования. Чернышов М.К. - 62 стр.

UptoLike

Составители: 

ɛ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɜɵɱɢɫɥɟɧɢɹ ɫɬɨɥɛɰɚ ɱɚɫɬɧɵɯ ɨɬ ɞɟɥɟɧɢɹ ɷɥɟ-
ɦɟɧɬɨɜ ɨɞɧɨɝɨ ɫɬɨɥɛɰɚ ɧɚ ɷɥɟɦɟɧɬɵ ɞɪɭɝɨɝɨ ɫɬɨɥɛɰɚ. ɉɪɟɞɭɫɦɨɬɪɟɬɶ ɫɢɝ-
ɧɚɥɢɡɚɰɢɸ ɨ ɫɥɭɱɚɟ, ɤɨɝɞɚ ɷɥɟɦɟɧɬ ɫɬɨɥɛɰɚ-ɞɟɥɢɬɟɥɹ ɪɚɜɟɧ ɧɭɥɸ. Ɉɫɬɚɥɶ-
ɧɵɟ ɭɫɥɨɜɢɹɤɚɤ ɜ ɜɚɪɢɚɧɬɟ (ɚ).
int subcol(int k, int l, int r);
ɜ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɜɵɱɢɫɥɟɧɢɹ ɷɥɟɦɟɧɬɨɜ ɫɬɨɥɛɰɚ ɨɬɧɨɫɢɬɟɥɶɧɵɯ
ɩɪɢɪɨɫɬɨɜ ɜ ɩɪɨɰɟɧɬɚɯ
di=(ai-bi)/ai*100 ɞɥɹ ɡɚɞɚɧɧɨɝɨ ɢɫɯɨɞɧɨɝɨ
ɫɬɨɥɛɰɚ. Ɉɫɬɚɥɶɧɵɟ ɭɫɥɨɜɢɹ - ɤɚɤ ɜ ɜɚɪɢɚɧɬɚɯ (ɚ) ɢ (ɛ).
int relincr(int k, int r);
Ɏɭɧɤɰɢɹ ɜɨɡɜɪɚɳɚɟɬ 1, ɟɫɥɢ ɜɫɬɪɟɬɢɬɫɹ ɞɟɥɢɬɟɥɶ, ɪɚɜɧɵɣ 0, ɜ ɨɫɬɚɥɶɧɵɯ
ɫɥɭɱɚɹɯ ɜɨɡɜɪɚɳɚɟɬ 0.
ɝ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɩɟɱɚɬɢ ɬɚɛɥɢɰɵ, ɫɨɞɟɪɠɚɳɟɣ ɫɬɨɥɛɰɵ, ɩɟɪɟɱɟɧɶ
ɤɨɬɨɪɵɯ ɡɚɞɚɧ ɫɩɢɫɤɨɦ (ɦɚɫɫɢɜɨɦ ) ɢɧɞɟɤɫɨɜ (ɧɨɦɟɪɨɜ) ɫɬɨɥɛɰɨɜ ɜ ɦɚɫɫɢ-
ɜɟ
Tabl.
int tabprint(int *list, int n);
12. ȼ ɧɟɤɨɬɨɪɨɣ ɩɪɨɝɪɚɦɦɟ ɚɧɚɥɢɬɢɱɟɫɤɢɯ ɩɪɟɨɛɪɚɡɨɜɚɧɢɣ ɜɵɪɚɠɟɧɢɹ,
ɨɩɪɟɞɟɥɹɸɳɢɟ ɮɨɪɦɭɥɵ, ɯɪɚɧɹɬɫɹ ɜ ɜɢɞɟ ɞɢɧɚɦɢɱɟɫɤɢɯ ɫɬɪɭɤɬɭɪɞɟ-
ɪɟɜɶɟɜ ɫ ɨɩɢɫɚɧɢɟɦ:
enum tpn {FUNC, OPER, VAR, CNST}; // ɬɢɩɵ ɭɡɥɨɜ
struct node
{
enum tpn tp_node; // ɬɢɩ ɭɡɥɚ
int cop; /* ɬɢɩ ɨɩɟɪɚɰɢɢ ɢɥɢ ɧɨɦɟɪ ɮɭɧɤɰɢɢ,
ɤɨɧɫɬɚɧɬɵ, ɩɟɪɟɦɟɧɧɨɣ */
node *al, *ar; // ɭɤɚɡɚɬɟɥɢ ɧɚ ɩɨɞɱɢɧɟɧɧɵɟ ɭɡɥɵ
};
ɚ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɨɛɯɨɞɚ ɞɟɪɟɜɚ, ɡɚɞɚɧɧɨɝɨ ɭɤɚɡɚɬɟɥɟɦ ɧɚ ɟɝɨ ɤɨ-
ɪɟɧɶ, ɜ ɩɨɪɹɞɤɟ: ɥɟɜɨɟ ɩɨɞɞɟɪɟɜɨ, ɤɨɪɟɧɶ, ɩɪɚɜɨɟ ɩɨɞɞɟɪɟɜɨ. ȼɵɜɨɞɢɬɶ ɧɚ
ɷɤɪɚɧ (ɩɟɱɚɬɶ) ɬɢɩ ɭɡɥɚ ɢ ɡɧɚɱɟɧɢɟ ɩɨɥɹ
cop ɜ ɭɡɥɟ.
void lkp(node *root);
ɛ) ȼ ɭɫɥɨɜɢɹɯ ɩɭɧɤɬɚ (ɚ) ɜɵɩɨɥɧɢɬɶ ɨɛɯɨɞ ɞɟɪɟɜɚ ɜ ɩɨɪɹɞɤɟ: ɤɨɪɟɧɶ, ɥɟɜɨɟ
ɩɨɞɞɟɪɟɜɨ, ɩɪɚɜɨɟ ɩɨɞɞɟɪɟɜɨ.
void klp(node *root);
62
ɛ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɜɵɱɢɫɥɟɧɢɹ ɫɬɨɥɛɰɚ ɱɚɫɬɧɵɯ ɨɬ ɞɟɥɟɧɢɹ ɷɥɟ-
ɦɟɧɬɨɜ ɨɞɧɨɝɨ ɫɬɨɥɛɰɚ ɧɚ ɷɥɟɦɟɧɬɵ ɞɪɭɝɨɝɨ ɫɬɨɥɛɰɚ. ɉɪɟɞɭɫɦɨɬɪɟɬɶ ɫɢɝ-
ɧɚɥɢɡɚɰɢɸ ɨ ɫɥɭɱɚɟ, ɤɨɝɞɚ ɷɥɟɦɟɧɬ ɫɬɨɥɛɰɚ-ɞɟɥɢɬɟɥɹ ɪɚɜɟɧ ɧɭɥɸ. Ɉɫɬɚɥɶ-
ɧɵɟ ɭɫɥɨɜɢɹ – ɤɚɤ ɜ ɜɚɪɢɚɧɬɟ (ɚ).

     int subcol(int k, int l, int r);

ɜ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɜɵɱɢɫɥɟɧɢɹ ɷɥɟɦɟɧɬɨɜ ɫɬɨɥɛɰɚ ɨɬɧɨɫɢɬɟɥɶɧɵɯ
ɩɪɢɪɨɫɬɨɜ ɜ ɩɪɨɰɟɧɬɚɯ di=(ai-bi)/ai*100 ɞɥɹ ɡɚɞɚɧɧɨɝɨ ɢɫɯɨɞɧɨɝɨ
ɫɬɨɥɛɰɚ. Ɉɫɬɚɥɶɧɵɟ ɭɫɥɨɜɢɹ - ɤɚɤ ɜ ɜɚɪɢɚɧɬɚɯ (ɚ) ɢ (ɛ).

     int relincr(int k, int r);

Ɏɭɧɤɰɢɹ ɜɨɡɜɪɚɳɚɟɬ 1, ɟɫɥɢ ɜɫɬɪɟɬɢɬɫɹ ɞɟɥɢɬɟɥɶ, ɪɚɜɧɵɣ 0, ɜ ɨɫɬɚɥɶɧɵɯ
ɫɥɭɱɚɹɯ ɜɨɡɜɪɚɳɚɟɬ 0.

ɝ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɩɟɱɚɬɢ ɬɚɛɥɢɰɵ, ɫɨɞɟɪɠɚɳɟɣ ɫɬɨɥɛɰɵ, ɩɟɪɟɱɟɧɶ
ɤɨɬɨɪɵɯ ɡɚɞɚɧ ɫɩɢɫɤɨɦ (ɦɚɫɫɢɜɨɦ ) ɢɧɞɟɤɫɨɜ (ɧɨɦɟɪɨɜ) ɫɬɨɥɛɰɨɜ ɜ ɦɚɫɫɢ-
ɜɟ Tabl.

     int tabprint(int *list, int n);

12. ȼ ɧɟɤɨɬɨɪɨɣ ɩɪɨɝɪɚɦɦɟ ɚɧɚɥɢɬɢɱɟɫɤɢɯ ɩɪɟɨɛɪɚɡɨɜɚɧɢɣ ɜɵɪɚɠɟɧɢɹ,
ɨɩɪɟɞɟɥɹɸɳɢɟ ɮɨɪɦɭɥɵ, ɯɪɚɧɹɬɫɹ ɜ ɜɢɞɟ ɞɢɧɚɦɢɱɟɫɤɢɯ ɫɬɪɭɤɬɭɪ – ɞɟ-
ɪɟɜɶɟɜ ɫ ɨɩɢɫɚɧɢɟɦ:

     enum tpn {FUNC, OPER, VAR, CNST};            // ɬɢɩɵ ɭɡɥɨɜ
     struct node
        {
        enum tpn tp_node;                           // ɬɢɩ ɭɡɥɚ
        int cop;             /* ɬɢɩ ɨɩɟɪɚɰɢɢ ɢɥɢ ɧɨɦɟɪ ɮɭɧɤɰɢɢ,
                                ɤɨɧɫɬɚɧɬɵ, ɩɟɪɟɦɟɧɧɨɣ */
        node *al, *ar;         // ɭɤɚɡɚɬɟɥɢ ɧɚ ɩɨɞɱɢɧɟɧɧɵɟ ɭɡɥɵ
        };

ɚ) ɋɨɫɬɚɜɢɬɶ ɮɭɧɤɰɢɸ ɞɥɹ ɨɛɯɨɞɚ ɞɟɪɟɜɚ, ɡɚɞɚɧɧɨɝɨ ɭɤɚɡɚɬɟɥɟɦ ɧɚ ɟɝɨ ɤɨ-
ɪɟɧɶ, ɜ ɩɨɪɹɞɤɟ: ɥɟɜɨɟ ɩɨɞɞɟɪɟɜɨ, ɤɨɪɟɧɶ, ɩɪɚɜɨɟ ɩɨɞɞɟɪɟɜɨ. ȼɵɜɨɞɢɬɶ ɧɚ
ɷɤɪɚɧ (ɩɟɱɚɬɶ) ɬɢɩ ɭɡɥɚ ɢ ɡɧɚɱɟɧɢɟ ɩɨɥɹ cop ɜ ɭɡɥɟ.

     void lkp(node *root);

ɛ) ȼ ɭɫɥɨɜɢɹɯ ɩɭɧɤɬɚ (ɚ) ɜɵɩɨɥɧɢɬɶ ɨɛɯɨɞ ɞɟɪɟɜɚ ɜ ɩɨɪɹɞɤɟ: ɤɨɪɟɧɶ, ɥɟɜɨɟ
ɩɨɞɞɟɪɟɜɨ, ɩɪɚɜɨɟ ɩɨɞɞɟɪɟɜɨ.

     void klp(node *root);

                                   62