anyone with C++ skills wanna help me out real quick??
I'm trying to do this assignment for CS10 (basic of programming with C++).
it's giving me a crap load of trouble. Just wondering if anyone can help me out.
it's giving me a crap load of trouble. Just wondering if anyone can help me out.
Originally Posted by aznd000d
I'm trying to do this assignment for CS10 (basic of programming with C++).
it's giving me a crap load of trouble. Just wondering if anyone can help me out.
it's giving me a crap load of trouble. Just wondering if anyone can help me out.
well, I have to write a program that will take info from the input.txt file and output it to either groupA.txt or groupB.txt files.
the input.txt file looks like this:
A 4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34
B 4.10 4.24 3.78 3.94 4.37 4.06 4.28 3.99 4.00 3.85
B 3.69 3.82 4.56 4.89 4.67 4.04 4.37 3.88 3.89 4.56
A 4.61 4.50 4.63 4.28 3.71 3.75 3.93 4.62 4.48 4.04
A 3.96 4.13 4.05 3.68 4.34 3.69 3.82 4.56 4.89 4.67
A 4.06 4.28 3.99 4.00 3.85 3.72 4.18 4.25 3.58 4.38
B 3.75 3.93 4.62 4.48 4.04 4.45 3.56 4.12 3.78 4.24
A 4.04 4.37 3.88 3.89 4.56 4.61 4.50 4.63 4.28 3.71
B 3.72 4.18 4.25 3.58 4.38 4.13 3.96 4.37 4.49 3.62
A 4.45 3.56 4.12 3.78 4.24 3.75 3.93 4.62 4.48 4.04
B 3.75 3.93 4.62 4.48 4.04 3.96 4.13 4.05 3.68 4.34
B 4.04 4.37 3.88 3.89 4.56 3.78 4.24 3.96 4.13 4.05
The letters infront of each line represent each type of info.
lines staring with A should be gathered into groupA.txt file and calculate it's average, and the same thing for lines starting with B.
the output files should like this:
groupA.txt
4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34 AVG: 4.031 ounces
4.61 4.50 4.63 4.28 3.71 3.75 3.93 4.62 4.48 4.04 AVG: 4.255 ounces
3.96 4.13 4.05 3.68 4.34 3.69 3.82 4.56 4.89 4.67 AVG: 4.179 ounces
4.06 4.28 3.99 4.00 3.85 3.72 4.18 4.25 3.58 4.38 AVG: 4.029 ounces
4.04 4.37 3.88 3.89 4.56 4.61 4.50 4.63 4.28 3.71 AVG: 4.247 ounces
4.45 3.56 4.12 3.78 4.24 3.75 3.93 4.62 4.48 4.04 AVG: 4.097 ounces
groupB.txt
4.10 4.24 3.78 3.94 4.37 4.06 4.28 3.99 4.00 3.85 AVG: 4.061 ounces
3.69 3.82 4.56 4.89 4.67 4.04 4.37 3.88 3.89 4.56 AVG: 4.237 ounces
3.75 3.93 4.62 4.48 4.04 4.45 3.56 4.12 3.78 4.24 AVG: 4.097 ounces
3.72 4.18 4.25 3.58 4.38 4.13 3.96 4.37 4.49 3.62 AVG: 4.068 ounces
3.75 3.93 4.62 4.48 4.04 3.96 4.13 4.05 3.68 4.34 AVG: 4.098 ounces
4.04 4.37 3.88 3.89 4.56 3.78 4.24 3.96 4.13 4.05 AVG: 4.090 ounces
-----------------------------------------------------------------------------------
ok, this is what I wrote, it compiles, but it doesn't run correctly.
the input.txt file looks like this:
A 4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34
B 4.10 4.24 3.78 3.94 4.37 4.06 4.28 3.99 4.00 3.85
B 3.69 3.82 4.56 4.89 4.67 4.04 4.37 3.88 3.89 4.56
A 4.61 4.50 4.63 4.28 3.71 3.75 3.93 4.62 4.48 4.04
A 3.96 4.13 4.05 3.68 4.34 3.69 3.82 4.56 4.89 4.67
A 4.06 4.28 3.99 4.00 3.85 3.72 4.18 4.25 3.58 4.38
B 3.75 3.93 4.62 4.48 4.04 4.45 3.56 4.12 3.78 4.24
A 4.04 4.37 3.88 3.89 4.56 4.61 4.50 4.63 4.28 3.71
B 3.72 4.18 4.25 3.58 4.38 4.13 3.96 4.37 4.49 3.62
A 4.45 3.56 4.12 3.78 4.24 3.75 3.93 4.62 4.48 4.04
B 3.75 3.93 4.62 4.48 4.04 3.96 4.13 4.05 3.68 4.34
B 4.04 4.37 3.88 3.89 4.56 3.78 4.24 3.96 4.13 4.05
The letters infront of each line represent each type of info.
lines staring with A should be gathered into groupA.txt file and calculate it's average, and the same thing for lines starting with B.
the output files should like this:
groupA.txt
4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34 AVG: 4.031 ounces
4.61 4.50 4.63 4.28 3.71 3.75 3.93 4.62 4.48 4.04 AVG: 4.255 ounces
3.96 4.13 4.05 3.68 4.34 3.69 3.82 4.56 4.89 4.67 AVG: 4.179 ounces
4.06 4.28 3.99 4.00 3.85 3.72 4.18 4.25 3.58 4.38 AVG: 4.029 ounces
4.04 4.37 3.88 3.89 4.56 4.61 4.50 4.63 4.28 3.71 AVG: 4.247 ounces
4.45 3.56 4.12 3.78 4.24 3.75 3.93 4.62 4.48 4.04 AVG: 4.097 ounces
groupB.txt
4.10 4.24 3.78 3.94 4.37 4.06 4.28 3.99 4.00 3.85 AVG: 4.061 ounces
3.69 3.82 4.56 4.89 4.67 4.04 4.37 3.88 3.89 4.56 AVG: 4.237 ounces
3.75 3.93 4.62 4.48 4.04 4.45 3.56 4.12 3.78 4.24 AVG: 4.097 ounces
3.72 4.18 4.25 3.58 4.38 4.13 3.96 4.37 4.49 3.62 AVG: 4.068 ounces
3.75 3.93 4.62 4.48 4.04 3.96 4.13 4.05 3.68 4.34 AVG: 4.098 ounces
4.04 4.37 3.88 3.89 4.56 3.78 4.24 3.96 4.13 4.05 AVG: 4.090 ounces
-----------------------------------------------------------------------------------
ok, this is what I wrote, it compiles, but it doesn't run correctly.
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main ()
{
ifstream fin;
ofstream fout;
fin.open ("input.txt");
if (fin.fail())
{
cout << "File 'input.dat' failed to open.";
exit (1);
}
double weight;
int count = 0;
double sum = 0;
double average;
char group;
while (!fin.eof())
{
fin >> group;
if (group == 'A')
{
fout.open("groupA.txt");
while (count < 10)
{
fin >> weight;
sum = sum + weight;
fout << weight << " ";
count = count + 1;
}
average = sum / count;
fout <<"average = " << average <<endl;
count = 0;
sum = 0;
}
if (group == 'B')
{
fout.open("groupB.txt");
while (count < 10)
{
fin >> weight;
fout << weight << " ";
sum = sum + weight;
count = count + 1;
}
average = sum / count;
fout << "Average = " << average << endl;
count = 0;
sum = 0;
}
}
fin.close();
fout.close();
fout.close();
}
btw, the problem is..
it only output to "groupA.txt" file, no "groupB.txt"
and "groupA.txt" file only contain this line:
4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34 average = 4.031
fawk, good thing this is the only CS class I have to take.
it only output to "groupA.txt" file, no "groupB.txt"
and "groupA.txt" file only contain this line:
4.45 3.56 4.12 3.78 4.24 3.96 4.13 4.05 3.68 4.34 average = 4.031
fawk, good thing this is the only CS class I have to take.
eof ........i think = to end of file
so !fin.eof is.... take in data until end of file.......then break out.
so while (!fin.eof()) is........as long as it's not at end of file....keep looping.
CS is kicking my ass right now. i've been trying to debug this program for 2 hrs now. Still can't seem to find out why it's not running correctly.
so !fin.eof is.... take in data until end of file.......then break out.
so while (!fin.eof()) is........as long as it's not at end of file....keep looping.
CS is kicking my ass right now. i've been trying to debug this program for 2 hrs now. Still can't seem to find out why it's not running correctly.
really???
but if I close the fout after each time. wouldn't that mean the next time I open and fout again, wouldn't that overwrite what's currently in that file?
let me try it real quick.
oh btw, this assignment was due uhhhhhhh 2 hrs ago...hehehehe. just coudln't finish it in time.
but if I close the fout after each time. wouldn't that mean the next time I open and fout again, wouldn't that overwrite what's currently in that file?
let me try it real quick.
oh btw, this assignment was due uhhhhhhh 2 hrs ago...hehehehe. just coudln't finish it in time.
well damn.
now the program outputs both "groupA.txt" and "groupB.txt". But as I expected. it overwrites the file each time it opens up.
so now each output file only has one line of data from the last line of the sample output files.
so now the question is.......how's the command to tell the program to NOT overwrite what's in that file.
now the program outputs both "groupA.txt" and "groupB.txt". But as I expected. it overwrites the file each time it opens up.
so now each output file only has one line of data from the last line of the sample output files.
so now the question is.......how's the command to tell the program to NOT overwrite what's in that file.



h: