TransWikia.com

Не работает код, подробности в коментарие кода

Stack Overflow на русском Asked on November 5, 2021

/*Я делаю лабораторную работу, мне нужно создать перевод римских чисел в арабские и наоборот, после этого сказали добавить конструктор класса и все пошло через одно место, пишет: “”Roman_Arab_num::get_roman”: нестандартный синтаксис; используйте “&”, чтобы создать указатель на член”, также, при запуске отладки, выводится надпись: “не удается найти файл”

#include <iostream>
#include <string>

using namespace std;

void print_main_choice() {
    cout << "'1' - arab to roman" << endl;
    cout << "'2' - roman ro arab" << endl;
    cout << "'3' - add/sub/mul/div of roman numbers" << endl;
    cout << "'0' - END" << endl;
}
void roman_combination() {
    cout << "|i - 1    |ii  - 2   |iii - 3    |iv - 4    |v - 5    |vi - 6    |vii - 7    |viii - 8    |ix - 9    |" << endl;
    cout << "|x - 10   |xx - 20   |xxx - 30   |xl - 40   |l - 50   |lx - 60   |lxx - 70   |lxxx - 80   |xc - 90   |" << endl;
    cout << "|c - 100  |cc - 200  |ccc - 300  |cd - 400  |d - 500  |dc - 600  |dcc - 700  |dccc - 800  |cm - 900  |" << endl;
    cout << "|m - 1k   |mm - 2k   |mmm - 3k   |mV - 4k   |V - 5k   |Vm - 6k   |Vmm - 7k   |Vmmm - 8k   |mX - 9k   |" << endl;
    cout << "|X - 10k  |XX - 20k  |XXX - 30k  |XL - 40k  |L - 50k  |LX - 60k  |LXX - 70k  |LXXX - 80k  |XC - 90k  |" << endl;
    cout << "|C - 100k |CC - 200k |CCC - 300k |CD - 400k |D - 500k |DC - 600k |DCC - 700k |DCCC - 800k |CM - 900k |" << endl;
    cout << "|M - 1kk  |MM - 2kk  |MMM - 3kk  |" << endl << endl;
}

class Roman_Arab_num {
private:
    int arab_class;
    string roman_class;

    string func(int num, string ten, string five, string one)
    {
        switch (num)
        {
        case 9:
            return one + ten;
        case 8:
            return five + one + one + one;
        case 7:
            return five + one + one;
        case 6:
            return five + one;
        case 5:
            return five;
        case 4:
            return one + five;
        case 3:
            return one + one + one;
        case 2:
            return one + one;
        case 1:
            return one;
        case 0:
            return "";
        }
    }
    int func2(char symb)
    {
        switch (symb)
        {
        case 'i':
            return 1;
        case 'v':
            return 5;
        case 'x':
            return 10;
        case 'l':
            return 50;
        case 'c':
            return 100;
        case 'd':
            return 500;
        case 'm':
            return 1000;
        case 'V':
            return 5000;
        case 'X':
            return 10000;
        case 'L':
            return 50000;
        case 'C':
            return 100000;
        case 'D':
            return 500000;
        case 'M':
            return 1000000;
        default:
            return 0;
        }
    }

public:
    Roman_Arab_num(int arab = 0){
        arab_class = arab;
    }
    Roman_Arab_num(string roman = "i") {
        roman_class = roman;
    }
    string arab_to_roman(int arab_class) {
        roman_class = func(arab_class / 1000000, "", "", "M");
        arab_class %= 1000000;
        roman_class += func(arab_class / 100000, "M", "D", "C");
        arab_class %= 100000;
        roman_class += func(arab_class / 10000, "C", "L", "X");
        arab_class %= 10000;
        roman_class += func(arab_class / 1000, "X", "V", "m");
        arab_class %= 1000;
        roman_class += func(arab_class / 100, "m", "d", "c");
        arab_class %= 100;
        roman_class += func(arab_class / 10, "c", "l", "x");
        arab_class %= 10;
        roman_class += func(arab_class, "x", "v", "i");
        return roman_class;
    }
    /*string check_symbols(string roman_check) {
        int s_1 = 0;
        while (roman_check[s_1] != '') {
            if (func2(roman_check[s_1]) == 0) {
                cout << "There is an invalid characters symbol!" << endl;
                roman_combination();
                cout << "Enter roman number again: " << endl;
                cin >> roman_check;
                s_1 = 0;
            }
            else {
                s_1++;
            }
        }
        return roman_check;
    }*/
    /*int roman_to_arab(string roman_class) {
        arab_class = 0;
        int s_1 = 0;

        while (roman_class[s_1] != '') {
            int s_2 = s_1 + 1;
            if (func2(roman_class[s_1]) > func2(roman_class[s_2])) {
                arab_class += func2(roman_class[s_1]);
                s_1++;
            }
            else if (func2(roman_class[s_1]) < func2(roman_class[s_2])) {
                arab_class -= func2(roman_class[s_1]);
                s_1++;
            }
            else if (roman_class[s_1] == roman_class[s_2]) {
                arab_class += func2(roman_class[s_1]);
                s_1++;
            }
            else if (roman_class[s_2] == '') {
                arab_class += func2(roman_class[s_1]);
                s_1++;
            }
        }
        return arab_class;
    }*/
    string get_roman() {
        return arab_to_roman(arab_class);
    }
    /*int get_arab() {
        return roman_to_arab(roman_class);
    }*/
};

int main() {
    int arab_main = 0;
    string roman_main;
    string choice = "";

    print_main_choice();
    cin >> choice;

    while (choice != "0") {
        if (choice == "1") {
            cout << "Enter arab number: ";
            cin >> arab_main;
            Roman_Arab_num obj(arab_main);
            if (arab_main <= 0) {
                cout << "Such number no in roman numbers!" << endl;
                continue;
            }
            else if (arab_main >= 4000000) {
                cout << "Very high number!" << endl;
                continue;
            }
            else {
                cout << obj.get_roman << endl;
                print_main_choice();
                cin >> choice;
            }
        }
        /*else if (choice == "2") {
            roman_combination();
            cout << "Enter your roman number: ";
            cin >> roman_main;
            Roman_Arab_num obj(roman_main);
            roman_main = obj.check_symbols;
            arab_main = obj.get_arab;
            cout << arab_main << endl;
            print_main_choice();
            cin >> choice;
        }*/
        /*else if (choice == "3") {
            cout << "'1' - addition" << endl;
            cout << "'2' - subtraction" << endl;
            cout << "'3' - multiplication" << endl;
            cout << "'4' - division" << endl;
            cin >> choice;
            if (choice == "1") {
                roman_combination();
                cout << "Enter your first roman numbers: ";
                cin >> roman_main;
                roman_main = obj.check_symbols(roman_main, s_1);
                cout << "Enter your second roman numbers: ";
                cin >> roman_main2;
                roman_main2 = obj.check_symbols(roman_main2, s_1);
                arab_main = obj.roman_to_arab(roman_main, s_1);
                result = arab_main + obj.roman_to_arab(roman_main2, s_1);
                cout << "Your result = " << result << endl;
                cout << obj.arab_to_roman(result) << endl;
                print_main_choice();
                cin >> choice;
            }
            else if (choice == "2") {
            }
            else if (choice == "3") {
            }
            else if (choice == "4") {
            }
            else {
            }
        }*/
        else {
            cout << "Invalid value, please try again" << endl;
            print_main_choice();
            cin >> choice;
        }
    }
}

One Answer

Банальная опечатка. Вместо

cout << obj.get_roman

должно быть

cout << obj.get_roman()

Answered by Герман Борисов on November 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP