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 7781535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:15:29+00:00 2026-06-01T19:15:29+00:00

For my CS assignment, we were to implement a binary heap to replace the

  • 0

For my CS assignment, we were to implement a binary heap to replace the STL priority queue on her working program, that was the first part. For the second part, we have to re-implement it using polymorphism. I finished the first part, and all I did was divide all classes into its own header and source file, and I get a massive amount of error. On xcode it says unknown type name ‘Event’.

I tried changing the #ifndef stuff ( sorry I don’t know what it’s called ), but no luck.

Any help would be appreciated, thank you.

David


I’m using xcode, but here’s the error message from Terminal:

In file included from ModemSimV2.h:5,
                 from Event.h:4,
                 from Event.cpp:1:
EventHeap.h:18: error: expected ‘,’ or ‘...’ before ‘&’ token
EventHeap.h:18: error: ISO C++ forbids declaration of ‘Event’ with no type
EventHeap.h:19: error: ISO C++ forbids declaration of ‘Event’ with no type
EventHeap.h:19: error: expected ‘;’ before ‘*’ token
EventHeap.h:23: error: ISO C++ forbids declaration of ‘Event’ with no type
EventHeap.h:23: error: expected ‘;’ before ‘*’ token
In file included from Event.h:4,
                 from EventHeap.h:8,
                 from EventHeap.cpp:1:
ModemSimV2.h:11: error: ‘EventHeap’ has not been declared
ModemSimV2.h:23: error: ISO C++ forbids declaration of ‘EventHeap’ with no type
ModemSimV2.h:23: error: expected ‘;’ before ‘*’ token
EventHeap.cpp: In constructor ‘EventHeap::EventHeap()’:
EventHeap.cpp:6: error: call of overloaded ‘Event()’ is ambiguous
Event.h:10: note: candidates are: Event::Event(int, int)
Event.h:9: note:                 Event::Event()
EventHeap.cpp: In constructor ‘EventHeap::EventHeap(int)’:
EventHeap.cpp:12: error: call of overloaded ‘Event()’ is ambiguous
Event.h:10: note: candidates are: Event::Event(int, int)
Event.h:9: note:                 Event::Event()
EventHeap.cpp: In member function ‘void EventHeap::buildHeap(int)’:
EventHeap.cpp:40: error: call of overloaded ‘Event()’ is ambiguous
Event.h:10: note: candidates are: Event::Event(int, int)
Event.h:9: note:                 Event::Event()

main.cpp:

#include <queue>
#include <vector>
#include <functional>  // for greater()
#include <climits>     // for INT_MAX
#include <iostream>
#include "random.h"
#include "ModemSimV2.h"
#include "Event.h"
#include "EventHeap.h"


using namespace std;

// Simple main to test ModemSim class.
int main( )
{
    int numModems;
    int totalTime;
    double avgConnectTime;
    int dialInFrequency;

    cout << "Enter number of modems, length of simulation,\n"
    << " average connect time, how often calls occur: ";

    cin >> numModems >> totalTime >>
    avgConnectTime >> dialInFrequency;

    EventHeap eHeap( numModems );
    ModemSimV2 s( numModems, avgConnectTime, dialInFrequency, eHeap );
    s.runSim( totalTime );

    return 0;
}

Event.h:

#ifndef EVENT_P2_H
#define EVENT_P2_H

#include "ModemSimV2.h"

class Event{
    //enum { DIAL_IN = 1, HANGUP = 2 };
public:
    Event( );
    Event( int name = 0, int tm = 0 );

    bool operator > ( const Event & rhs ) const;
    bool operator < ( const Event & rhs ) const;
    bool operator <= ( const Event & rhs ) const;
    bool operator != ( const Event & rhs ) const;

    //void process( ModemSimV2 m );

    friend class ModemSimV2;

private:
    int who;        // the number of the user
    int time;       // when the event will occur
    int what;       // DIAL_IN or HANGUP
};

/*
class Dialin : public Event{

public:
    Dialin( );
    void process( ModemSimV2 m );
};*/
#endif

Event.cpp:

#include "Event.h"

Event::Event( ) {

}

Event::Event( int name, int tm )
: time( tm ), who( name ) { 
    return;
}

bool Event::operator > ( const Event & rhs ) const { 
    return time > rhs.time; 
}

bool Event::operator < ( const Event & rhs ) const { 
    return time < rhs.time; 
}

bool Event::operator <= ( const Event & rhs ) const { 
    return time < rhs.time; 
}

bool Event::operator != ( const Event & rhs ) const { 
    return time != rhs.time; 
}

EventHeap.h:

#ifndef BINARY_HEAP_P2_H
#define BINARY_HEAP_P2_H

#include <iostream>
#include <cmath>
#include <vector>

#include "Event.h"

class EventHeap{
public:
    EventHeap( );
    EventHeap( int numIndex );

    bool empty( ) const;
    const int & findMin( ) const;

    void push( const Event & x );
    Event * pop();

private:
    int size;         // Number of elements in heap
    Event *array;            // The heap array

