Question
Working with Points and Structs (C Programming) Your code must use the following structure: struct point_struct { double xcoor; double ycoor; char label[25]; }; typedef
Working with Points and Structs (C Programming)
Your code must use the following structure:
struct point_struct {
double xcoor;
double ycoor;
char label[25];
};
typedef struct point_struct Point;
the following functions must be created:
Point getPoint(); // read in a point from the user (stdin)
double distance(Point pt1, Point pt2); // return the distance between pt1 and pt2
double slope(Point pt1, Point pt2); /* calculate the slope of the line starting at pt1 and going to pt2 */
void perpPoint (Point pt1, Point pt2, Point *pt3); /* calculate pt3 such that a line from pt1 to pt3 is perpendicular to the line from pt1 to pt2, and the distance between pt1 and pt2 is the same as the distance between pt1 and pt3 */ See the zylab for how the input will be formatted.
Grading: 10 points function getPoint (), 15 points function distance(), 15 points function slope(), 15 points function perpPoint(),
10 points create a main that has an array of 5 points and
- reads in 4 points from the user by calling getPoint 4 times
- displays the distance between the 1st and 2nd points, and the 3rd and 4th points
- displays the slope of the line between the 1st and 2nd points, and the 3rd and 4th points
- creates a 5th point by calling perpPoint() using the 1st and 2nd points
This is the format of the code.
#include
struct point_struct { double xcoor; double ycoor; char label[25]; }; typedef struct point_struct Point;
Point getPoint(); // read in a point from the user (stdin)
double distance(Point pt1, Point pt2); // return the distance between pt1 and pt2
double slope(Point pt1, Point pt2); /* calculate the slope of the line starting at pt1 and going to pt2 */ void perpPoint (Point pt1, Point pt2, Point *pt3); /* calculate pt3 such that a line from pt1 to pt3 is perpendicular to the line from pt1 to pt2 */
int main() {
Point anArray[5];
/* Type your code here. */
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started