| | |
End of file function + Array
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
OK, Here we go.
The input file is:
2 40
3 80
6 50
1 15
2 70
And here's the result (WTH?):
=> The Attachment
And the codes:
The input file is:
2 40
3 80
6 50
1 15
2 70
And here's the result (WTH?):
=> The Attachment
And the codes:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() { ifstream infile("TEMPER.dat"); ofstream outfile("RESULT.dat"); int i=0; double x = 0.549; double P[1000], V[1000], T[1000]; cout<<"Case\t"<<"P(atm)\t"<<"V(l)\t"<<"T(K)"<<endl <<"----\t"<<"------\t"<<"-----\t"<<"----"<<endl; outfile<<"Case\t"<<"P(atm)\t"<<"V(l)\t"<<"T(K)"<<endl <<"----\t"<<"------\t"<<"-----\t"<<"----"<<endl; for (i=0; infile>>P[i]>>V[i]; i++) { infile>>P[i]>>V[i]; T[i]=((P[i]*V[i])/x); cout<<i+1<<"\t"<<P[i]<<"\t"<<V[i]<<"\t"<<T[i]<<"\t"<<endl; outfile<<i+1<<"\t"<<P[i]<<"\t"<<V[i]<<"\t"<<T[i]<<"\t"<<endl; } return 0; }
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
C++ Syntax (Toggle Plain Text)
double P[1000], V[1000], T[1000];
Next time try to use a STL vector for this . you can make a struct that contains int P , int V and int T and make a vector of that struct. And Feel free to use the STL libraries , they are implemented on many plactforms.
and you better using x like this
C++ Syntax (Toggle Plain Text)
const double x = 0.549;
Last edited by NicAx64; Mar 22nd, 2009 at 5:59 am.
Nothing like a kernel pannic !
•
•
•
•
C++ Syntax (Toggle Plain Text)
double P[1000], V[1000], T[1000];
Next time try to use a STL vector for this . you can make a struct that contains int P , int V and int T and make a vector of that struct. And Feel free to use the STL libraries , they are implemented on many plactforms.
and you better using x like this
C++ Syntax (Toggle Plain Text)
const double x = 0.549;
And as I said already, our tutor is a bit strict. For this assignment, we can't use STL library, dynmaic memory or ...
Any suggestion about the output? why is it only 3 and why random?
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
Great! Works like a charm. Thanks AncientDragon.
Now let's look at this one which is almost the same, but I'm getting only the first line.
This is Data.dat:
0 0
0.2 0.1
0.4 0.3
0.6 0.6
0.8 0.9
1.0 1.4
1.2 1.9
1.4 2.6
1.6 3.5
1.8 4.5
2.0 5.7
2.2 7.0
2.4 8.5
2.6 9.9
2.8 11.5
3.0 12.8
3.2 14.2
3.4 16.4
3.6 18.4
3.8 20.1
4.0 19.5
4.2 18.7
4.4 16.6
4.6 15.5
4.8 14.1
5.0 12.9
5.2 11.5
5.4 9.6
5.6 8.0
5.8 6.4
6.0 5.2
6.2 3.9
6.4 3.2
6.6 2.6
6.8 2.1
7.0 1.7
7.2 1.2
7.4 0.9
7.6 0.5
7.8 0.1
And the result:
=> The attachment
Now let's look at this one which is almost the same, but I'm getting only the first line.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> using namespace std; int main() { ifstream infile("Data.dat"); int t[1000], v[1000], x[1000]; int i=0; for (i=0; infile>>t[i]>>v[i]; i++) { x[i]=v[i]*t[i]; cout<<"The Displacement for t= "<<t[i]<<" and v= "<<v[i]<<" is: "<<x[i]<<endl<<endl; } return 0; }
This is Data.dat:
0 0
0.2 0.1
0.4 0.3
0.6 0.6
0.8 0.9
1.0 1.4
1.2 1.9
1.4 2.6
1.6 3.5
1.8 4.5
2.0 5.7
2.2 7.0
2.4 8.5
2.6 9.9
2.8 11.5
3.0 12.8
3.2 14.2
3.4 16.4
3.6 18.4
3.8 20.1
4.0 19.5
4.2 18.7
4.4 16.6
4.6 15.5
4.8 14.1
5.0 12.9
5.2 11.5
5.4 9.6
5.6 8.0
5.8 6.4
6.0 5.2
6.2 3.9
6.4 3.2
6.6 2.6
6.8 2.1
7.0 1.7
7.2 1.2
7.4 0.9
7.6 0.5
7.8 0.1
And the result:
=> The attachment
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
make the arrays float instead of int. ifstream is producing an error attempting to convert that decimal point to an int.
Last edited by Ancient Dragon; Mar 23rd, 2009 at 8:52 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Another thread solved by Ancient Dragon.
I wish you were our lecturer/ tutor.
I wish you were our lecturer/ tutor.
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
![]() |
Similar Threads
- Safe Array (C++)
- Programming in VBA reading file into dynamic array (VB.NET)
- Programming VBA: Reading excel into an Array (Visual Basic 4 / 5 / 6)
- How to read excel cells into Array (Visual Basic 4 / 5 / 6)
- Reading a file into a Parallel Array (C++)
- seek function (Perl)
- C++ complete binary tree using an array. Unexpected end file (C++)
- reading a file into code (Java)
- File parsing in 'C' (C)
Other Threads in the C++ Forum
- Previous Thread: Questions about memmove, malloc and realloc - C/C++ - Urgent
- Next Thread: opengl won't map textures
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple spoonfeeding string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






