• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

COMP115 ass3 (2 Viewers)

pb

Inside The Hollow
Joined
Jan 20, 2004
Messages
775
Location
Westie!
Gender
Female
HSC
2003
Originally posted by MicK_eT
:( i feel like breaking down and crying.. comp is sooo evil.. i cant do any of the evil weekly exercises and i cant do the assignment 3.. grr... evil exams at teh end of semester.. *sighs*

maths is evil now too... *sigh*... i dunno what the hell they are doin now... hahah.. hmmmz...

true... everything u said is true... :(
maths and comp r evil
 

...

^___^
Joined
May 21, 2003
Messages
7,723
Location
somewhere inside E6A
Gender
Male
HSC
1998
this wk's comp prac is very evil
but apparently it benefits us

getting onto the assignment
its fucken crazy
 

ND

Member
Joined
Nov 1, 2002
Messages
971
Location
Club Mac.
Gender
Male
HSC
2003
Wow that assignment was easy... alot quicker than the last one. Wtf were those things in the bonus file? I just deleted them and did it with arrays.
 

zxl

Member
Joined
Dec 19, 2003
Messages
34
Gender
Male
HSC
2003
finished it all in 1 hour, nothing particularly hard really
 

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
Originally posted by ND
Wow that assignment was easy... alot quicker than the last one. Wtf were those things in the bonus file? I just deleted them and did it with arrays.
yeh i am doing them without them functions aswell.

how you managing to do the formatting [setw(4), etc] in the strings, i am assuming you made an array of strings?
 

ND

Member
Joined
Nov 1, 2002
Messages
971
Location
Club Mac.
Gender
Male
HSC
2003
Originally posted by redruM
yeh i am doing them without them functions aswell.

how you managing to do the formatting [setw(4), etc] in the strings, i am assuming you made an array of strings?
This is my code for the formatting:

setw(20-data.surname.length()-data.firstname.length())

I outputted it after the firstname. They are from a struct called "data".

For the bonus, i used arrays of structs.
 

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
i know how to make it work using strings...but i have to try it out.

you use something like string streams.


thats a pretty cool method ND. mine is similar, but i stored my line of info as a string and stored that string in an array.
then i output each line of the array, for each grade.
 

BigJim

New Member
Joined
May 16, 2004
Messages
2
Heyas, new to board.

Anyway... I'm having a prob with assign3.

It was all working well, until i tried to make my own user defined function to print the stuff in the file, rather than have to write it 3 times....

I tried using prototype mode and all that, but it keeps saying my arrays from main are undefined.

Any ideas?

*EDIT*
Passed the values in 1 by 1 as normal strings and doubles rather than trying to pass over the whole array.... but everytime it clears the file when it passes through
 
Last edited:

doe

Member
Joined
Jan 23, 2004
Messages
751
Gender
Undisclosed
HSC
N/A
are you reopening the file and stuff each time? if so it might be trucating it.

move the arrays from main outside of any functions (ie make them global variables), or pass them as an argument.
 

BigJim

New Member
Joined
May 16, 2004
Messages
2
Ahhh thanks. Declared them outside main then just passed in the array position and it works now.

Yeah and I had it reopening and truncating file too.
inFile and outFile wouldnt work unless I did, until i moved em outside of main.

Cheers
 
Last edited:

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
Originally posted by jezzmo
Does anyone know how to format the average marks into 2 decimal places?

ive tried using setprecision(2) but that simply truncates them all to integers (2 digits).
yeh like pb said, you gotta use showpoint. just chuck the following line in.
outFile.setf(ios::showpoint);
 

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
no worries...i cant get mine to work tho!!

the setw() isnt working with strings...aargh! have to use a loop which is going to output spaces....so fucked!
 

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
yay! completed it!!!

it is so inefficient tho...could have made it shorter, but cant be fucked now....at last i'll submit an assignment that was submitted at 22.5x :p

edit: yeh mine was like:
Code:
int e = 18-lastName.length()-firstName.length();
while ( e > 0)
                   {                                             
                    tempE << " ";                        
                    e--;
                   }
i used string streams, so it was like inputting a space, everytime it looped through, into the string.
 
Last edited:

Wacky

Who me?
Joined
Nov 30, 2002
Messages
41
Gender
Male
HSC
2003
students.txt doesn't have a blank line at the end, so why would there be this problem?
EDIT: I was referring to the doubling up - I had this problem, then I downloaded the text from the site again and it worked fine
EDIT2: though regular_solution.exe seems to handle blank lines fine
 
Last edited:

redruM

Breathe and Stop
Joined
May 11, 2004
Messages
3,954
Gender
Male
HSC
2003
yeh i had that problem too. it was coz of my while loop.

you just need to rearrange the inFile bit to the end, i think from memory.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Top