Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:22:38+00:00 2026-06-16T17:22:38+00:00

#include <cstdlib> #include <iostream> #include Node.h #ifndef HW4_H #define HW4_H using namespace std; /**

  • 0
#include <cstdlib>
#include <iostream>
#include "Node.h"
#ifndef HW4_H
#define HW4_H
using namespace std;
/**
You are to implement the two functions in this class.
You can add any other method or members to it as well.
However, you cannot change their signature.  
**/
class HW4{

public:
    int count(Node* r) const
    {
        if(r->next==NULL&&r->bro==NULL) { return 0;}
        if(r.isLeaf())
        {
            return ((1+count(r->next)+count(r->bro)));
        }
        count(r->next);
    }

    /*
    This method will return true if the tree rooted at node sn can answer
    the demand induced by its leaves.
    */
    bool canDemandBeAnswered(Node* root)
    {
        if(count(root)>(root.getCapacity()))
        {
            return 0;
            exit(0);      
        }
        else 
        {
            return (canDemandBeAnswered(root->next)&&canDemandBeAnswered(root->bro));
        }
    }




    /*
    This method should return a linked list of nodes representing the 
    customers with the overall highest revenue.
    The resulting list should conform to the capacity limitations.
    */
    //     Node* getBestCustomers(Node* root);


};

#endif

#include <cstdlib>
#ifndef NODE_H
#define NODE_H

/**
The Node class. You must implement the two methods isLeaf() and addChild(Node*) below.
Otherwise, you can add any methods or members your heart's desire.
The only limitation is that they have to be in this file.
**/
class Node { 
private:
    int capacity;
    int price;


public:
    /**
    Hint: to be used for saving the Node's children and for returning the linked list           
    **/
    Node* next;
    Node* bro;

    Node(){
        capacity = 0;          
        price = 0;
    }
    Node(int capacity_){
        capacity = capacity_;  
        price = 0;
    }                

    //should return true if this node has no children, false otherwise.

    //this method adds a child to this node.


    int getCapacity(){
        return capacity;
    }   


    int getPrice(){
        return price;
    }

    void setPrice(int price_){
        price = price_;
    } 


    bool isLeaf()
    {
        if((this->next)->capacity==0)
            return 1;
        else return 0;
    }     


    void addChild(Node* child)
    {
        Node* temp;
        if(this->next!=NULL)
        {
            temp=this->next;
            child->bro=temp;
            this->next=child;
        }
        else
            this->next=child;
    }  
};




#endif

I get the following error: “isLeaf() has not been declared”. I don’t understand why – I declared both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:22:39+00:00Added an answer on June 16, 2026 at 5:22 pm
    bool canDemandBeAnswered(Node* root)
    {
        if(count(root)>(root.getCapacity()))
    

    This attempts to call getCapacity on a Node *. But Node * doesn’t have a function called getCapacity — Node does.

    You can use (*root).getCapacity() or the shorthand, root->getCapacity().

          if(r.isLeaf())
    

    You have the same issue here. r is a Node *.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've try to compile this code: #include <iostream> #include <cstdlib> using namespace std; #define
#include <cstdlib> #include<iostream> using namespace std; template <typename T> class stack { public: T
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
Code looks like that #include <cstdlib> #include <iostream> using namespace std; #define n 3;
Consider the following program #include <iostream> #include<cstdlib> using namespace std; class E { public:
This is a small program: #include <iostream> #include <cstdlib> using namespace std; int main()
#include <cmath> #include <iostream> #include <cstdlib> using namespace std; class myClass { int d;
i want to implement binary_search with pointers #include <cstdlib> #include <iostream> using namespace std;
#include <cstdlib> #include <iostream> #include <string> #include <string.h> using namespace std; class Portfolio{ public
SO i have this code: #include <iostream> #include <cstdlib> using namespace std; int main()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.