Q about Files, EOF, reading marker... help

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 1
Reputation: ecullenlvr is an unknown quantity at this point 
Solved Threads: 0
ecullenlvr ecullenlvr is offline Offline
Newbie Poster

Q about Files, EOF, reading marker... help

 
0
  #1
Nov 11th, 2008
Hi everyone. I am new to DaniWeb, so I hope I am doing this right. I need to make a few programs for one of my classes. I understand the concepts, but there are a few points I do not understand. My questions are below, and I will bold what I do not understand underneath.


2. Store the following data in a file:
5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 75 81 73
Write a program to calculate and display the average of each group of numbers in an output file. The data are arranged in the file so that each group of numbers is preceded by the number of data items in the group. Thus the first number in the file, 5 indicates that the next five numbers be grouped together and the 4 indicates the next 4 numbers go together. (Hint: use a nested loop. The outer loop should terminate when the EOF marker is encountered)
I understand everything except how to get the program to recognize 5, 4, 6. And then, how do you get the program to use those numbers in the average, but not in the total?

3. Write a program that reads, moves the reading marker, and displays every second character in this file: abcdefghijklmnopqrstuvwxyz.
I do not understand how to get the reading marker to pick out those characters.

Thats it. Thank you in advance. If you give me the gist of the concept, I can probably create the program on my own. I just hate loops and I was absent for the class on files. Thank you so muh!

~jen
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Q about Files, EOF, reading marker... help

 
0
  #2
Nov 11th, 2008
For your first problem, read a number from the file. Use that number as the limit on a loop that reads in values to be summed and averaged. Main loop comes around again, reading in the next count of values number, ....

I'd put the reading statement for the count value as the condition of the outer loop, that way, when you've reached the end of data, attempting to read in the next, nonexistent value will exit the main loop.

Regarding the second, when a problem mentions moving the read pointer, I take that to mean making use of the seekg( ) function. You would again need a loop, incrementing by 2, to move along to the desired locations.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 349 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC