Welcome! Log In Create A New Profile

# Asignment3 -Question6

Posted by chuchu
Announcements Last Post
SoC Curricula 09/30/2017 01:08PM
Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
School of Computing Short Learning Programmes 11/24/2014 08:37AM
Unisa contact information 07/28/2011 01:28PM
 Asignment3 -Question6 June 04, 2008 09:11AM Registered: 11 years ago Posts: 14 Rating: 0
I am confused with this question, what does the report that is to be displayed on the console contain.
what does the summary report contain ?
and regarding the friend function that takes two input, if one of the inputs is a summary report then what is the second input? what does it mean one day's object? does it mean that the main program requests a date to compare with the summary report?
Thanks
 Re: Asignment3 -Question6 June 04, 2008 01:49PM Registered: 14 years ago Posts: 1,424 Rating: 0
The structure of the weatherReport class is given in the first paragraph.

The friend function that you need to create must take the month-end weatherReport object as the first argument and then a daily weatherReport object as the second argument. Since there are 30 daily objects, you must cycle through this 30 times, each with a different daily object as the second argument.
 Re: Asignment3 -Question6 June 04, 2008 02:00PM Registered: 11 years ago Posts: 14 Rating: 0
What does the month-end weatherReport store- is it the highest temprature, the lowest temprature and rain and snow of the weather.dat . If so with which daily weatherReport value shall I compare the summary inorder to change the highest temprature if the day's highest temprature is grater than the summary
 Re: Asignment3 -Question6 June 04, 2008 03:04PM Registered: 12 years ago Posts: 475 Rating: 0
chuchu Wrote:
-------------------------------------------------------
> What does the month-end weatherReport store- is it
> the highest temprature, the lowest temprature and
> rain and snow of the weather.dat . If so with
> which daily weatherReport value shall I compare
> the summary inorder to change the highest
> temprature if the day's highest temprature is
> grater than the summary

The montly report has the same type as the daily reports,i.e. WeatherReport. Thus for your second question: compare apples with apples. Does that make sense?
 Re: Asignment3 -Question6 June 05, 2008 07:16AM Registered: 11 years ago Posts: 14 Rating: 0
let me make my question clear
Here are the list of things I did
1. I created the weatherReport class
2. initialized the WeatherReport with a default given values
3. overloaded the operator >> to input the 30 daily data from a file.
4. from the main program display the 30 daily data on the console

my question is
1. what is the summary object? is it highest temprature, the lowest temprature and rain and snow of the weather.dat ?
2.if the summary object is as described in 1, then if I am to compare the summary object with any day's object from weather.dat, the result would always be the summary object ?
so can anyone please clarfy for me question6
 Re: Asignment3 -Question6 June 05, 2008 09:51AM Registered: 12 years ago Posts: 475 Rating: 0
Look at the following pseudocode:

foreach day

if day.highestTemp > summary.highestTemp then
summary.highestTemp = day.highestTemp

if day.lowestTemp < summary.lowestTemp then
summary.lowestTemp = day.lowestTemp

summary.rainFall = summary.rainFall + day.rainFall

summary.snowFall = summary.snowFall + day.snowFall

end

Get it. The membernames maybe wrong. I didn't have a look at the assignment.

Cheers
 Re: Asignment3 -Question6 June 05, 2008 01:12PM Registered: 14 years ago Posts: 1,424 Rating: 0
The design specifications are not the best since the daily data and the summary are logically different things, although they have the same data members. Unfortunately, that's the way the assignment was set so that's how you should write it.

You have only one class, weatherReport. You need to read in all of the data from the data file and create one weatherReport object for each day. These are held in the 30-element array.

The summary report that you need to create unfortunately has been decided to also be a weatherReport object. You must calculate and store the summary data inside this object. The way you calculate the summary by using the friend function with two parameters.

You should cycle through each of the 30 days and calculate the summary data inside this function. After that, you'll be left with an array of 30 elements containing the daily values and a 31st weatherReport object containing the summary data. Henry's post above shows the algorithm for creating the summary data.
 Re: Asignment3 -Question6 June 05, 2008 01:28PM Registered: 12 years ago Posts: 475 Rating: 0
I agree on the design issue. The lecturers actually missed a golden opportunity here to get students thinking on OO design. We could then have had a DailyWeatherReport which extends WeatherReport since the summary don't require the day member.

