터미널에서 C ++ 프로젝트를 컴파일 할 수 없습니다.

Talcicio

내 할당은 C ++에서 접미사 식을 중위 식으로 변환하는 이진 식 트리를 만드는 것입니다. 나는 원래 내 Xcode IDE에서 모든 작업을 코딩했으며 터미널에서 linprog4로 주기적으로 ssh하여 터미널에서 작동하는지 확인했습니다. 왜냐하면 그것을 입력하기 전에해야하기 때문입니다. 사용하여 컴파일 할 때 나타나는 오류를 이해하지 못합니다. g ++ -o proj4.x -std = c ++ 11 proj4_driver.cpp BET.cpp

이 과제는 2 주 전에 마감되었으며 불행히도 모든 파일과 함께 tar 파일을 제출할 때 .tar 확장자를 포함하는 것을 잊었습니다. 나는 그것이 내 파일에 영향을 미칠 것이라고 생각하지 않지만 지금은 컴파일되지 않고 내가 얻는 오류를 이해하지 못합니다. 누군가 내 코드를 훑어보고 내가 빠진 것이 있는지 확인할 수 있습니까? 내 코드를 살펴본 결과 실수로 어딘가에 임의로 입력 한 것 같지 않습니다.

다음은 내가 받고있는 오류의 스크린 샷입니다. 여기에 이미지 설명 입력

BET.h

#ifndef BET_H
#define BET_H

using namespace std;

class BET {
    private:

        struct BinaryNode {

            string data;
            BinaryNode * parent;
            BinaryNode * childLeft;
            BinaryNode * childRight;
            bool visited;           // to tell if node has been visited to or not


            // Construct a blank copy version BinaryNode when an
            // object of BET is created
            BinaryNode( const char & d = char{}, BinaryNode * p = NULL,
                        BinaryNode * l = NULL,
                        BinaryNode * r = NULL,  bool v = false )
                        : data { d },
                        parent { p },
                        childLeft { l },
                        childRight { r },
                        visited { v } {}

            // Construct a blank move version of BinaryNode when an
            // an object of BET is created
            BinaryNode( char && d, BinaryNode * p = NULL, BinaryNode * l = NULL,
                        BinaryNode * r = NULL, bool v = false )
                        : data { std::move(d) },
                        parent { p },
                        childLeft { l },
                        childRight { r },
                        visited { v } {}

        };  // end of BinaryNode struct

    public:

        // constructors and destructor
        BET();
        BET( const string postfix );
        BET( const BET & rhs );
        ~BET();

        // help copy constructor
        bool buildFromPostfix( const string postfix );

        // copy assignment operator
        const BET & operator=( const BET & rhs );

        void printInfixExpression();
        void printPostfixExpression();

        size_t size();
        size_t leaf_nodes();

        bool empty();
        bool isOperand(BinaryNode * n);

    private:
        BinaryNode *root;
        size_t leaves, nodes;
        bool useP;

        void printInfixExpression( BinaryNode * n );
        void makeEmpty( BinaryNode* & t );
        BinaryNode * clone( BinaryNode * t ) const;
        void printPostfixExpression( BinaryNode * n );
        size_t size( BinaryNode * t );
        size_t leaf_nodes( BinaryNode * t );


}; // end of BET class

#endif

BET.cpp

#include <iostream>
#include <stack>
#include <sstream>
#include <string>
#include "BET.h"

//using namespace std;

// default zero-param constructor
BET::BET() {

    root = new BinaryNode;
    leaves = 0;
    nodes = 0;
}

// one-param constructor, where parameter "postfix" is a
// string containing a postfix expression. The tree should
// be built based on the postfix expression. Tokens in the
// postfix expression are separated by space
BET::BET(const string postfix) {

    root = new BinaryNode;
    buildFromPostfix(postfix);
}

// copy constructor
BET::BET(const BET & rhs) {

    leaves = rhs.leaves;
    nodes = rhs.nodes;
    root = rhs.root;
}

// destructor
BET::~BET() {

    makeEmpty(root);
    leaves = nodes = 0;
}

