Welcome! Log In Create A New Profile

Advanced

Assignment 2 countdown

Posted by valkeye 
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 Assignment 2 countdown
May 09, 2006 02:36PM
Hey All,

So, everybody should be about finished with assignment 2. How'd you all find it?

-Valkeye
Mel
Re: Assignment 2 countdown
May 09, 2006 02:42PM
At first scan over, it seemed quite tough, but once I got into it, it was actually pretty straight-forward. I think I will do well! I submitetd mine on Monday. Someone in the forum mentioned adding an if statement to the dream question to make sure an error wasn't returned if there were no people in that group, which I didn't think about!
avatar Re: Assignment 2 countdown
May 09, 2006 02:49PM
I think the assignment was quite straight forward, the only question which made me think carefully at first glance was the last one. But after reading through it, I didn't think it was too bad.

-Valkeye
Mel
Re: Assignment 2 countdown
May 09, 2006 02:51PM
I think it helped they way they broke the questions down into smaller problems - I agree, the last question did look quite daunting on first glance!
Re: Assignment 2 countdown
May 11, 2006 08:46AM
Hi All....

I have completed the assignement but to be exactly honest Im still not 100% sure as to when you use a return statement, a void value and a void reference parameter. Please would somebody clarify this all with me.
avatar Re: Assignment 2 countdown
May 11, 2006 11:08AM
Hi Computergeek,

the way I see it, you have 3 options:

void function, value returning function and a function with reference paramaters.

I would use a void function when I want to perform a task that has no effect on any of my variables, EVEN THOUGH the function may have variables as parameters.

eg.

//This function draws 10 stars to the console
void drawStars(){
cout << "**********" << endl;
}

In this function there is absolutely no effect on any variables in my program. There is no need to return any values therefore making the return type void. Also, the function doesn't need to know how many stars to draw, it is a fixed number, 10, therefore the parameter list is empty.

Because this function has a return statement of void (nothing), you don't need a return statement.

//This function draws a number of stars to the console
void drawStars(int num){
for(int i = 0; i < num; i++)
cout << '*';
cout << endl;
}

Once again, there is no effect on any variable, although a variable is needed to determine the number of stars to draw. This is also void, returns nothing.

So, use void functions when you don't need to get anything back from the function.

Now, the next question is when to use a value returning function as opposed to a void function with reference parameters.

If I wanted to add two numbers then I would use a value returning function.

int addNums(int a, int b){
return a+b;
}

Now it is possible to do this very thing using a reference parameter, eg:

void addNums(int &a, int b){
a += b;
}

But this is bad!! Even though it works, you now have lost your origional value of a. Whereas in the first example you leave both a and b alone and assign the result of the addition to the variable in the function which called the addNums function. (In the first example we did not create a seperate variable and assign a value to it).

I hope you're still with me here. This may be jumping ahead but this is what a refernce parameter actually is.

A normal variable has a portion of memory assigned to it, and each time you create a new variable, more RAM is assigned. What happens with a refernce parameter is the actuall value of the RAM location holding the variable is changed. This is known in C++ as "Changing the outside object".

Lastly, I would use a void function with reference parameters when I specifically want to do something to the variable I use in the parameter list.

eg.
//This function increments a number
void incNum(int &num){
num++;
}

Here, I don't care about the origional value of the parameter, I want to increment it. There are many different applications when programming where you will like to use this technique.

I hope I've answered your question satisfactionally. I'm at work so I can't really think my post through, so it may be a bit disjointed. If you want a bit more help on stuff mail me at valkeye@gmail.com

-Valkeye
Re: Assignment 2 countdown
May 11, 2006 11:10AM
Hi Guys

I spend to much time on Question 5, only because I could not make up my mind about using a float value or an int value to display average. Although we all know that average will almost always result in a float value. Mel, in regard with your comment about number of people, it refers to the division by zero error that will result when you compute Number of Games divided by number of people. So we just make sure that we compute if the condition holds for Number of people > 0 in question 5 I think.

Mel
Re: Assignment 2 countdown
May 11, 2006 12:11PM
I think in this question it depends on how accurate you want your answer to be. The way I saw it was that a float value would be acceptable, because someone can be a fraction of a year old. I thought if would be better to use a float value for accuracy.

About the zero error, I understood that, I just meant that I hadn't thought about that until someone mentioned it! I'll have to remember that for future...

Re: Assignment 2 countdown
May 11, 2006 04:56PM
To jump in on ComputerGeek and Valkeye's conversation regarding return values vs ref parameters.
If you only need 1 value then use a function that returns a value.
Remember that a value returning function can only return a single value, thus if you need to change, initialize or compute more than one value then you have to use reference parameters.
Obviously are not limited to using reference parameters in void functions only. You can have a function that computes and returns a value as well as modifies the values of 1 or several of its parameters that have been passed by reference.
Remember that when passing a reference param to a function, you actually send the memory address of the variable to the function, the function will will modify the value stored at that specific memory address / location.