Anyhow, what's done is done.
 Re: Asignment3 -Question6 June 05, 2008 02:04PM Registered: 11 years ago Posts: 14 Rating: 0
I did store weatherReport object for each day in an array.
I don't think I made my question clear...I did calculate the summary data by taking the highest temprature, the lowest temprature and rainfall and Snowfall from weather.dat.
But if I am to compare the summary object with any day's object from weather.dat, the result would always be the summary object... this is what is bothering me?

But thanks for the support
 Re: Asignment3 -Question6 June 06, 2008 01:05PM Registered: 14 years ago Posts: 1,424 Rating: 0
You are not making your problem very clear. It sounds like you're calculating your summary data as you are reading the data from the file and storing it in the daily weatherReport objects. You are not supposed to do that. It is supposed to be a two-step process: Read data into array of objects. Calculate summary from array.
 Re: Asignment3 -Question6 June 06, 2008 04:17PM Registered: 11 years ago Posts: 14 Rating: 0
Thanks robanaurochs.
It is quite clear now.
 Re: Asignment3 -Question6 June 11, 2008 09:14PM Registered: 11 years ago Posts: 533 Rating: 0
OK, Another question, who has had a look at the initial values for highTemp and lowTemp. highTemp should be 9999.

If you do the comparison: if daily.highTemp greater than summary.highTemp, daily will (as long as we are alive on earth) not be more that summary.

In comparison lowTemp's initial value is -9999.... I'm very tempted to assume this is a error in the Question and swap the two initial values around.

What do you think?
 Re: Asignment3 -Question6 June 11, 2008 09:29PM Registered: 14 years ago Posts: 1,424 Rating: 0
Well-spotted but the question does mention specially that the summary object must be initialised with default values. This could mean that these defaults are not the same as those from the default constructor although it would make sense.

You could swap the high/low default values around and then use the fact that the logical impossibility of highest being lower than lowest as a way to determine whether the object has valid data or not. But this is extra not a requirement.

I would say, swap the values but put a note in your assignment explaining what you've done and why.
 Re: Asignment3 -Question6 June 11, 2008 09:52PM Registered: 11 years ago Posts: 533 Rating: 0
I've posted the same question to myUnisa as well, hopefully one of the lectures will see it. I'll send them an e-mail tommorow as well, In the mean time I'm going to swap them around so long.
 Re: Asignment3 -Question6 June 12, 2008 07:08AM Registered: 11 years ago Posts: 14 Rating: 0
I just intialized the the summery object with zero values to solve the problem.
 Re: Asignment3 -Question6 June 12, 2008 08:27AM Registered: 11 years ago Posts: 533 Rating: 0
Zero values wont do the trick. What if the lowest temp is higher than zero?
 Re: Asignment3 -Question6 June 12, 2008 08:31AM Registered: 12 years ago Posts: 475 Rating: 0
No, the safest way is to extend the if statements to check for the defaults as well. In other words, if the summary object still have the default values, then overwrite it with what you are comparing from the daily object.
 Re: Asignment3 -Question6 June 12, 2008 08:37AM Registered: 11 years ago Posts: 533 Rating: 0
It will work but it is so inelegant
 Re: Asignment3 -Question6 June 13, 2008 09:01AM Registered: 13 years ago Posts: 22 Rating: 0
A question from one of the students:

The question ask that the constructor initialises the member variables with 9999 for highTemp and -9999 for lowTemp. To determine the highest and lowest temperature for the summary object it makes logically more sense if the member variables was initialised other way around (-9999 for highTemp and 9999 for lowTemp). Is this an error in the question? Can we initialise the member variables other way around and comment our assignments accordingly or should we implement additional code and validation to determine if the summary object still contains default values.

And an answer from the module leader:

Do initialise the highest and lowest temperatures the other way around, and comment accordingly, it certainly makes more sense. Both approaches will be acceptable when we mark.

Mrs MA Schoeman

School of Computing
 Re: Asignment3 -Question6 June 17, 2008 09:03PM Registered: 12 years ago Posts: 31 Rating: 0
Let's try again.
I am strugglig to resolve the errors I am getting whilst trying to load the data from the file into the 30 objects. I have overloaded the extraction operator as follows:
friend istream& operator>> (istream& fin, weatherReport& daily);

