Author |
Message |
{uZa}DeathByMunky
|
Post subject: Computer Science help! Posted: Mon Mar 30, 2009 10:02 pm |
|
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.
|
|
|
|
|
cmos
|
Post subject: Re: Computer Science help! Posted: Tue Mar 31, 2009 1:04 pm |
|
|
Found Submit Button |
|
Joined: Mon Feb 23, 2009 10:14 pm Posts: 38
|
|
|
|
|
{uZa}DeathByMunky
|
Post subject: Re: Computer Science help! Posted: Wed Apr 01, 2009 1:30 am |
|
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.
|
|
|
|
|
{uZa}1terribleshot
|
Post subject: Re: Computer Science help! Posted: Wed Apr 01, 2009 7:21 am |
|
Joined: Wed Feb 25, 2009 9:19 am Posts: 466 Location: Indiana
|
OMG were you speaking english JK Good luck Dude
|
|
|
|
|
cmos
|
Post subject: Re: Computer Science help! Posted: Wed Apr 01, 2009 11:13 am |
|
|
Found Submit Button |
|
Joined: Mon Feb 23, 2009 10:14 pm Posts: 38
|
Good deal dude. Sorry if I confused you at all.
|
|
|
|
|
{uZa}DeathByMunky
|
Post subject: Re: Computer Science help! Posted: Wed Apr 01, 2009 3:45 pm |
|
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.
|
|
|
|
|
|