473,382 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Student needs assistance... (deperately)

I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).

I have the following header file for my memory manager:
<code>
#ifndef MemManager_h
#define MemManager_h

#include <cstdlib>

class MemManager
{
public:
// Constructor
//
// Input : None
// Purpose: To create an empty MemManager
// Output : None

MemManager ( );
// Copy constructor
//
// Input : MemManager M
// Purpose: To initialize MemManager to M
// Output : None

MemManager ( const MemManager & M );

// Copy assignment
//
// Input : MemManager M
// Purpose: To assign Rhs to current MemManager
// Output : Current MemManager

const MemManager & operator= ( const MemManager & M );
// Destructor
//
// Input : None
// Purpose: To free memory of MemManager
// Output : None

~MemManager ( );
// Clear
//
// Input : None
// Purpose: To re-initialize MemManager to empty
// Output : None

void Clear ( );

//
// Input : None
// Purpose: To delete the top element of MemManager
// Output : 1 if successful; 0 otherwise
// Notes: Only used to clear the linked list for this class

int Pop ( );
// Empty
//
// Input : None
// Purpose: To check if MemManager is empty
// Output : 1 if empty; 0 otherwise

int Empty ( ) const;

/************************************************** ***
Allocate

Inputs: int Pages
Output: int Starting Page

Notes: Takes in the number of pages needed by a job
Outputs the starting page for the job in memory
returns -1 if there is not enough memory for the
job.
************************************************** *******/
int Allocate(int N);

/************************************************** ***********
GetNumPages

Inputs: None
Outputs: Pages

Notes: Returns the number of pages in the current
MemNode's block
type.
************************************************** ***********/
int GetNumPages(MemNode & MN);

/************************************************** ************
GetFirstPage

Inputs: None
Outputs: Page

Notes: Returns the first available memory page from the
current
MemNode's blockType.

************************************************** ******************/
//int GetFirstPage(MemNode & MN) const;

private:

typedef struct BlockType
{
int firstPage;
int numberPages;

//Constructor
BlockType() : firstPage(0), numberPages(59)
{}

//I am not sure that I should ALLOW this since we are
to be
// limited to 60 pages... I left it in...
BlockType(int f, int n) : firstPage(f), numberPages(n)
{}

}BlockType;

struct MemNode
{
BlockType Element;
MemNode *Next, *Previous;

// StackNode constructors
MemNode ( ) : Next ( NULL )
{}
MemNode ( const BlockType & E, MemNode *P = NULL ) :
Element ( E ), Next ( P )
{ }
};

// Pointer to the top of Stack
MemNode *Top;
int NumNodes;

};

#endif

</code>

In the private section I have a typedef (I know this C not C++ but I
cannot compile if I don't use the type def...)

I have a typedef of 'BlockType'. I am supposed to keep this Private
(requirement of the assignment) and I need to access the properties of
the BlockType: firstPage and numberPages (meaning the first available
page of memory and the number of pages available respectively.

I declare the following function:
int GetNumPages(MemNode & MN);

I get the non-sensical error of: expected `;' before '(' token

If I comment out the line the error goes away and it will compile. This
tells me there are no semi-colons missing on the lines above. The error
does not however point to any error that I can see to fix.

I am down to the crunch and I am stumped.

It would work fine (I think) if I moved the code into a seperate class
but the prof has specified that he does not want us to do that.

I however cannot figure out how to get access to those values. (Ant the
error does not help since the compiler is obviously confused.)

PLEASE HELP.

Thanks.

Oct 9 '06 #1
5 1657

sa***@murdocks.on.ca wrote:
I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).

I have the following header file for my memory manager:
I have trimmed out the comments fom your code to (hopefully) better
illustrate the problem.
<code>
#ifndef MemManager_h
#define MemManager_h

#include <cstdlib>

class MemManager
{
public:
MemManager ( );
MemManager ( const MemManager & M );
const MemManager & operator= ( const MemManager & M );
~MemManager ( );
void Clear ( );
int Pop ( );
int Empty ( ) const;
int Allocate(int N);
This is your problem line.
int GetNumPages(MemNode & MN);
private:

typedef struct BlockType
{
<snip>
}BlockType;

struct MemNode
{
<snip>
};
MemNode *Top;
int NumNodes;
};

#endif

</code>
The compiler reads your code starting at the top and working towards
the bottom. When it reaches your problem line

int GetNumPages(MemNode & MN);

it's going to have trouble knowing what that means if it doesn't know
what MemNode is. And your definition of MemNode doesn't appear until
later.

Do you know about forward declarations? Alternatively, are you aware
that the public, protectected and private parts of a class do not need
to be declared in that order and that you can, for example, have a
private section followed by a public section followed by another
private section?

You said you got the error
expected `;' before '(' token

I don't know what compiler you are using, but Comeau online does a
better job of diagnosing the problem. It says
error: identifier "MemNode" is undefined

Sometimes compilers are like that. Making the intuitive link between
what the compiler says and what is actually wrong can be a bit of an
art.

<snip>

Gavin Deane

Oct 9 '06 #2
Thank you!

I have now got a private section, public section, private section.

I had no idea you could do that.

I don't know what forward declarations are, but they are now my list of
things to read about.

Thanks again.

FYI: It was recommended that I use Dev C++ by bloodshed so that is what
I use. That way I can hand in the whole project with the assignment and
they can either just run it, or complile it as they see fit.

Gavin Deane wrote:
sa***@murdocks.on.ca wrote:
I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).

I have the following header file for my memory manager:

I have trimmed out the comments fom your code to (hopefully) better
illustrate the problem.
<code>
#ifndef MemManager_h
#define MemManager_h

#include <cstdlib>

class MemManager
{
public:
MemManager ( );
MemManager ( const MemManager & M );
const MemManager & operator= ( const MemManager & M );
~MemManager ( );
void Clear ( );
int Pop ( );
int Empty ( ) const;
int Allocate(int N);

This is your problem line.
int GetNumPages(MemNode & MN);
private:

typedef struct BlockType
{

<snip>
}BlockType;

struct MemNode
{

<snip>
};
MemNode *Top;
int NumNodes;
};

#endif

</code>

The compiler reads your code starting at the top and working towards
the bottom. When it reaches your problem line

int GetNumPages(MemNode & MN);

it's going to have trouble knowing what that means if it doesn't know
what MemNode is. And your definition of MemNode doesn't appear until
later.

Do you know about forward declarations? Alternatively, are you aware
that the public, protectected and private parts of a class do not need
to be declared in that order and that you can, for example, have a
private section followed by a public section followed by another
private section?

You said you got the error
expected `;' before '(' token

I don't know what compiler you are using, but Comeau online does a
better job of diagnosing the problem. It says
error: identifier "MemNode" is undefined

Sometimes compilers are like that. Making the intuitive link between
what the compiler says and what is actually wrong can be a bit of an
art.

<snip>

Gavin Deane
Oct 9 '06 #3
****

Sorry I spoke too soon.

It compiled because in my debugging I had commented out the function.

It didn't compile. I am still looking at the issue.
Gavin Deane wrote:
sa***@murdocks.on.ca wrote:
I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).

I have the following header file for my memory manager:

I have trimmed out the comments fom your code to (hopefully) better
illustrate the problem.
<code>
#ifndef MemManager_h
#define MemManager_h

#include <cstdlib>

class MemManager
{
public:
MemManager ( );
MemManager ( const MemManager & M );
const MemManager & operator= ( const MemManager & M );
~MemManager ( );
void Clear ( );
int Pop ( );
int Empty ( ) const;
int Allocate(int N);

This is your problem line.
int GetNumPages(MemNode & MN);
private:

typedef struct BlockType
{

<snip>
}BlockType;

struct MemNode
{

<snip>
};
MemNode *Top;
int NumNodes;
};

#endif

</code>

The compiler reads your code starting at the top and working towards
the bottom. When it reaches your problem line

int GetNumPages(MemNode & MN);

it's going to have trouble knowing what that means if it doesn't know
what MemNode is. And your definition of MemNode doesn't appear until
later.

Do you know about forward declarations? Alternatively, are you aware
that the public, protectected and private parts of a class do not need
to be declared in that order and that you can, for example, have a
private section followed by a public section followed by another
private section?

You said you got the error
expected `;' before '(' token

I don't know what compiler you are using, but Comeau online does a
better job of diagnosing the problem. It says
error: identifier "MemNode" is undefined

Sometimes compilers are like that. Making the intuitive link between
what the compiler says and what is actually wrong can be a bit of an
art.

<snip>

Gavin Deane
Oct 9 '06 #4
Got it now.

Thanks again.
sa***@murdocks.on.ca wrote:
****

Sorry I spoke too soon.

It compiled because in my debugging I had commented out the function.

It didn't compile. I am still looking at the issue.
Gavin Deane wrote:
sa***@murdocks.on.ca wrote:
I am a student with an assignement due tomorrow. I am to write a sort
of a memory manager, I don't want to go into all of the details (it's
long).
>
I have the following header file for my memory manager:
I have trimmed out the comments fom your code to (hopefully) better
illustrate the problem.
<code>
#ifndef MemManager_h
#define MemManager_h
>
#include <cstdlib>
>
class MemManager
{
public:
MemManager ( );
MemManager ( const MemManager & M );
const MemManager & operator= ( const MemManager & M );
~MemManager ( );
void Clear ( );
int Pop ( );
int Empty ( ) const;
int Allocate(int N);
This is your problem line.
int GetNumPages(MemNode & MN);
private:
>
typedef struct BlockType
{
<snip>
}BlockType;
>
struct MemNode
{
<snip>
};
MemNode *Top;
int NumNodes;
};
>
#endif
>
</code>
The compiler reads your code starting at the top and working towards
the bottom. When it reaches your problem line

int GetNumPages(MemNode & MN);

it's going to have trouble knowing what that means if it doesn't know
what MemNode is. And your definition of MemNode doesn't appear until
later.

Do you know about forward declarations? Alternatively, are you aware
that the public, protectected and private parts of a class do not need
to be declared in that order and that you can, for example, have a
private section followed by a public section followed by another
private section?

You said you got the error
expected `;' before '(' token

I don't know what compiler you are using, but Comeau online does a
better job of diagnosing the problem. It says
error: identifier "MemNode" is undefined

Sometimes compilers are like that. Making the intuitive link between
what the compiler says and what is actually wrong can be a bit of an
art.

<snip>

Gavin Deane
Oct 9 '06 #5

sa***@murdocks.on.ca wrote:
****

Sorry I spoke too soon.

It compiled because in my debugging I had commented out the function.

It didn't compile. I am still looking at the issue.

Re-arrange your class, put the private section before the public
section.

Oct 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mojo | last post by:
Ok, I don't want to much help but I need a push. I am supposed to write a program with 3 classes: 1. Controlling class 2. Student class 3. Grades class Controlling class instantiates a student...
16
by: Kirk Bevins | last post by:
Hello, new to posting, got a dilema in c++. I cant seem to create new instances of my student class. The idea is to make a database where the user inputs surnames and library card numbers etc. The...
5
by: Bob Alston | last post by:
I am looking for any Microsoft Access based software that could be used for a United Way agency that provides basic needs assistance - food, clothing, financial (rent, utilities, Rx, gasoline,...
2
by: Anderson | last post by:
Does anyone have a sample student record system in access. Or would you point me somewhere where I can get examples. many thanks. Andy
1
by: Student | last post by:
Hey I need to write an application that will scan my network, explicitly my network group. So it needs to do something like a "nbtscan" (you give it a parameter like 192.168.0.0/24 and it gives you...
0
by: michael horthum | last post by:
- i am not a beginner, books, or online tutorials don't help, please save your advises- i want to learn c# from someone who knows it well. concepts and fundamentals i currently have (gdi+,...
10
by: sandy | last post by:
I have been given a class, stack to work with. I have created a class called Job that I want to push on the stack. I cannot seem to figure out why the push isn't working. (I know the stack...
6
by: sandy | last post by:
I am working on an assignment which is a 'discrete event simulation'. I have a class called event, I need to add it to a priority queue and I cannot for some reason. I am sure it's the syntax... ...
0
by: Racqetsports | last post by:
Hi there, In a gradebook database, student grades must be computed from 2 scores: a Daily grade, and then scores from Assignments. Knowing about nested forms, I am requesting direction on how to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.