Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write the statements to do the following: (2 pts) a. Define a struct with mem

ID: 3821966 • Letter: 1

Question

1. Write the statements to do the following: (2 pts) a. Define a struct with member variables width, height, topleft x, topleft y all floats). Use a tag to call it Rectangle. b. Declare a variable struct type Rectangle 2. Consider the following variables: struct int x; float y; char zi var1; union nt x; float y; char[20] z;) var2 f float and int are stored using 4 bytes each, what is the size (in bytes) for var1? What is the size of var2? (2 pts) 3. Consider the following code struct Triangle float side 1; float side2 float side3 t1, t2; num Boolean (FALSE, TRUE enum Boolean isEquilateral(struct Triangle triangle); a. Implement the function isEquilateral which returns enum value TRUE if the given triangle is equilateral and enum value FALSE otherwise. (2 pts) b. Assign values of your choice to member variables of t1 (1.5 pts c. Call the function isEquilateral on triangle t1 and capture the returned value in variable result. (1 pt) d. Copy the content from t1 to t2 without having to individually copy each member. (1 pt)

Explanation / Answer

1.
struct Rectangle{
float width;
float height;
float topleft_x;
float topleft_y;
};

struct Rectangle rect;

2.
size of var1 = 9 bytes
size of var2 = 20 bytes (Union takes up the size of the biggest element)

3.
a.enum Boolean IsEquilateral(struct Trianle *triangle){
    if (triangle->side1 == triangle->side2 && triangle->side2 == triangle->side3){
       return TRUE;
    }
    else {
       return FALSE;
    }
}

b. t1.side1 = 5.0;
   t1.side2 = 5.0
   t1.side3 = 5.0
c.
   declare a variable of type enum Boolean as follows:
   enum {TRUE, FALSE} result;
   result = IsEquilateral(&t1);

d. t2 = t1;

4.
The output is 84

5.
struct Record std2;
std2.name = "Jennifer";
printf("%s", std2.name);
struct Record *rec;
rec = &std2;
rec->grade1 = 76;
(*rec).grade2 = 86;
scanf("%d", &(*rec).grade2);