Netid: ___________________ Section: ____________
Print out this page and fill in the blanks to answer the following questions. Hand in this assignment at the beginning of Lab 12. You should use the material found in Lecture 19&20 and 21 of the course notes. As with all prelabs/labs, if you are not sure of the answer you may go to any EWS lab on campus and check your results by using the gcc compiler, or you can ask anyone of the CS101 staff for help.3. In this problem, you are going to use
functions from math library. You will need to know how to make eclipse
able to compile functions in the math library. To do this perform the
steps shown below:
open eclipse, create a new project lab12 as managed c project, right
click on lab12, on the property item, you will see this

then you select "C/C++ Build", in "Tool
Settings" you select "GCC C Linker", then select "Libraries"

then click on "+" (find Libraries (-l) and look immediately to the
right)

in "Enter Value", just enter "m"
Click on "OK" to finish this setup, ready to deal with
this problem 3:
Complete the code for the function
named convert that converts points in polar coordinates to points in
cartesian coodinates by means of the formula,
x
= radius * cos(theta)
y = radius *
sin(theta)
When your code is including in the following program you should obtain the output shown below.
#include <stdio.h>
#include <math.h>
typedef struct {
double x;
double y;
} cartesian;
typedef struct {
double radius;
double theta;
} polar;
cartesian convert( polar point)
{
cartesian p;
___________________________________
___________________________________
return p;
}
void main(void)
{
polar point = { 1.0 , 3.141592653589793 / 4 };
cartesian p ;
p = convert(point);
printf(" x = %lf , y = %lf \n", p.x , p.y);
}
which should display
x =
.707107 y = .707107
6. When using the conversion specifier %s,
scanf()
ignores all leading spaces and reads until the next space. However, scanf()
will continue to read even if it goes past the end of a character array
if no space is reached. Another problem with %s is that we cannot read
more than one word at a time since the space character serves as a
delimiter. To fix this problem (only for reading strings) we will
use the brackets conversion specifier %[ ], consult page 498 of Applied
C for more information.
Inside the brackets we will use the special symbol '^' meaning NOT. For
example, %[^;]; then the [^ ; ] part means read all
characters (including blanks) while the character is NOT ; (and
therefore
stop reading when the next character is a ; ) and the ;
outside the [^ ;]; means read and discard the next ;.
For example, if we declared,
char artist[40];
char song_name[40];
char album_title[40];
int track_length;
The Beatles; 214
scanf(" %[^;]; %i", artist, &track_length);
Complete the following C program to read in
The Beatles; The Long and Winding Road; Let It Be... Naked; 214