Have fun
Re: Assignment 2 countdown
May 11, 2006 08:19PM
Hi everyone!

This assignment did give me some gray hairs, I must admit.

Well...

All the questions were very straight forward, except, things did not work out too well with question 5. (And I was too lazy to do the Question 1, lol)

I just couldn't get the part right where the user enters X and the values are displayed. Everytime I enterd X, nothing apeared on the screen and I got a error message.

Question 6 went well though.

Re: Assignment 2 countdown
May 16, 2006 04:10PM
Thanks Valkeye and AndreB,

I do understand but not 100%,,,I guess I'd just need some more practice at it.
Re: Assignment 2 countdown
May 17, 2006 01:54PM
Hi guys, are anyone of you registered for COS112V it also uses C++ as the course language, but I tell you if COS111U is standard grade then COS112V is the Higher Grade Equivalent of COS111U. valkeye and Mel if you guys are not registered for COS112V would you like to receive code on COS112V anyway just to look at. I had a look in the COS112V forum and can not find students with your capabilities for feedback.

Mel
Re: Assignment 2 countdown
May 17, 2006 02:10PM
Thanks Bendon that woud be great. I wanted to do COS112 this year, but I thought I should probably do COS111 first. How are you finding doing them concurrently?
Re: Assignment 2 countdown
May 17, 2006 02:24PM
COS111U AND COS112V uses the same textbook, but COS111U tries to teach you or introduce you to programming. But COS112V expect you to be fluent in a langauge and it uses the EZWIN Library to display results. It teaches you to make use of not only multiple function programming only, but also multiple files and header files. The use of multiple file compiling exposes you to a more dinamic way of compiling and executing code. Just work through your textbook, I know you do not actually need it for COS111U, but if you understand the excercises in the textbook you will understand COS112V easily.
avatar Re: Assignment 2 countdown
May 17, 2006 03:00PM
Hey Brendonw,

I'd love to check out some of your code, I'm only gonna do 112V next year. I've got the text book, but to be honest I haven't even looked at it yet, esp. seeing that all the feedback I've had on it has been VERY negative.

Mail me on valkeye@gmail.com.

If you're interested in finding a really brilliant resource you should try going through Bruce Eckel's Thinking in C++. It's free and I am finding it really good. The depth it goes into is amazing. Give it a try.

-Valkeye
Re: Assignment 2 countdown
May 17, 2006 03:08PM
I will keep you guys posted. What other subjects are you guys registered for. I have INF109, INF120, COS114, COS113, COS111, COS112, STS105. I have managed thus far, looks like if I will make it. I have a very relaxed job. You can say I am studying full time and working full time.
Re: Assignment 2 countdown
May 17, 2006 04:30PM
Hi Brendon,,,lucky for you. Im battling studying at nights. I onlky have three courses...how are you finding Cos113 ??
avatar Re: Assignment 2 countdown
May 17, 2006 10:04PM
Yeah.. I'm doing COS111U, COS113W, COS101S, OPS101G, OPS102H and CEM101A. I work fulltime and have evening commitments most evenings as well. So it's like trying to study between events. I'm able to commit about 10hours a week for everything.

-Valkeye
Re: Assignment 2 countdown
May 18, 2006 08:41AM
Hi computergeek COS113 is the least of my worries, I got a 93% in my first assignment. At this stage in the game I am more worried about time versus volume management. Today, I am handing in an assignment, 2 days late for INF109 also one of my easier subjects. I see a patern forming here I am neglecting COS113, INF109, INF120 "the easier subjects" and this is why I am handing INF109 in late. I just came from a battle with ass2 for COS112V.

valkeye and Mel, look at this tool the next time you want to save some time programming. Develop a header file and include all your favourite libraries in it. The next time you code you call just this one header file instead of #include <iostream>...

Create a header file say utility.h.

#ifndef UTILITY_H
#define UTILITY_H
#include <iostream>
#include "fstream"
#include "sstream"
#include <iomanip>
#include <string>
#include "ezwin.h"
#include "rect.h"
#endif

Now these are my favourites and I call them only through a single statement #include "utility.h" in my main .cpp file. The boby of this structure u can use for functions and call them in your main .cpp file as a function call after including that file as a header file.




Mel
Re: Assignment 2 countdown
May 18, 2006 08:44AM
I'm doing COS111U, COS113W, COS114X, STS105, CSS101 and I have just finished ACN102. I also work full time and have to study in the evenings and over weekends. I think it helps when you enjoy your subjects, and especially when subjects are "hands-on" and straight away you can see a result (programs compile correctly etc) it gives more motivation. I did INF109 last year and found it pretty easy. A lot of the stuff is common sense (I thought!)

Valkeye, is there any way we can get credit for CEM101A? I mean, surely after passing a certain number of computer subjects it's a given that we know how Office works? For me it's so much admin to do all those tests as well!
Sorry, only registered users may post in this forum.

Click here to login