Notice that a rectangle can be represented in a cartesian plane main.c point.h X rectangle.h by only having two points. Let's say we have the image below. 1 // WARNING: Do not change this fi 2 // Doing so will nullify your sco 3- typedef struct { int x; int y; 6 } Point; y 4. pt2 pt1 Using only the upper-right point p2 and the lower-left point p1, we can plot a rectangle, easy-peasy. With these two points -- each with an x- and y-coordinate -- we can calculate for a rectangle's length and width! Given two methods that take a rectangle pointer as their parameter, find (1) its length in get Jength method and (2) its width in get width method. Input 1. Upper-Right Polnt's X-Coordinate 2. Upper-Right Point's Y-Coordinate 3. Lower-Left Point's X-Coordinate 4. Lower-Left Point's Y-Coordinate Output The first few lines contain the message prompt for the inputs. The last lines will display the calculated length and width. UR'S X: 10 UR'S Y: 5 LL's X: 5 LL's Y: 2 Length: 5 Width: 3
Rectangle's Length and Width
Code in C language
// WARNING: Do not add, remove, or change anything before the line 19 of this file.
// Doing so will nullify your score for the activity.
#include <stdio.h>
#include "rectangle.h"
int get_length(Rectangle *rect);
int get_width(Rectangle *rect);
int main() {
int ur_x, ur_y, ll_x, ll_y;
printf("UR's X: ");
scanf("%d", &ur_x);
printf("UR's Y: ");
scanf("%d", &ur_y);
printf("LL's X: ");
scanf("%d", &ll_x);
printf("LL's Y: ");
scanf("%d", &ll_y);
// TODO: Initialize the points here
// Point ...
// TODO: Initialize the rectangle here
// Rectangle ...
// TODO: Call the get_length here
int len = ___;
printf("\nLength: %d", len);
// TODO: Call the get_width here
int wid = ___;
printf("\nWidth: %d", wid);
return 0;
}
// TODO implement get_length
int get_length(Rectangle *rect) {
return 0;
}
// TODO implement get_width
int get_width(Rectangle *rect){
return 0;
}
refer to pics for instructions
Step by step
Solved in 3 steps with 2 images