Question

In: Computer Science

Instead of using two different variables, however, we will define a structure with two members; one...

Instead of using two different variables, however, we will 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, 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 the main. Then, call your first function (the 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 the main. When done, call a second function (the checking 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 (the printing 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.

Use C code to solve this problem.

Solutions

Expert Solution

Code:

#include <stdio.h>
struct Height{
    int feet;
    int inches;
};

struct Height initializeStructure(){
    struct Height h;
    printf("Enter feet: ");
    scanf("%d", &h.feet);
    printf("Enter inches: ");
    scanf("%d", &h.inches);
    return h;
}

void verifyHeight(struct Height h){
    int inches = h.feet * 12 + h.inches;
    if(inches <= (5*12 + 8) || inches >= (7*12 + 7)){
        printf("Height entered is invalid");
        exit(0);
    }
}

void printHeight(struct Height h){
    printf("\nHeight:\tFeet = %d Inches = %d\n", h.feet, h.inches);
}

int main(){
    struct Height h1;
    h1 = initializeStructure();
    verifyHeight(h1);
    printHeight(h1);
    return 0;
}

Output:


Related Solutions

(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...
Run two different multiple regressions using excel. One should include two of the three idepenedent variables...
Run two different multiple regressions using excel. One should include two of the three idepenedent variables and the other should include all three variables. What are the regession equations? Years Weekend Daily Tour Income Daily Gross Revenue Number of Tourists 1 Friday 3378 4838.95 432 1 Saturday 1198 3487.78 139 1 Sunday 3630 4371.3 467 2 Friday 4550 6486.48 546 2 Saturday 2467 3437.39 198 2 Sunday 3593 4571.43 452 3 Friday 898 2515.15 119 3 Saturday 2812 5462.11 342...
Run two different multiple regressions using excel. One should include two of the three idepenedent variables...
Run two different multiple regressions using excel. One should include two of the three idepenedent variables and the other should include all three variables. The first multiple regression equation is Gross Revenue = 766.981 + 2.977*Daily Tour Income - 12.31*Number of Tourists. 1. What is the second multiple regression equation?   Would adding dummy variables for the three days for my second regression work? l  need 2 dummy variables since I have 3 categories (days, in this case). What would the equation...
1)define variables. 2)define functions. 3)define data structure.
1)define variables. 2)define functions. 3)define data structure.
Define three integer variables (number1, number2, and number3). We also define two other storage spaces for...
Define three integer variables (number1, number2, and number3). We also define two other storage spaces for storing sum as well as averageValue. The storage space (sum) is used to store the sum of three integer numbers. The storage space (averageValue) is used to store the average of the three numbers. ***************************************************************************************/ #include <stdio.h> // standard input and output functions library #include <stdlib.h> // include library to execute command (system ("pause"); ) /* The purpose of this program is to calculate...
Define different type of sampling and measurement of variables? ( with example) ?
Define different type of sampling and measurement of variables? ( with example) ?
1. We define the activity of pure liquids as 1 to define the standard state. However,...
1. We define the activity of pure liquids as 1 to define the standard state. However, this is an arbitrary choice. Find the dissociation constant, K, for the autoprotolysis of pure water using the molarity standard state for water (i.e. defining the activity as 1 for a water concentration of 1 mol/l). You may take the density of water to be 1.0 g/ml. 2.   Will K have the same value in this standard state at 60?C?   
What is a demographic variable? Using race and social class as two major demographic variables, define...
What is a demographic variable? Using race and social class as two major demographic variables, define each and explain the consequences of developing notions of race and social class.
In C++, 
 Define a structure Triangle that contains three Point members. Write a function that computes...
In C++, 
 Define a structure Triangle that contains three Point members. Write a function that computes the perimeter() of a Triangle. Write a program that reads the coordinates of the points, calls your function, and displays the result. C++
The organic layer can also be extracted with NaOH (aq) instead of using potassium carbonate. However,...
The organic layer can also be extracted with NaOH (aq) instead of using potassium carbonate. However, sometimes, initially two layers form in the separatory funnel when the base is first added to the organic layer. But during extraction, the solution has been reported to become warm. When the separatory funnel is put back into the ring stand to let separation occur, no separation is observed not even after standing for 5 minutes. What happened? Explain using a chemical reaction.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT