http://uzaclan.com/forum/

Computer Science help!
http://uzaclan.com/forum/viewtopic.php?f=9&t=235
Page 1 of 1

Author:  {uZa}DeathByMunky [ Mon Mar 30, 2009 10:02 pm ]
Post subject:  Computer Science help!

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.

Author:  cmos [ Tue Mar 31, 2009 1:04 pm ]
Post subject:  Re: Computer Science help!

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.

Author:  {uZa}DeathByMunky [ Wed Apr 01, 2009 1:30 am ]
Post subject:  Re: Computer Science help!

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.

Author:  {uZa}1terribleshot [ Wed Apr 01, 2009 7:21 am ]
Post subject:  Re: Computer Science help!

OMG were you speaking english JK b29


Good luck Dude

Author:  cmos [ Wed Apr 01, 2009 11:13 am ]
Post subject:  Re: Computer Science help!

Good deal dude. Sorry if I confused you at all.

Author:  {uZa}DeathByMunky [ Wed Apr 01, 2009 3:45 pm ]
Post subject:  Re: Computer Science help!

You didn't confuse me. Those links were actually very helpful. I understand file I/O a lot better now.

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/