bool BET::buildFromPostfix(const string postfix) {

    // Create stack to hold variables
    stack<BinaryNode *> s;
    stack<BinaryNode> bet;
    char token;
    string temp;
    int index = 1;
    bool doubleDigit = false;
    int opCount = 0, digitCount = 0;

    //stringstream hexToInt;

    // iterator through postfix
    for (int i = 0; i < postfix.size(); ++i) {

        // grab token at iterations index
        token = postfix[i];


        if ( (token > '0' && token < '9') || (token > 62 && token < 80)) {
           // check to see if token is an operand

            // create a dynamic object of BinaryNode
            BinaryNode *operand = new BinaryNode;

            // check to see if next index of postfix is digit
            // if its not, then we know its a double digit
            // this while loop should only continue as long as the
            // next index is between 0 and 9

            temp = postfix[i];
            while (postfix[i + index] >= '0' && postfix[i + index] <= '9') {

                temp += postfix[i + index];
                index++;
                doubleDigit = true;
            }

            if (doubleDigit == true) {

                i += index;
                doubleDigit = false;
                index = 1;
                operand->data = temp;

            } else {

                operand->data = postfix[i];
            }

            s.push(operand);
            digitCount++;

        } else if (token == '+' || token == '-' || token == '*' || token == '/'){
            // check to see if token is operator

            BinaryNode *operand = new BinaryNode;
            operand->data = postfix[i];
            operand->childLeft = s.top();
            s.top()->parent = operand;
            s.pop();
            operand->childRight = s.top();
            s.top()->parent = operand;
            s.pop();
            s.push(operand);
            opCount++;
        } else {
            // if neither, must be space or other character

            if (token == ' ') {

            } else
                return false;
        }

    }

    if (digitCount <= opCount) {
        return false;
    }

    root = s.top();

    nodes = size();
    //leaves = leaf_nodes();

    // THINGS TO DO:
    // Make error cases with if statements to return false at some point
    return true;
}

// assignment operator
const BET & BET::operator=(const BET & rhs) {

    root = clone(rhs.root);

    return *this;
}

// public version of printInfixExpression()
// calls the private version of the printInfixExpression fuction
// to print out the infix expression
void BET::printInfixExpression() {


    printInfixExpression(root);
}

// public version of printPostfixExpression()
// calls the private version of the printPostfixExpression function
// to print out the postfix expression
void BET::printPostfixExpression() {

    printPostfixExpression(root);
}

// public version of size()
// calls the private version of the size function to return
// the number of nodes in the tree
size_t BET::size() {

    return size(root);
}


// public version of leaf_nodes()
// calls the private version of leaf_nodes function to return
// the number of leaf nodes in the tree
size_t BET::leaf_nodes() {

    return leaf_nodes(root);
}

// public version of empty()
// return true if the tree is empty. return false otherwise
bool BET::empty() {

    if (nodes == 0) {
        return true;
    } else
        return false;
}

// checks whether node is operand or not
bool BET::isOperand(BinaryNode * n) {

    if (n->data != "+" && n->data != "-" && n->data != "*" && n->data != "/") {
        return true;
    } else
        return false;

}
// private version of printInfixExpression
// print to the standard output the corresponding infix expression
void BET::printInfixExpression(BinaryNode * n) {
    //BinaryNode * temp = NULL;

    if (n != NULL ) {
        printInfixExpression(n->childRight);
        cout << n->data << " ";
        printInfixExpression(n->childLeft);
    }

    /*
    if (n != NULL && useP == true) {

        printInfixExpression(n->childRight);

        if (isOperand(n->parent)  && n->parent != NULL && !n->childLeft) {
            cout << "(";

        }

        cout << n->data << " ";

        if (isOperand(n->parent) && n->parent != NULL && !n->childRight) {
            cout << ")";
        }

        printInfixExpression(n->childLeft);

    }
    */
}

// private method makeEmpty()
// delete all nodes in the subtree pointed to by n.
// Called by functions such as the destructor
void BET::makeEmpty(BinaryNode * & n) {

    if (n != NULL) {
        makeEmpty(n->childLeft);
        makeEmpty(n->childRight);
        delete n;
    }
}

// private method clone()
// clone all nodes in the subtree pointed by n. Called by
// functions such as the assignment operator=
BET::BinaryNode * BET::clone(BinaryNode * n) const {


    if (n != NULL) {
        root->childRight = clone(n->childRight);
        root->childLeft = clone(n->childLeft);
        root->data = n->data;
    }

    return root;
}

// private method printPostfixExpression()
// print to the standard output the corresponding postfix expression
void BET::printPostfixExpression(BinaryNode * n) {

    if (n != NULL) {
        printPostfixExpression(n->childRight);
        printPostfixExpression(n->childLeft);
        cout << n->data << " ";
    }
}

// private version of size()
// return the number of nodes in the subtree pointed by n
size_t BET::size(BinaryNode * n) {


    if (n != NULL) {
        size(n->childLeft);
        size(n->childRight);
        nodes++;
    }

    return nodes;
}

// return the number of leaf nodes in the subtree pointed by n
size_t BET::leaf_nodes(BinaryNode * n) {

    if (n != NULL) {
        leaf_nodes(n->childLeft);
        leaf_nodes(n->childRight);

        if (n->childLeft == NULL && n->childRight == NULL) {
            leaves += 1;
        }
    }

    return leaves;
}

Driver.cpp

#include "BET.cpp"

//using namespace std;


int main() {
    string postfix;

    // get a postfix expression
    cout << "Enter the first postfix expression: ";
    getline(cin, postfix);

    // create a binary expression tree
    BET bet1(postfix);

    if (!bet1.empty()) {
        cout << "Infix expression: ";
        bet1.printInfixExpression();
        cout << "\n";

    cout << "Postfix expression: ";
    bet1.printPostfixExpression();

    cout << "\nNumber of nodes: ";
    cout << bet1.size() << endl;

    cout << "Number of leaf nodes: ";
    cout << bet1.leaf_nodes() << endl;

        // test copy constructor
        BET bet2(bet1);
        cout << "Testing copy constructor: ";
        //bet2.printInfixExpression();

        // test assignment operator
        BET bet3;
        bet3 = bet1;
        cout << "Testing assignment operator: ";
        //bet3.printInfixExpression();
    }

    cout << "Enter a postfix expression (or \"quit\" to quit): ";
    while (getline(cin, postfix)) {
    if (postfix == "quit") {
        break;
        }
    if (bet1.buildFromPostfix(postfix)) {
        cout << "Infix expression: ";
        bet1.printInfixExpression();

        cout << "Postfix expression: ";
        bet1.printPostfixExpression();

        cout << "Number of nodes: ";
        cout << bet1.size() << endl;

        cout << "Number of leaf nodes: ";
        cout << bet1.leaf_nodes() << endl;
    }
    cout << "Enter a postfix expression (or \"quit\" to quit): ";
    }
    return 0;

}
존 3136

Driver.cpp #include "BET.cpp"#include "BET.h"

또는 (그리고 이것은 단지 완전성을위한 것이며 권장되지 않습니다), .cpp의 포함을 남겨두고 .cpp (에서와 같이 g++ Driver.cpp) 만 컴파일하십시오 -드라이버가 BET를 포함하므로 모든 코드가 거기에 있고 짓다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

다른 프로젝트 C #에서 파일을 컴파일 할 수 없습니다.

분류에서Dev

qtcreator에서 Qt 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

Visual Studio 2015 / C # 6 / Roslyn은 PCL 프로젝트에서 XML 주석을 컴파일 할 수 없습니다.

분류에서Dev

포인터 문제로 인해 Delphi 4에서 이전 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

Linux 터미널에서 C # 코드를 어떻게 컴파일 할 수 있습니까?

분류에서Dev

Ubuntu를 사용하여 Eclipse에서 NDK 프로젝트를 만들고 컴파일 할 수 없습니다.

분류에서Dev

Android 스튜디오에서는 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

Android Studio에서는 특정 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

Intellij에서 프로젝트를 이동했는데 이제 컴파일 할 수 없습니다.

분류에서Dev

온라인 컴파일러를 사용하여 잘 컴파일되지만 내 컴퓨터에서 C ++ 함수를 컴파일 할 수 없습니다.

분류에서Dev

Facebook SDK로 인해 Gradle 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

Ubuntu 터미널에서 C # 코드를 어떻게 컴파일, 실행 및 디 컴파일 할 수 있습니까?

분류에서Dev

스칼라 / SBT 프로젝트를 컴파일 할 수 없습니다.

분류에서Dev

"& lt;"로 C # 코드를 컴파일 할 수 없습니다. 및 "& gt;" 그것에

분류에서Dev

netbeans 창에서 C 코드를 컴파일 할 수 없습니다.

분류에서Dev

C ++ 프로그램을 컴파일 할 수 없습니다.

분류에서Dev

c로 컴파일 한 후 오브젝트 파일에서 구조 정의를 사용할 수 있습니까?

분류에서Dev

Linux 터미널에서 C ++ 파일을 컴파일하고 실행할 수 있습니까?

분류에서Dev

C # 프로젝트에서 C ++ / CLI 프로젝트의 클래스를 사용할 수 없습니다.

분류에서Dev

C ++ 함수를 컴파일 할 수 없습니다.

분류에서Dev

터미널의 파일 이름에서 아포스트로피를 제거 할 수 없습니다.

분류에서Dev

Android 프로젝트에서 aar의 전이 종속성을 컴파일 할 수 없습니다.

분류에서Dev

C ++ : 컴파일 오류를 이해할 수 없습니다.

분류에서Dev

C 라이브러리를 컴파일 할 수 없습니다.

분류에서Dev

C 프로그래밍 언어에서 예제 프로그램을 컴파일 할 수 없습니다.

분류에서Dev

프로 토크 생성 (C ++) 클래스를 컴파일 할 수 없습니다.

분류에서Dev

한 C # 프로젝트에서 다른 프로젝트로 클래스를 가져올 때 자동 생성 된 파일을 제외 할 수 있습니까?

분류에서Dev

메모장 ++에서 C ++를 컴파일 할 때 "지정된 파일을 찾을 수 없습니다"오류

분류에서Dev

OpenCl은 'printf'로 커널을 컴파일 할 수 없습니다.

Related 관련 기사

  1. 1

    다른 프로젝트 C #에서 파일을 컴파일 할 수 없습니다.

  2. 2

    qtcreator에서 Qt 프로젝트를 컴파일 할 수 없습니다.

  3. 3

    Visual Studio 2015 / C # 6 / Roslyn은 PCL 프로젝트에서 XML 주석을 컴파일 할 수 없습니다.

  4. 4

    포인터 문제로 인해 Delphi 4에서 이전 프로젝트를 컴파일 할 수 없습니다.

  5. 5

    Linux 터미널에서 C # 코드를 어떻게 컴파일 할 수 있습니까?

  6. 6

    Ubuntu를 사용하여 Eclipse에서 NDK 프로젝트를 만들고 컴파일 할 수 없습니다.

  7. 7

    Android 스튜디오에서는 프로젝트를 컴파일 할 수 없습니다.

  8. 8

    Android Studio에서는 특정 프로젝트를 컴파일 할 수 없습니다.

  9. 9

    Intellij에서 프로젝트를 이동했는데 이제 컴파일 할 수 없습니다.

  10. 10

    온라인 컴파일러를 사용하여 잘 컴파일되지만 내 컴퓨터에서 C ++ 함수를 컴파일 할 수 없습니다.

  11. 11

    Facebook SDK로 인해 Gradle 프로젝트를 컴파일 할 수 없습니다.

  12. 12

    Ubuntu 터미널에서 C # 코드를 어떻게 컴파일, 실행 및 디 컴파일 할 수 있습니까?

  13. 13

    스칼라 / SBT 프로젝트를 컴파일 할 수 없습니다.

  14. 14

    "& lt;"로 C # 코드를 컴파일 할 수 없습니다. 및 "& gt;" 그것에

  15. 15

    netbeans 창에서 C 코드를 컴파일 할 수 없습니다.

  16. 16

    C ++ 프로그램을 컴파일 할 수 없습니다.

  17. 17

    c로 컴파일 한 후 오브젝트 파일에서 구조 정의를 사용할 수 있습니까?

  18. 18

    Linux 터미널에서 C ++ 파일을 컴파일하고 실행할 수 있습니까?

  19. 19

    C # 프로젝트에서 C ++ / CLI 프로젝트의 클래스를 사용할 수 없습니다.

  20. 20

    C ++ 함수를 컴파일 할 수 없습니다.

  21. 21

    터미널의 파일 이름에서 아포스트로피를 제거 할 수 없습니다.

  22. 22

    Android 프로젝트에서 aar의 전이 종속성을 컴파일 할 수 없습니다.

  23. 23

    C ++ : 컴파일 오류를 이해할 수 없습니다.

  24. 24

    C 라이브러리를 컴파일 할 수 없습니다.

  25. 25

    C 프로그래밍 언어에서 예제 프로그램을 컴파일 할 수 없습니다.

  26. 26

    프로 토크 생성 (C ++) 클래스를 컴파일 할 수 없습니다.

  27. 27

    한 C # 프로젝트에서 다른 프로젝트로 클래스를 가져올 때 자동 생성 된 파일을 제외 할 수 있습니까?

  28. 28

    메모장 ++에서 C ++를 컴파일 할 때 "지정된 파일을 찾을 수 없습니다"오류

  29. 29

    OpenCl은 'printf'로 커널을 컴파일 할 수 없습니다.

뜨겁다태그

보관