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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

Notice that a rectangle can be represented in a cartesian plane
by only having two points. Let's say we have the image below.
main.c
point.h x
rectangle.h
< > + c
1 // WARNING: Do not change this file.
// Doing so will nullify your score for the activity.
3- typedef struct {
int x;
int y;
6 } Point;
2
pt2
5
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_length method and (2) its
width in get_width method.
Input
1. Upper-Right Point'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
Transcribed Image Text:Notice that a rectangle can be represented in a cartesian plane by only having two points. Let's say we have the image below. main.c point.h x rectangle.h < > + c 1 // WARNING: Do not change this file. // Doing so will nullify your score for the activity. 3- typedef struct { int x; int y; 6 } Point; 2 pt2 5 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_length method and (2) its width in get_width method. Input 1. Upper-Right Point'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
main.c
point.h
rectangle.h x
1 // WARNING: Do not change this file.
2 // Doing so will nullify your score for the activity.
3 #include "point.h"
5- typedef struct {
Point upp_rig;
Point low_lef;
} Rectangle;
7
+
Transcribed Image Text:main.c point.h rectangle.h x 1 // WARNING: Do not change this file. 2 // Doing so will nullify your score for the activity. 3 #include "point.h" 5- typedef struct { Point upp_rig; Point low_lef; } Rectangle; 7 +
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY