Question: programming in c (15 pts) Write the statements to do the following: (10 pts) Define a struct with member variables width, height, topleft_x, topleft_y (all

programming in c

(15 pts) Write the statements to do the following:

(10 pts) Define a struct with member variables width, height, topleft_x, topleft_y (all floats). Use a tag to call it Rectangle.

(5 pts) Declare a variable called rect1 of struct type Rectangle.

(10 pts) Consider the following variables:

struct { int x; float y; char z;} var1;

union { int x; float y; char z[20]} var2;

If float and int are stored using 4 bytes each, what is the size (in bytes) for var1? What is the size of var2?

(30 pts) Consider the following code.

struct Triangle {

float side1;

float side2;

float side3} t1, t2;

enum Boolean {FALSE, TRUE};

enum Boolean isEquilateral(struct Triangle * triangle);

(15 pts) Implement the function isEquilateral which returns enum value TRUE if the given triangle is equilateral and enum value FALSE otherwise. (Hint: in the real world, no two float values are exactly the same. If the difference of two float values is between -0.0001 and 0.0001, consider almostEqual and neglect the minor difference.)

(6 pts) Assign values of your choice to member variables of t1 to 2.5, 4.5, and 4.5, respectively.

(4 pts) Call the function isEquilateral on triangle t1 and capture the returned value in variable result.

(5 pts) Copy the content from t1 to t2 without having to individually copy each member.

(10 pts) Give the output from the following program, either actual output or unpredictable.

typedef struct {

char name[20];

int grade1;

int grade2;

int finalGrade } Record;

void computeFinal(Record record) {

record.finalGrade = (record.grade1 + record.grade2)/2;

}

int main() {

Record std1 = {Mark, 81, 88, 0};

computeFinal(std1);

printf(Final Grade: %d, std1.finalGrade);

return 0;

}

(35 pts) Consider the Record structure declared in the previous exercise.

Add statements to do the following:

(5 pts) Declare a new Record variable std2:

(5 pts) Set the name of std2 to Jennifer;

(5 pts) Print the name of std2 to the standard output

(5 pts) Declare a pointer named ptr to Record and make it point to std2.

(5 pts) Use the pointer ptr to set grade1 of std2 to 76 using the arrow notation

(5 pts) Use the pointer ptr and the * operator to set the grade2 of std2 to 86

(5 pts) Update grade2 of std2 by reading a value into it from the standard input

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!