Welcome! Log In Create A New Profile

Advanced

Assignment 3 Question 4

Posted by dve83 
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
Assignment 3 Question 4
June 10, 2006 01:38PM
How much error checking should we do. Eg. the assignment says tht setDay() should set the day variable to the one provided by the user.
Should we confirm the validity of the day each time the user changes it in some way? just need to be sure.
Re: Assignment 3 Question 4
June 10, 2006 03:00PM
I did the checking in the mutator so if they ever change the day it will be checked. But then you also have to check the month because they might input 31 June or something similar.

That how I did it.

Devesh
Re: Assignment 3 Question 4
June 13, 2006 06:01PM
devesh - How are you converting the month input from string to int, and then from int back to string for the stream output. Why have the month as int within the object whereas the inputs and outputs will always be as a string representation of the month. Now the calling code must convert the month and the object itself needs to convert it back. It would make more sense to initialize the object with the month as string and leave all conversions to the object itself, simplifying the calling code.
This is probably a stupid question, I managed to spend about 30mins on this last night at about 12 o' clock. I was not the brightest tool in the shed at that stage.
Re: Assignment 3 Question 4
June 17, 2006 12:44AM
The function for month input is an integer as is the constructor. So it seems like they expect the month int. The month value is also stored as an int.

To output it via the overloaded operator you just check the value of month and send the correct value out to the stream. The question only expects the output to be the month in string.

I am a little confused as to what you are saying. Please explain it again if I am missing something.

Devesh
Re: Assignment 3 Question 4
June 17, 2006 08:54AM
I eventually sent an email Mrs Schoeman with a couple of questions. Perhaps I read the question a little hastily, but it seemed at little strange to expect the user to input the month as string, then have the calling code handle the conversion to int, and then hae the object do the conversion back to string. Why not pass the month as a string to the object, and let it do all the converting.
Mrs Schoeman confirmed that the output of the month must indeed be as a string, a point which I neglected in my frustration, and unfortunately I got her reply after I had submitted my assignment. An unnecessary waste of points.

Another point of frustration was the the overloaded increment/decrement operators. They only work as prefix operators (--d1 or ++d1) and not as postfix operators (d1++, or d1--). I could not find any differentiation in the prescribed book ot tut letter regarding prefix and postfix operators.

Another point was the use of 2 constructors instead of 1 with default values.

To top it all off I kept on declarinf the object as Date d1(), instead of Date d1, without the parenthesis.

My orginal question was posted under quite a bit of frustration. perhaps the reason for the lack of clarity.

Thanks for responding anyway.

AndreB
Re: Assignment 3 Question 4
June 18, 2006 12:04AM
hi guys

if i want to add an enum for my dates into this class, where would i do it? does it go in the header file or in the default constructor?

thanx
Re: Assignment 3 Question 4
June 19, 2006 12:57PM
To answer the question regarding:

Another point of frustration was the the overloaded increment/decrement operators. They only work as prefix operators (--d1 or ++d1) and not as postfix operators (d1++, or d1--). I could not find any differentiation in the prescribed book ot tut letter regarding prefix and postfix operators.


This is explained on page 413 of C++ Program Design: An introduction to Programming and Object-Oriented Design.

The operator is a member operator this implies that only the right operant can be promoted. This could be one possible explanation.
Re: Assignment 3 Question 4
June 19, 2006 06:19PM
Hi Whatever,

Please see the thread "Is this the way to declare a class in C++" or something to that affect, for a detailed explanation on this.

Both the pre and post fix operators can and should be member operators (i.e. declared within the class.)

AndreB
Re: Assignment 3 Question 4
July 09, 2006 12:04PM
Did anyone else have problems
implementing the increment (++)
operator overload.

I find the declaration supplied
by Unisa giving me compiler errors

Anyone else ?
Re: Assignment 3 Question 4
July 10, 2006 09:07AM
Hi ToxMox

See the above comments and/or check there are a few other threads that included problems with the increment operator.
Remember that definition of the overloaded operator in the given class definition is for the prefix increment operator only (++i), not the postfix (i++).

Hope this helps.
AndreB
Sorry, only registered users may post in this forum.

Click here to login