Register    Login    Forum    Search    FAQ

Board index » {uZa}GENERAL FORUMS » The Lounge




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Computer Science help!
 Post Posted: Mon Mar 30, 2009 10:02 pm 
Offline
Forum Regular
Forum Regular
User avatar

Joined: Sun Feb 22, 2009 2:07 pm
Posts: 100
Location: North Alabama
I've got a test tomorrow morning at 9:30, and I've been going through my practice problems. I've been getting stuck on these File I/O problems. I normally don't ask for help on these, but I'm really pushed for time. I know some of you guys may have majored in this or are pretty good with programming.

I'm using Dev C++.

Here's the problem:

Write a function that takes in a string file
name as a parameter. The function should
open the file for input and make sure the
file is available. The file will contain
integers in sorted order. Input the integer
values until you reach the end of the file.
Pass back as a parameters the low, hi, and
median values from the list of integers.


This is what I have so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void TestFile(string yourchoice, int &low, int &hi, int &median);

int main(){

int low;
int hi;
int median;
string yourchoice;

cout << "What file would you like to open?" << endl;
cin >> yourchoice;

TestFile(yourchoice, low, hi, median);

cout << "The LOW is: " << low << endl;
cout << "The HIGH is: " << hi << endl;
cout << "The MEDIAN is: " << median << endl;

system("pause");
return 0;
} // end main



void TestFile(string yourchoice, int &low, int &hi, int &median){

ifstream inFile;
inFile.open("yourchoice.txt"); //no idea how to actually use the user entered string.

if(inFile.fail()){
cout <<"File not found!" << endl;
system("pause");
exit(0);
}
}

Any help would be greatly appreciated.


Top 
 Profile  
 
 Post subject: Re: Computer Science help!
 Post Posted: Tue Mar 31, 2009 1:04 pm 
Offline
Found Submit Button
Found Submit Button

Joined: Mon Feb 23, 2009 10:14 pm
Posts: 38
Jeez man it has been a long time since I looked at any code.

Here are a couple of links that my show you the way

http://www.fredosaurus.com/notes-cpp/io ... tfile.html

http://www.dreamincode.net/forums/showtopic44081.htm

http://www.dreamincode.net/forums/showtopic68191.htm

For some reasone I am thinking that you want to use an array for your string. Maybe I am over thinking the problem. I'm guessing that you are to determine what is the largest, smallest, and middle number. Meaning that you will need to do some comparing.

I don't see any error trapping. I would imagine they would want you to print a message if the file doesn't exist.

Be sure to look at that 3rd link. It sounds like your problem. Of course, I remember break being a poor programming technique.


Top 
 Profile  
 
 Post subject: Re: Computer Science help!
 Post Posted: Wed Apr 01, 2009 1:30 am 
Offline
Forum Regular
Forum Regular
User avatar

Joined: Sun Feb 22, 2009 2:07 pm
Posts: 100
Location: North Alabama
Thanks for the links cmos. Luckily my brother is a Computer Science major and he help me out with it. Turns out the call was something I haven't even learned yet. I think I did pretty well on my test though. I studied for around 6 hours straight.


Top 
 Profile  
 
 Post subject: Re: Computer Science help!
 Post Posted: Wed Apr 01, 2009 7:21 am 
Offline
Forum Regular
Forum Regular
User avatar

Joined: Wed Feb 25, 2009 9:19 am
Posts: 466
Location: Indiana
OMG were you speaking english JK b29


Good luck Dude

_________________
b30 I wasn't there..... and you can't prove it. b19

Image


Top 
 Profile  
 
 Post subject: Re: Computer Science help!
 Post Posted: Wed Apr 01, 2009 11:13 am 
Offline
Found Submit Button
Found Submit Button

Joined: Mon Feb 23, 2009 10:14 pm
Posts: 38
Good deal dude. Sorry if I confused you at all.


Top 
 Profile  
 
 Post subject: Re: Computer Science help!
 Post Posted: Wed Apr 01, 2009 3:45 pm 
Offline
Forum Regular
Forum Regular
User avatar

Joined: Sun Feb 22, 2009 2:07 pm
Posts: 100
Location: North Alabama
You didn't confuse me. Those links were actually very helpful. I understand file I/O a lot better now.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 6 posts ] 

Board index » {uZa}GENERAL FORUMS » The Lounge


Who is online

Users browsing this forum: No registered users and 35 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron