Welcome! Log In Create A New Profile

Advanced

Assignment 3

Posted by Icebabe 
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
avatar Re: Assignment 3
July 07, 2006 08:11AM
None of these ideas are mine. I got them from reading books. If you want to learn how to write better code (in any language) I hightly recommend Code Complete 2 by Steve McConnell (ISBN 0-7356-1967-0) I've seen a copy in the library in Pretoria but when I went there last time, nobody had ever taken it out.

I've found it one of the most helpful and enlightening books I've ever read. It has examples mainly in C/C++, Java, C# and VB but a few also in Cobol, Ada and Pascal.
avatar Re: Assignment 3
July 07, 2006 02:40PM
Cool, will keep an eye out for them.

-Valkeye
Re: Assignment 3
July 11, 2006 08:45AM
Dear Valkeye and robanaurochs

In the declaration of your enum variables(This is also known as aliases or programmer defined objects)It basically allows you to declare your own objects or assign an alias to those variables to like u say get rid of the literals. Your code thow does not assign any aliases to any literals so how do you expect to compute making reference to months. Maybe you know something I do not?

And Valkeye I see you have been busy in my absence!! I am so busy with my other modules I do not have time for this one I completed the whole asignment last night without going through the chapters partianing to this assignment properly. I also ran into structs for the first time last night. O ja enums comes from COS112V. You will get to know more about that next year, when you do COS112V.
Re: Assignment 3
July 11, 2006 03:03PM
HI ALL....PLEASE COULD SOMEONE E-MAIL ME OR PASTE THE ENTIRE ASSIGNMENT 3 HERE AS I NEED TO STUDY FROM SOME GOOD ANSWERS. MY WIFE AND I WILL TAKE YOU FOR SUPPER IN RETURN smiling smiley

MY E-MAIL IS tnurick@mailbox.co.za

Thanks smiling smiley
avatar Re: Assignment 3
July 11, 2006 04:04PM
HI Brendonw,

How did you find the assignment. I also left it for the last minute only to find that my book had a duplicate of chapters 28 and no chapter 29 and 30. But it wasn't too hard. I've dealt a bit with enums before, not in depth, but if my memory server me correctly they are similar to structs, but only take up the amount of RAM of the largest object type in the enum..

Hi Computergeek,

When the assignments come back, maybe we can start a thread examining all the assignment questions and answers, getting everyone's input. Feel a bit dodge just mailing or posting my assignment.

-Valkeye
Re: Assignment 3
July 11, 2006 04:14PM
Valkeye

Your claim to say that it is almost like structs is not far off. Wait till you get to learn about class objects then it becomes really interesting. Assignment 3 was a breaze, it is all because of my COS112V exposure.

avatar Re: Assignment 3
July 11, 2006 04:23PM
Yeah.. Well at the moment I've been riding off of all my Java exposure and have probably only devoted just over a week to the subject on a whole. smiling smiley But I'm pretty sure that the ride will stop soon enough and some serious hair pulling will start.

-Valkeye
avatar Re: Assignment 3
July 11, 2006 07:15PM
Brendonw

You are correct that aliases (or to use the C++ term, references) are indeed a way to avoid incurring extra memory cost by having two names address the same variable.

To all who have been following, I'm sorry for introducing enums when I should have just used ordinary constants.

It is incorrect to say that enums are similar to structs or classes. Their form is similar but their function is waaaaaaay different. Structs, classes (and another concept called a union) are the only things that can contain groups of variables and are used to logically arrange your data and functions. Structs are inherited from C and classes were introduced when C++ was invented. You don't need to know any more about that until COS112.

enums, on the other hand are ways of replacing numerical values with names when names mean more than their numerical values. Computers function best with numbers. Humans function best with words. For example, say you want to have a card game and need to have a variables track the suit and value of each card. Obviously, you'd keep the value as an integer but to give the suit a value is rather meaningless (what is the value of a Heart compared with a Diamond?). The answer is to use an enum.

enum Suit {Hearts, Diamonds, Clubs, Spades};

struct Card
  {
  int faceValue;
  Suit cardSuit;
  };
Using enums also has the advantage in that you are restricted on what values you can assign to the variable. You can only assign the names that are defined in the list, and no other. The compiler gives each of the different elements in the list an integral value, starting at 0, and increases that value by 1 for each item in the enum list unless a value is explicitly defined by the programmer. In the above example, Hearts == 0, Diamonds == 1, Clubs == 2, and Spades == 3. Note that if you create a variable of an enum, you can only assign it the names, you cannot assign the values.

Suit cardSuit;
cardSuit = 0; // invalid, not allowed to assign a numerical value
cardSuit = Diamonds; // correct, using an element from the enum list

Note also, that you can convert enum values back to ordinary integral values. This allows you to use them in switch statements, and for loops. Note that in for loops, you should use an int as the control variable because you can't increment an enum variable (unless you overload the ++ operator and have some fancy programming inside) but you can increment the int and compare it's value to that of one of the names in the enum list.

Note: this might seem like a whole new concept but you've been using a built-in enum for quite a while now. It's defined inside the C++ compiler so you won't find it defined in any of the library headers but you can imagine that it would be defined like:
enum bool {false, true};

You can create bool variables and only assign to them the names "false" and "true". Even though false == 0, you cannot assign 0 to a bool variable and likewise with true, which has the value 1.

Sometimes the values that are assigned to the enum elements are meaningless to humans - like the card suits example above or like
enum Direction {South, East, North, West};

but sometimes the values do mean something. In this case, you'd assign the values yourself and not let the compiler do it for you. (Note that hexidecimal numbers are written in C++ with 0x in front of them)
enum Colours {Red = 0xFF0000, Green = 0x00FF00, Blue = 0x0000FF, 
             Magenta = 0xFF00FF, Cyan = 0x00FFFF, Yellow = 0xFFFF00,
             // I won't carry on, you get the point
             };

Now you don't need to remember the actual colour values, you can use the colour names instead.

All that said about enums, they're still treated as constants and are converted during compilation into literals - see my previous post with the disassembly - so they're another way of documenting your code and making it easier to read.
Re: Assignment 3
July 11, 2006 08:49PM
vALKEYE,,,...

Please dude.....as you have a good understanding of this work I'd like to learn from someone who knows whats happening.

I know that the best way for me to learn and understand this work is for me to go through someone who knows assignment.

If you really dont want to e-mail it to me then its fine but if you do then it would be much appreciated.

my e-mail is tnurick@mailbox.co.za , just incase you are feeling kind smiling smiley

Re: Assignment 3
July 16, 2006 12:27PM
Hi Valkeye

I have completed Assignment 3 , thanks to some help on the forum. One or two of my questions aren't compiling though. Can I mail then to you for assistance?

Thanks
avatar Re: Assignment 3
July 16, 2006 01:21PM
Hi,

Sure, if you want to mail them you can. valkeye@gmail.com. You could also post them here so others can benefit if you want. But if you do that remember to use the code tags. [xxxx] and [/xxxx] where xxxx = code.

-Valkeye
Re: Assignment 3
July 16, 2006 04:14PM
Hi Valkeye , I sent you a mail.

Some of my questions had problems compiling so I thought i'd rather mail them to you directly.

Thanks

-Whizza
Re: Assignment 3
July 17, 2006 07:41AM
I finally got this one done. I had to rely on an extension. With increased work pressure I find myself constantly 2-3 weeks behind on everything.
Structs was easy to grasp and working with an array of structs has helped me with another project where I'm working with an array of classes.
This was one assignment that I actually enjoyed.
Cheers,
AndreB
Re: Assignment 3
July 17, 2006 08:56AM
Don't worry AndreB you are not alone!

I've been behind 2-3 weeks aswell with most of my Assignments. In real sh*t with COS114X as I don't have enough credits yet and assignment due dates nearly over. I have 8 Modules this year (Finished 2 in May/June) and i'm constantly travelling with my new job. Going to Mauritius again tomorrow for the week.

This forum is great though as it's comforting to know there are others in the same boat! grinning smiley

-Whizza[/img]
Re: Assignment 3
July 17, 2006 05:10PM
Hi Whizza
Enjoy the trip to Mauritius.
I've taken 7 modules this year, and unfortunately travel quite a bit as well. I've got 2 trips within the next 2 weeks. Sometimes the traveling helps, as you can lock yourself in a hotel room and work all night, but sometimes it's just the opposite.

Good luck
AndreB
Sorry, only registered users may post in this forum.

Click here to login