Welcome! Log In Create A New Profile


Software included on CD

Posted by ShaunGVW 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Software included on CD
February 22, 2006 01:12PM
I installed the C++ compiler and IDE as explained on the disk, and got the program working. Problem is my console window doesn't remain open, even though the checkbox under Environment options is ticked to keep the window open. All "Include" directories appear correct. Anyone got any suggestions?

Shaun van Wyngaard
Re: Software included on CD
February 22, 2006 02:20PM

One of the issue may be that your code is kept in a folder that's name has spaces in it. Try moving your code or editing the folder name to exclude space (white space).

Alternativaly try Sleep();

int main (){


return 0;

Hope it helps
Re: Software included on CD
February 22, 2006 02:35PM
Thanks Jaceus

Will try it tonight when I get home. I know that I do have spaces in the directory names. What is the reason for this? When I run the program in another program (Borland C IDE), it runs fine.

Re: Software included on CD
February 22, 2006 02:45PM

Apparently there is a glitch in the Mingw compiler. I haven't read much about this only that it may be one of the reasons for your problem. good hearing from fellow students

Good luck with the studies.

Re: Software included on CD
February 22, 2006 07:20PM
I used somethign other than what Jaques used, uhm ,let me jsut find it

system("pause"winking smiley;

that also helps.
Re: Software included on CD
February 23, 2006 06:53AM

I deleted all spaces from my directories, and all works fine now. (Thanks to Jacques for this). I was so encouraged, I even attempted Ass 1 Q5 (with little success). I can't say too much for the compiler error messages. Not very descriptive. It seems to give single word messages!

Regarding Q5, are we supposed to create a header file, implementation file, and the main calling program? I am not trying to get free answers here, it is just that I did Delphi in first year, not C++ (I haven't studied for a while now!). Also, is the struct supposed to contain any functions, because I only have variables (1 word, and the pointer as per the question), which I have declared as public, but in my main calling program, it doesn't seem to allow me to declare "fat new Adjective"


avatar Re: Software included on CD
February 25, 2006 12:45PM
Hi Shaun

If you have any problems with understanding error messages, just post them and maybe somebody will be able to explain them. Not me, I don't use MinGW, sorry. If you post your code, then maybe help can be given that way.

If you've never programmed in C/C++/Java/C# then the code will seem a little odd. At least this years textbook is a little more structured than last year's.

As far as Q5, I don't think the programme is big enough to warrant splitting it into different files. That technique's only to organise yourself better and make it easier to maintain the code and find things.

You must use a struct and the instructions tell you to only use variables - word (of the type string) and antonymPtr (a pointer to Adjective objects). You don't need any functions.

[Rememeber that structs have public access by default so you don't need to explicitly state that]

I don't know what you mean by "declare 'fat new Adjective'"?. The question is specific in that you must use the adjPtr variable to hold the address of the first object in the heap memory.

Adjective *adjPtr = new Adjective;
adjPtr->word = "fat";

That should start you off. I would suggest following the hint in the question otherwise your code will look WAY too complicated. If you don't use another pointer variable, the last link will have to be made like this:

adjPtr->antonymPtr->antonumPtr = adjPtr;

Good luck this year.

Re: Software included on CD
February 27, 2006 10:30AM
Thanks Rob.

I was getting a bit mixed up in what I was trying. I was going to create 2 pointers called fat and thin, then put "fat" and "thin" into their info, and get their links to point to each other, and then also make another pointer to point to fat. I misunderstood what was required. I now understand to use the pointer *adjPtr and point it to fat, and then again using it to get fat to point to thin and back to fat again. (or something like that!)

avatar Re: Software included on CD
February 27, 2006 01:39PM
As soon as you get a question that needs pointers you should be thinking about the heap (or dynamic) memory.

Data stored in stack(or static) memory is automatically created and destroyed and is accessed by variables you define in your code. Data stored in heap memory is allocated and deallocated by the programmer and is accessible only by using pointers. The pointer variables, being variables are located on the stack but contain a numerical address to the location where the object on the heap was allocated.

To use an analogy, you can imagine a harbour full of boats docked at a pier. The water represents the heap, the boats represent your data and the ropes holding the boat to the pier are the pointers.

Be careful, though, if you accidentally let go of the rope (i.e. change the value of the pointer) you lose your boat for good. The boat still exists but you can't access it or destroy it to make room for new boats. This is called a memory leak and for this reason you should always have an equal number of deletes for every new.

Another thing, always initialise your pointer variables. If you don't have any data to point to at the time of the definition, then make the pointer a null (or empty) pointer by setting the value to zero.

Type *typePtr = 0;

Just like ordinary variables, the initial value is whatever junk was in that space of memory at the time. If the pointer points to a part of the heap that has not been allocated (i.e. no new statement) and you try and delete it,

Type *typePtr; // warning: no initial value
delete typePtr; // runtime error - this will crash your programme

you will effectively be trying to dealocate memory you never had in the first place. This is the easiest way to crash your programme. Try at your own risk. delete ignores null pointers (i.e. pointers that point to memory address 0x00000000).

Getting back to the question, the "fat" and "thin" are string data not variable names. The only variable name given is adjPtr so this is the only one on the stack. The object for "fat" and the one for "thin" are to be created on the heap memory. To go back to the harbour analogy, your rope is the adjPtr variable and you must create a "boat" at the end of that rope and assign "fat" to it. Then you must create another "boat", give it the word "thin" and then attach it to the back of the "fat" boat using the rope at the back. Once you've got that done correctly, just take the rope at the back of the "thin" boat and attach it to the "fat" one.

[I think this analogy is getting a bit stretched, hmm]

There are two ways of creating the second Adjective: a clean way(using two variables) and an ugly way(only using adjPtr).

The ugly way:

adjPtr->antonymPtr = new Adjective;
adjPtr->antonymPtr->word = "thin";

The clean way:

Adjective *thinPtr = new Adjective;
thinPtr->word = "thin";
adjPtr->antonymPtr = thinPtr;

You might ask why I say the second way is cleaner than the first if there's more code involved. Just remember that in the professional environment, if a change needs to be made to some code (say, for a new version) and somebody else is given the job, the worst thing is to have that person scratching his/her head trying to figure out what you've done. Always try and make your code as easy to read as possible. The second code snippet, although a bit longer, is easier to read than the first and it's also easier to make the final link.

This post has become way too long but I hope that some people might find it helpful.

Sorry, only registered users may post in this forum.

Click here to login