Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions