| | |
Q about Files, EOF, reading marker... help
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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.
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Assigning variables from csv files.. (C++)
- file open code in VB (Visual Basic 4 / 5 / 6)
- reading a file into code (Java)
Other Threads in the C++ Forum
- Previous Thread: where can download C++ installer?
- Next Thread: Keil board MCBSTR9
Views: 349 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