where daily is defined as an object of type weatherReport daily[MAX_SIZE]

when I compile however I get the following error for the code:

fin >> daily.dayOfMonth; error C:\unisa\cos112\Test\WeatherReportApp.cpp:62
no match for 'operator[]' in 'daily'

Can someone please assist
Thanks
 Re: Asignment3 -Question6 June 17, 2008 09:24PM Registered: 11 years ago Posts: 533 Rating: 0
This is not the cause of the error both, at least I don't think so, but it is a start.

You've overloaded the >> operator for the use with objects of type istream and weatherReport as parameters. But when you use it you give it an istream and a int dayOfMonth (which is most likely not accessible cause it's private) as parameters.
 Re: Asignment3 -Question6 June 17, 2008 10:10PM Registered: 12 years ago Posts: 31 Rating: 0
Thank you for the feedback rdebruyn. Is that the right place to fill the arrays (i.e. at the definition of the extraction operator?) or should it be done in the main function using a set function?
 Re: Asignment3 -Question6 June 18, 2008 09:34AM Registered: 11 years ago Posts: 533 Rating: 0
Let me put it this way, there is no weatherReport object in the definition of the class.

The array of objects only exist in the main funtion or there where you create an instance (object) of the class with a statement such as weatherReport dailyReport; or weatherReport dailyReport[365]; for a array of objects.
 Re: Asignment3 -Question6 June 18, 2008 11:40AM Registered: 12 years ago Posts: 31 Rating: 0
Thanks again. In the end the logic was correct but I did not have a "while(fin.eof())" condition in. The array is now populated so the real work can start
 Re: Asignment3 -Question6 June 18, 2008 11:56AM Registered: 12 years ago Posts: 2,075 Rating: 0
wait I'm confused again. If you update the summary object memebers in the friend function, then you still have to return the summary object to the calling function, and assign this object to the summary object?
 Re: Asignment3 -Question6 June 18, 2008 12:30PM Registered: 11 years ago Posts: 533 Rating: 0
My friend function uses two reference parameters. Go check again what is the difference between reference parameters and value parameters
 Re: Asignment3 -Question6 June 18, 2008 12:37PM Registered: 12 years ago Posts: 2,075 Rating: 0
I understand that yours is the right way to do it, but the question in the tut letter is:

Quote
The friend function takes two weatherReport objects Ã¢â‚¬â€œ the summary object and one day's object (an element in the array)Ã¢â‚¬â€œ and it returns an updated summary object

this seems redundant to me.
 Re: Asignment3 -Question6 June 18, 2008 12:43PM Registered: 11 years ago Posts: 533 Rating: 0
I've interpreted "and it returns an updated summary object" as after the function has executed the summary object contains the updated values.

I know why you want to know what "they" meant. cause I'm going through my 2nd assignment now, and the guy that marked it didn't leave anything up for interpretations.

All my answers is write. Just not exactly like theirs so they mark it wrong. Brilliant.
 Re: Asignment3 -Question6 June 18, 2008 10:03PM Registered: 12 years ago Posts: 31 Rating: 0
I am struggling again to call the friend function that will do the comparisons and build up the summary object. From the main function I want to pass the filled daily array of objects as the first parameter and the initialised summary object as the second parameter: monthEnd(daily[MAX_SIZE], monthly); I get the error error cannot convert weatherReport' to weatherReport*' for argument 1' to weatherReport monthEnd(weatherReport*, weatherReport)'

I have no idea what the error is.
 Re: Assignment -Question June 19, 2008 08:20AM Registered: 11 years ago Posts: 533 Rating: 0
daily[MAX_SIZE] is one element of the array (most likely out_of_bounds, cause the last element's index is normally MAX_SIZE - 1) you function looks for the array as a parameter, not just one element. - That's the cause of the error.

However, the question is as follows "The friend function takes two weatherReport objects Ã¢â‚¬â€œ the summary object and one day's object (an element in the array)Ã¢â‚¬â€œ and it returns an updated summary object." Be careful, I've got "penalised" in the previous assignment for not giving exactly what they ask for, although my solution worked 100% correctly.

Your solution will work, but for reasons I can not recall right now, It would be best_practises to implement a copy constructor with your solution. (The reasons is in the textbook)
Sorry, only registered users may post in this forum.