IO stream

B

Ben Pope

oLgAa25 said:
Then why do I need to learn it. ? what for ? can you give details ?

It allows you to step through your code line by line and analyse the
values of variables at runtime.

Ben Pope
 
O

osmium

Olga said:
Ok this is it for me, I am going Nutssss.... here. I don't know what I
am doing wrong any more
I started out by having a problem with my output coming out in bad
way, and now I am back to no where :(

I took another look at your code from 7:14 last night It looks pretty bad.
You read the individual scores in the average function but then you try to
write them in main. They are gone now, like my tape player analogy.
Whoever does the reading should also do the writing. I assume you know about
arrays - you shouldn't have been given this assignment if you don't. Try
changing the signature of the average function to (my variable names)

void student_average(int scores[5], double& average_score)

The function can no longer read the file. main must do all the file
manipulation, collect five scores, put them in an array and pass them to
student_average It's a convoluted way to do this, but ISTM to be what your
instructor wants.

The 7:14 edition has EOF detection wrong, so you get two Plutos. There is
an uninitialized variable "numberof tests" or some such, in the average
function.

Leave almost all of the formatting out, it isn't necessary and it just makes
something rather simple look complicated. And it takes time to type and
correct the typing and syntax errors. Get it working. Then, and only then,
make it pretty.

Check for end of file immediately after you read a student name. *Then* is
when the system realizes it is at end of file.
 
B

BobR

oLgAa25 wrote in message ...
Guys, do you get paid,

Yes, when we do the work. If we do your homework, we expect you to transfer
the grades and course credits to our accounts. <G> But, that's why we don't
do the work, you would not learn anything! If I (or others) posted a program
for you, using our experience, and you turned it in, your teacher would fail
you for obvious reasons (you don't know that stuff yet.).
or do you that because you like helping people
like me?
because you do a good job, and I realy appreciate that.
Olga

I started helping because I was helped, and it feels good when I get it
right. Matter of fact, Mr. 'osmium' is one of the many who have aided me over
the last five years ( I came up to C++ from Assembler in 2000.(hobbiest,
wanna be pro<g>)).

A good book(s) is a must, but, you can learn much from reading this and other
(C++) newsgroups.
 
B

BobR

oLgAa25 wrote in message
Ok this is it for me, I am going Nutssss.... here. I don't know what I
am doing wrong any more
I started out by having a problem with my output coming out in bad
way, and now I am back to no where :(
I don't know what else to do
Thank you all for the help

One way to find problem code:
Comment-out code until it compiles and runs as expected. Then un-comment, a
few lines at a time, until the errors crop up. Now you've isolated the
problem code, and can concentrate on that area.
Always break-up the program into small tasks. Don't try to do everything in
one function.

I know you are pressed for time right now, but, read-up on your debugger when
you get time. It is a valuable tool.
 
O

osmium

oLgAa25 said:
Nop, no arrays, and that is the problem. We are still not there yet.

Well, try this then. Write code for this function.

void stud_average(ifstrean& in, ofstream& out, double& mean score)

Read the student name and detect end of file in main. Then call
stud_average which will read five scores and as each one is read it is
written to the output file. it computes the mean score and then returns to
main. main will write the score returned, compute and store the letter
grade, and then (attempt to ) read the next students name. No arrays and no
need for five variable names. I don't really like it but one has to follow
the rules. AFAIK this complies with all the rules, will work and doesn't
depend on any additional knowledge on your part.
 
O

oLgAa25

Oh sure ;-), well Thank you for volunteering your time.
what is a good book to learn, because my book talk more than it
delivers.

I tried to to go to the newsgroups website , but God, it took me to an
unwanted place.
so I need to setup my earth link account.

I need to find the setting directions.

Good sense of humor guys, nice to have troubles with you;-)
 
O

oLgAa25

see you are right,
I wrote my void function and my calculateAverage and I had no errros,
but when it came to putting my code together, that is when I paniced at
firct, and then *Never Worked* ;-)

but again I am just at the begining of C++, and still have a long way
to go. But to be honest I don't think that I will be making a living of
c++ coding :)
 
O

oLgAa25

Oh well guys, after I gave up on my machine, I sent my code to
classmate to compile it for me, and she sent me the output.
It was as we the teacher asked us to do. so I think that my compiler is
getting old. I am using Dev-C++
hmmmm I need to change it

Olga
 
B

BobR

oLgAa25 wrote in message
Oh well guys, after I gave up on my machine, I sent my code to
classmate to compile it for me, and she sent me the output.
It was as we the teacher asked us to do. so I think that my compiler is
getting old. I am using Dev-C++
hmmmm I need to change it
Olga

<OT>
No, Dev-C++ is not a compiler. It is an IDE, and it usually comes with the
window$ port of GCC (GNU Compiler Collection) called MinGW.
You should be using Dev-C++ with a version 4.9.9.2 or newer (4.9.9.1 came
with GCC 3.3.1 [1]). If yours is older, then you should update. Click
'Tools -->check for updates/packages', or go to the Bloodshed site if your
Dev-C++ is old(and does not have that option).
Dev-C++ IDE: http://www.bloodshed.net/

[1] put "std::cout<<__VERSION__<<std::endl;" in main() to see your GCC
version.
</OT>
 
A

Aleksander Beluga

oLgAa25 said:
Thank you so much,
but you still didn't recommend a good c++ book !..;-)

I believe Bjarne Stroustrup's "The C++ Language" 3rd ed is the best.
 
O

osmium

Olga said:
but you still didn't recommend a good c++ book !..;-)

I recommend authors, not books. Stephen Prata and Robert Lafore are both
very good. Based on what I have seen of your work, I would defer getting
Stroustrup for a while.
 
B

BobR

oLgAa25 wrote in message
Thank you so much,
but you still didn't recommend a good c++ book !..;-)

While you are researching what books to get, go download 'Thinking in C++'
vol.1(of 2) at:
(available for free here):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

It is NOT a 'programming newbie' book. It's not 'the' best book, but, it it
extremely far from the worst (..and won't cost you anything but short
download time. You can buy it in hardcopy too.)

I've heard good things about Mr. Glassborow's book 'You Can Do It!'
http://www.spellen.org/youcandoit
It is targeted for 'programming newbies'. I wish it had been available when I
started C++.

Besides what the other posters have suggested, you can find book reviews at
www.accu.org to aid in your choice(s).
 
O

oLgAa25

Hello all,
one more question, what about Deitel & Deitel.? any ideas?
appreciate it
 
N

Neil Cerutti

Hello all,
one more question, what about Deitel & Deitel? any comments?
Thank you

Personally, I didn't like it. The programming style, the problems, and
the order in which they presented topics went against the
recommendations of Bjarne Stroustrup: Learn how to harness the power
of the standard library before mastering the low-level, C-compatible
features. _Accelerated C++_ (Koenig, Moo) uses the approach advocated
in _The C++ Programming Language_.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Chatbot 0
Linker Error Help!! 2
setfill('\t') 5
NullPointerException error 3
Questions about new range for 2
clearing contents of ostringstream object 4
C++ help 3
Little help please 7

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top