Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,961 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,521 people online right now. Registration is fast and FREE... Join Now!




TeXtfiLe

 
Reply to this topicStart new topic

TeXtfiLe, Somebody help me??

okky
5 Jun, 2007 - 01:00 PM
Post #1

New D.I.C Head
*

Joined: 28 May, 2007
Posts: 6


My Contributions
Write a program that writes a row of whole numbers (closed by a 0) to a textfile.
Next, write a program that determines the maximum and minimum values of those numbers in the file.
Then this program must write all numbers in this file, smaller than the average of the maximum and
the minimum, to a new textfile. After all numbers are written, the content of the new file must be
printed to the screen.

Somebody wants to help me?? smile.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: TeXtfiLe
5 Jun, 2007 - 01:24 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 48 times
Dream Kudos: 550
My Contributions
All of these things have been done over and over on this site. A simple search will get you far.

Having said that. The site has a policy that we must see some effort. We are here to help troubleshoot and answer conceptual questions -- not here to do your homework.

So either post specific syntax or conceptual questions, or provide us with your attempts.
User is offlineProfile CardPM
+Quote Post

Topher84
RE: TeXtfiLe
6 Jun, 2007 - 06:21 AM
Post #3

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
QUOTE(okky @ 5 Jun, 2007 - 02:00 PM) *

Write a program that writes a row of whole numbers (closed by a 0) to a textfile.
Next, write a program that determines the maximum and minimum values of those numbers in the file.
Then this program must write all numbers in this file, smaller than the average of the maximum and
the minimum, to a new textfile. After all numbers are written, the content of the new file must be
printed to the screen.

Somebody wants to help me?? smile.gif


I'll go along w/ the rules and say you need to provide some effort but I am bored and will help you with a vague sample solution outline.

Program 1
-at this point i am guessing you have to enter the #s in yourself
1. Prompt the user for the #s (0-terminated)
2. Store these numbers in an array of ints
3. Create an fstream object to output to the txt file
4. Attempt to create (open) the file
5. Loop through your array to output the #s to the file
6. Close the file

Program 2
1. Create an fstream object to read the #s into an array from the file stopping on 0 (or until end of file if you only have 1 line)
2. Use a sorting function on the array to get the numbers in order
* you can then determinate max/min
3. Add the numbers in the array and do your arithmetic to get the avg and what not
-I am guessing what you are sayign is that you want the program to read in the numbers from the file and then get the average of all the numbers. Then write back out to a file all of the numbers that are smaller than that average.
4. You have an array that is in order so just loop through it comparing to if each individual element is less than the average and write that number out to the file
5. Close the file when done

Hope it helps some

This post has been edited by Topher84: 6 Jun, 2007 - 06:21 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: TeXtfiLe
6 Jun, 2007 - 03:28 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,225



Thanked: 36 times
Dream Kudos: 25
My Contributions
Users are unpredictable...unless you want to do the proper error checking, your assignment parameters seem to allow for no user interaction. Run a for loop, and randomly generate integers, placing them in the file.
User is online!Profile CardPM
+Quote Post

Topher84
RE: TeXtfiLe
7 Jun, 2007 - 07:21 AM
Post #5

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
QUOTE(Amadeus @ 6 Jun, 2007 - 04:28 PM) *

Users are unpredictable...unless you want to do the proper error checking, your assignment parameters seem to allow for no user interaction. Run a for loop, and randomly generate integers, placing them in the file.


This seems like an intro level class program.. and judging by him not replying i'd say he is gone... I seriously doubt that if he can't write info to a txt file he doesn't know how to generate random numbers!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:33AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month