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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.