Question

In: Computer Science

(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure...

(MUST BE DONE IN C (NOT C++))

Instead of using two different variables, define a structure with two members; one representing the feet and the other one representing the inches. You will also use three functions; one to initialize a structure, another one to check the validity of its values and one last one to print them out.

First, go ahead and define your structure. Next, declare a structure of this type inside main. Then, call your first function (this is a initialization function). This function will be of type structure, it will receive zero parameters and it will return a structure. Inside the function, ask the user for the height of the student. In other words, you will use this function to initialize the structure you have in main.

When done, call a second function (this is checking the function). To this function, you will send your structure. The function will not return anything and it will validate the values inputted by the user. If any of the values is not in the right range (between 5’ 8” and 7’ 7”), display an error message and exit the program. Make sure to also check for negative values.

Lastly, if the program didn’t exit, call the last function (this is printing the function). This function will receive a structure, it will not return anything and it will display the values of the two members of the structure.

Solutions

Expert Solution

Code is:

#include <stdio.h>

#include <stdlib.h>

struct st_size

{

int feet;

int inches;

};

struct st_size init_struct();

void check_struct(struct st_size in_struct);

void print_struct(struct st_size in_struct);

int main()

{

struct st_size struct1;

struct1 = init_struct();

check_struct(struct1);

print_struct(struct1);

return 0;

}

//function to assign structure

struct st_size init_struct()

{

struct st_size struct2;

printf("Please enter height of the student in feet and inches \n");

scanf("%d", &struct2.feet);

scanf("%d", &struct2.inches);

return struct2;

}

//function to check structure

void check_struct(struct st_size in_struct)

{

if (((in_struct.feet <= 5 ) && (in_struct.inches < 8 )) || ((in_struct.feet >= 7) && (in_struct.inches>7))||((in_struct.feet<0) || (in_struct.inches<0 )))

{

printf("Invalid height");

exit(0);

}

}

//function to print structure

void print_struct(struct st_size in_struct)

{

printf("Height entered is %d feet and %d inches",in_struct.feet,in_struct.inches);

}

Output:


Related Solutions

(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your...
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your program. Define each structure with exactly three members (each member has to be a different datatype). You may set them up whichever way you want. Don’t forget your semicolons. - Inside main, declare two structures. One for each of the two structures you defined. - Then, initialize each one of the members manually (the three members of your first structure and the three elements...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
1)define variables. 2)define functions. 3)define data structure.
1)define variables. 2)define functions. 3)define data structure.
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
You are required to use only C for this problem. To begin, instead of using two...
You are required to use only C for this problem. To begin, instead of using two different variables for this problem, you are going to define a structure with two members; one representing the feet and the other one representing the inches. We will also use three functions; one to initialize a structure, one to check the validity of its values, and the last one to print them out. First, define your structure. Next, declare a structure of this type...
* Discuss the two variables that must be considered whether you are using the present value...
* Discuss the two variables that must be considered whether you are using the present value of cash flow approach or the relative valuation ratio approach to valuation. Why are these variables relevant for either valuation approach? *Discuss the contention that differences in the performance of various firms within an industry limit the usefulness of industry analysis. Apa referencing required
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT