-
uhhhhhh, what?
hi,
i'm still new to programming in C
and i don't know how to do this really complicated task
1. Use #define to set the value for PI=3.14159265359
2. Consider an ellipse in the x, y-plane. Let a be the semi-major axis
and b be semi-minor axis of the ellipse. The center of the ellipse
is located at (x0, y0). If the major axis coincides with the x-axis,
the polar representation of the ellipse is
x - x0=a cos(theta) and y-y0=b sin(theta) (1)
However, if the major axis of the ellipse is rotated by theta0 from
the x- axis in the counterclockwise direction, the x, y-coordinates
become
x = x0 + a cos(theta)cos(theta0)-b sin(theta)sin(theta0) (2)
y = y0 + a cos(theta)sin(theta0)+b sin(theta)cos(theta0) (3)
Create the void function:
void ellipse(double a, double b, double x0, double y0,
double theta0);
The input arguments are the semi-major axis a, the minor axis b,
the origin of the ellipse (x0, y0), and the tilt angle theta0
(in degrees) of the major axis from the x-axis.
In ellipse() compute and print (x, y) from theta=0 to 360 degrees
with the increment of 10 degrees. To print use %4d, %12.3e, and
%12.3e for theta, x, and y, respectively. Your output in ellipse()
should look like as follows:
-------------------------------
theta x-coord y-coord
-------------------------------
0 3.732e+00 2.000e+00
10 3.619e+00 2.135e+00
... ......... .........
360 3.732e+00 2.000e+00
3. In prob1(), call ellipse() for a=2.0, b=1.0, x0=2.0, y0=1.0,
theta0=30.0.
4. Copy "in_ellipse.dat" from the public directory to your directory
5. In prob2() define the file stream *infile to read "in_ellipse.dat"
6. In prob2() read "in_ellipse.dat" using fgets(). Print each line as
it is read.
7. Finally, print the total number of lines in the file.
and the in_ellipse.dat looks like this:
#Ellipse
#-------------------------------
#theta x-coord y-coord
#-------------------------------
0 3.732e+00 2.000e+00
10 3.619e+00 2.135e+00
20 3.457e+00 2.236e+00
30 3.250e+00 2.299e+00
40 3.005e+00 2.323e+00
50 2.730e+00 2.306e+00
60 2.433e+00 2.250e+00
70 2.123e+00 2.156e+00
80 1.808e+00 2.027e+00
90 1.500e+00 1.866e+00
100 1.207e+00 1.679e+00
110 9.378e-01 1.472e+00
120 7.010e-01 1.250e+00
130 5.036e-01 1.021e+00
140 3.518e-01 7.906e-01
150 2.500e-01 5.670e-01
160 2.014e-01 3.565e-01
170 2.074e-01 1.656e-01
180 2.679e-01 -1.179e-11
190 3.811e-01 -1.352e-01
200 5.434e-01 -2.359e-01
210 7.500e-01 -2.990e-01
220 9.946e-01 -3.227e-01
230 1.270e+00 -3.062e-01
240 1.567e+00 -2.500e-01
250 1.877e+00 -1.558e-01
260 2.192e+00 -2.652e-02
270 2.500e+00 1.340e-01
280 2.793e+00 3.208e-01
290 3.062e+00 5.282e-01
300 3.299e+00 7.500e-01
310 3.496e+00 9.794e-01
320 3.648e+00 1.209e+00
330 3.750e+00 1.433e+00
340 3.799e+00 1.643e+00
350 3.793e+00 1.834e+00
360 3.732e+00 2.000e+00
please help me!!!! i don't understand any of this...
-
Each of the assignments (or whatever) is given pretty much step by step. For 1, you just have to literally do what it says. For 2, they give you formulas and you have to type them in, pretty much literally as it looks (except for the implicit multiplication). For 3, 4, 5, 6, and 7, you just have to do literally what it says. (Edit: I guess 7 requires a small amount of work.) I suppose if you have questions on what some of the words mean, you can ask.
(And I guess I have to mention: this is pretty much the complete opposite of a "really complicated task".)
-
ok thanks
that helps a bit
and you might not think its hard
but i just don't get it
-
and how do you call ellipse() in prob1()?
right now the part of my code looks like this
void prob1(void)
{
int a, b, x0, y0, theta0;
(i think i have to call it here, how do i do that?)
return;
-
To call a function, you type its name, followed by a set of parentheses (). If the function requires arguments, then you put the arguments inside the parentheses.
-
i'm still having a lot of trouble...
i don't know where to put what
-
Code:
void prob1(void)
{
int a, b, x0, y0, theta0;
ellipse(); //(this is a comment btw) this line will pass processing and appear to 'jump' to what is in ellipse
}
this will only work if you have ellipse defined, above this function, i.e.
Code:
int ellipse(void){
printf("look!, we're here\n");
}
-
ahh
ok
i have another quick question
how would i do number 2?
it seems like i need an if else statement
or is that wrong?
this is what i have so far.
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359
void prob1(void);
void prob2(void);
void ellipse(double a, double b, double x0, double y0, double theta0);
int main(void)
{
int menu;
printf("\nThere are two parts.\n");
printf("Enter the part number to execute (1, or 2):");
scanf("%d", &menu);
switch(menu){
case 1:
prob1();
break;
case 2:
prob2();
break;
default:
printf("part %d does not exist.\n", menu);
}
exit(0);
}
void prob1(void)
{
int a, b, x0, y0, theta0;
ellipse();
return;
}
void ellipse(double a, double b, double x0, double y0, double theta0)
{
return;
}
void prob2(void)
{
FILE *infile;
infile = fopen("me9xaj", "r");
while(fgets(text,
return;
}
if this is wrong could you tell me what i need to change? thanks
-
If i were you I will properly indent the code and do code tags for the people around to properly and easily read your code.
-
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359
void prob1(void);
void prob2(void);
void ellipse(double a, double b, double x0, double y0, double theta0);
int main(void)
{
int menu;
printf("\nThere are two parts.\n");
printf("Enter the part number to execute (1, or 2):");
scanf("%d", &menu);
switch(menu){
case 1:
prob1();
break;
case 2:
prob2();
break;
default:
printf("part %d does not exist.\n", menu);
}
exit(0);
}
void prob1(void)
{
int a, b, x0, y0, theta0;
ellipse();
return;
}
void ellipse(double a, double b, double x0, double y0, double theta0)
{
return;
}
void prob2(void)
{
FILE *infile;
infile = fopen("me9xaj", "r");
while(fgets(text,
return;
}
is that ok? the formatting won't let me indent
please help me
i really don't get any of this.
-
one thing that's really bothering me is where do i put which functions?
i'm given four of them
-
just click the hash symbol when you're posting a code and arrange your code properly after that.. anyway I've seen your code you sure this is compiling successfully? looks like this will not compile successfully...
-
and how do i do the number 7? whats an infile?
-
i haven't even tried it yet to be honest
well, i just did
and i gave me a bunch of errors and stuff
this is so difficult
is it possible to ask if someone could do the code for me and then explain it?
-
Code:
void prob2(void)
{
FILE *infile;
infile = fopen("me9xaj", "r");
while(fgets(text,
return;
}
Before you proceed to 7 it would be better if you have to make sure that the code you posted is compiling successfully and specify what type of file you're trying to open and test it if it opened successfully or not.