Hey everybody,
I need some help here. I have to create a project to plot Cartesian graphs. Until now i am using c++ to calculate the Cartesian coordinates, but i need further development. I enter a loop where my x coordinate every time adds 0.1, and the corresponding y coordinate for the given equation is created.
I have an equation :-
100y+22.09x=2209
and, my code goes as given below. Sample output, of first 6 x and y coordinates is also given (here also i had to type all the values)
But i need to get this information out of c++. Until now, i have to copy all the coordinates one by one. i need a tag which could export this info in another form, like word doc, or spreadsheet(x coordinate and y coordinate as 2 separate columns).
Please help.
x coordinate = 0
y coordinate = 4.7
x coordinate = 0.1
y coordinate = 4.699765
x coordinate = 0.2
y coordinate = 4.69906
x coordinate = 0.3
y coordinate = 4.697885
x coordinate = 0.4
y coordinate = 4.696238
x coordinate = 0.5
y coordinate = 4.694121
NwN,
I am not very Good at c++. I did not fully understand ur answer. I need more explained answer.
so, according to you, in my code, i should write like this:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
double i,a,b,e,y2;
//the values of a and be a are are already inputed by the user in the earlier phase of my code
for (i=0;i<10;i=i+0.1)
{
cout<<"\n\nX coordinate = "<<i;
y2=((a*b)-(b*i*i))/a;
e=sqrt(y2);
cout<<"\nY coordinate = "<<e;
getch();
}
std::ifstream ifs("coordinates.csv");
ifs << x << "," << y << "\r\n";
getch();
}
Would this create this "coordinates,csv" in its main folder, every time i run the software and it calculates the required result?
And also please tell if any libraries are required to mention
I am asking cause i didnt understand the wiki u have mentioned
Also, you shouldn't use FP numbers in a loop. They are not exact. Instead calculate the number of times the loop needs to run, and convert that to an int. Should be easy (EndValue - StartValue) / StepValue, so for you this (10.0 - 0.0) / 0.1 = 100.0. Use static_cast<int> to do the casting.
So use ints as variable types in the for loop, but double types inside the loop.