    void buildHeap( int index );
    void reIndex( int hole );
    int getLeft( int index ) const;
    int getRight( int index )const;
    int getParent( int index )const;
};


#endif

EventHeap.cpp:

#include "EventHeap.h"

//Constructor
EventHeap::EventHeap( ) {

    array = new Event[1];
    size = 0;
}

EventHeap::EventHeap( int numVals ) { 

    array = new Event[numVals];
    size = 0;
}

//insert
void EventHeap::push( const Event &e ) {

    array[size] = e;
    reIndex( size );
    size++;
}

//removes the min val   
Event* EventHeap::pop( ) {

    Event *e = &array[0];
    array[0] = array[size - 1];
    size--;
    if( !empty( ) )
        buildHeap(0);

    return e;
}

//re do
void EventHeap::buildHeap( int nodeIndex ) {

    int leftChildIndex, rightChildIndex, minIndex;
    Event tmp;

    leftChildIndex = getLeft(nodeIndex);

    rightChildIndex = getRight(nodeIndex);

    if (rightChildIndex >= size) {

        if (leftChildIndex >= size)

            return;

        else

            minIndex = leftChildIndex;

    } else {

        if (array[leftChildIndex] <= array[rightChildIndex])

            minIndex = leftChildIndex;

        else

            minIndex = rightChildIndex;

    }

    if (array[nodeIndex] > array[minIndex]) {

        tmp = array[minIndex];

        array[minIndex] = array[nodeIndex];

        array[nodeIndex] = tmp;

        buildHeap(minIndex);

    }
}


//re index
void EventHeap::reIndex( int hole ) {

    while( array[hole] != NULL && array[hole] <  array[getParent( hole )] ) {
        int pIndex = getParent( hole );
        Event temp( array[hole] );
        array[hole] = array[pIndex];
        array[pIndex] = temp;
        hole = pIndex;
    }
}

//is Empty
bool EventHeap::empty() const {
    return ( size == 0 );
}

int EventHeap::getLeft( int index ) const {
    return ( index * 2 ) + 1;
}

int EventHeap::getRight( int index ) const {
    return ( index * 2 ) + 2;
}

int EventHeap::getParent( int index ) const {
    return ( index - 1 ) / 2;
}

ModemSimV2.h

#ifndef MODEM_SIM_V2_H
#define MODEM_SIM_V2_H

#include "Event.h"
#include "EventHeap.h"
#include "random.h"


class ModemSimV2{
public:
    ModemSimV2( int modems, double avgLen, int callIntrvl, EventHeap e );
    // Add a call to eventSet at the current time,
    // and schedule one for delta in the future.
    void nextCall( int delta );

    // Run the simulation
    void runSim( int stoppingTime );// = INT_MAX );

    // friend class Event;

private:
    Random r;                       // A random source
    EventHeap *eventSet;                    // Pending events

    // Basic parameters of the simulation
    int freeModems;                 // Number of modems unused
    const double avgCallLen;        // Length of a call
    const int freqOfCalls;          // Interval between calls
};

#endif

ModemSimV2.cpp

#include "ModemSimV2.h"

// Constructor for ModemSim.
ModemSimV2::ModemSimV2( int modems, double avgLen, int callIntrvl, EventHeap e )
: freeModems( modems ), avgCallLen( avgLen ),
freqOfCalls( callIntrvl ), r( (int) time( 0 ) )
{
    eventSet = &e;
    nextCall( freqOfCalls );  // Schedule first call
}

// Place a new DIAL_IN event into the event queue.
// Then advance the time when next DIAL_IN event will occur.
// In practice, we would use a random number to set the time.
void ModemSimV2::nextCall( int delta ){
    static int nextCallTime = 0;
    static int userNum = 0;

    eventSet->push( Event( userNum++, nextCallTime ) );
    nextCallTime += delta;
}

// Run the simulation until stopping time occurs.
void ModemSimV2::runSim( int stoppingTime ){
    Event *e;

    while( !eventSet->empty( ) ){
        e = eventSet->pop();
        if ( e->time > stoppingTime )
            break;
        //e->process( this );
        nextCall( freqOfCalls );
    }
}
  • 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-01T19:15:31+00:00Added an answer on June 1, 2026 at 7:15 pm

    Event.h includes ModemSimV2.h. ModemSimV2.h includes Event.h. That’s not going to work without a little help.

    You should read up on forward declarations. See this StackOverflow question for more information.

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

Sidebar

Related Questions

ok so this is the assignment that I'm working on: Implement a class Student
A homework assignment asks me to implement a program that counts the words in
I am working on an assignment that asks me to implement an AVL tree.
The assignment at my first year uni computing course says my program should read
I'm working on a homework assignment where we are asked to implement an evaluation
So for my assignment, I am supposed to implement a Node class that just
I have an assignment that requires us to implement a doubly linked list class.
I'm working on C programming assignment to implement Sieve of Eratosthenes without using the
I am currently working on a programming assignment. The assignment is to implement a
I have an assignment that I'm supposed to implement the MIPS processor in C++

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.