Question

In: Computer Science

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 inside main. Then, call your first function (the initialization function). This function will be of a type structure, it will receive zero parameters, and it will return a structure. Inside the function, you will ask the user for the height of the student. To clarify, you will use this function to initialize the structure you have in main.

After that, call a second function (the checking function). In 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” of the student height), your program will display an error message and your program will then exit. Oh and do make sure to also check for negative values. That'll be important.

With all that done, 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. Good luck!

Solutions

Expert Solution

#include <stdio.h>

//Structure declaration for the valid height
struct Valid_height {
int feet;
int inch;
};

//Struct Function prototype for initialization
struct Valid_height getStudentDetail();
//Struct Function prototype for Validation
void validate_student_detail(struct Valid_height student_height);
//Struct Function prototype for Printing
void print_student_detail(struct Valid_height student_details);

int main() {
struct Valid_height Student1;
Student1 = getStudentDetail();
validate_student_detail(Student1);
print_student_detail(Student1);

return 0;
}

//Struct Function definition for initialization
struct Valid_height getStudentDetail()
{
struct Valid_height s1;
printf("Enter the student height details in feet and inches\n");
printf("Enter Student height in feet: ");
scanf("%i", &s1.feet);
printf("Enter Student height in inches: ");
scanf("%i", &s1.inch);
  
return s1;
}  

//Struct Function definition for validation
void validate_student_detail(struct Valid_height student_height)
{
printf("In the validate student function\n");
//Handle the feet to inches conversion for valid height
float valid_inches;
float total_feet;
int quotient;
valid_inches = student_height.inch % 12;
quotient = student_height.inch / 12;
total_feet = (valid_inches/12);
student_height.feet = quotient + student_height.feet;
total_feet = student_height.feet + total_feet;
printf("The Student height in feet: %f\n", total_feet );
if (total_feet < 5.6667 || total_feet >= 7.58333)
{
printf("Student height not in expected range between 5’ 8” and 7’ 7” \n");
exit(0);
}
  
}

//Struct Function definition for printing
void print_student_detail(struct Valid_height student_details)
{
//Handle the feet to inches conversion for valid height
float valid_inches;
int quotient;
valid_inches = student_details.inch % 12;
quotient = student_details.inch / 12;
student_details.inch = valid_inches;
student_details.feet = quotient + student_details.feet;
printf("The Student height in feet: %i\n", student_details.feet );
printf("The Student height in inches: %i\n", student_details.inch );
}


Related Solutions

This problem requires you to use a heap to store items, but instead of using a...
This problem requires you to use a heap to store items, but instead of using a key of an item to determine where to store the item in the heap, you need to assign a priority (key) to each item that will determine where it is inserted in the heap a) Show how to assign priorities to items to implement a first-in, first-out queue with a heap. b) Show how to assign priorities to items to implement a first-in, last-out...
Instead of using int.TryParse, use int.Parse instead and use try/catch in C# to handle possible errors...
Instead of using int.TryParse, use int.Parse instead and use try/catch in C# to handle possible errors using System; using System.Collections.Generic;                    public class Program {    public static void Main()    {        List<int> list = new List<int>();               Console.WriteLine("Please input integers: (in one line)");                      string input = Console.ReadLine();        string[] tokens = input.Split(); // split string into tokens "12 13 10" -> "12" "13"...
Begin by re-writing the problem.  Minitab is required; attach or include your output. Use Word; you may...
Begin by re-writing the problem.  Minitab is required; attach or include your output. Use Word; you may handwrite equations. You may want to refer to the Minitab handout for Chapter 11, which may be found on Canvas. Quarterly GPAs are compared for seven randomly chosen students in each of the four business majors at Catalyst University. Do the data show a significant difference in mean GPAs?  The data is in the file named GPA1. GPA for Randomly Selected Students in Four Business...
(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...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. Semester GPAs are compared for seven randomly chosen students in each class level at Oxnard University. Do the data show a significant difference in mean GPAs? GPA for Randomly Selected Students in Four Business Majors Accounting Finance Human Resources Marketing 2.48 3.16 2.93 3.54 2.19 3.01 2.89 3.71 2.62 3.07 3.48 2.94 3.15 2.88 3.33 3.46 3.56 3.33...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. 1) Are women's feet getting bigger? Retailers in the last 20 years have had to increase their stock of larger sizes. Wal-Mart Stores, Inc., and Payless ShoeSource, Inc., have been aggressive in stocking larger sizes, and Nordstrom's reports that its larger sizes typically sell out first.  Twelve women from each age group were randomly selected and their shoe sizes...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. 1) Are women's feet getting bigger? Retailers in the last 20 years have had to increase their stock of larger sizes. Wal-Mart Stores, Inc., and Payless ShoeSource, Inc., have been aggressive in stocking larger sizes, and Nordstrom's reports that its larger sizes typically sell out first.  Twelve women from each age group were randomly selected and their shoe sizes...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab18 is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. 1) In preliminary tests of a vaccine that may help smokers quit by reducing the “rush” from tobacco, 180 subjects who wanted to quit smoking were either given a placebo or the vaccine. Of the 90 in the placebo group, only 10 quit smoking compared with 25 of the vaccine group. (15 points) a) At the .10 level...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. Semester GPAs are compared for seven randomly chosen students in each class level at Oxnard University. Do the data show a significant difference in mean GPAs? GPA for Randomly Selected Students in Four Business Majors Accounting Finance Human Resources Marketing 2.48 3.16 2.93 3.54 2.19 3.01 2.89 3.71 2.62 3.07 3.48 2.94 3.15 2.88 3.33 3.46 3.56 3.33...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word)...
Begin by re-writing the problem. Minitab is required; attach or include your output. Type (use Word) your assignment; you may handwrite equations. Semester GPAs are compared for seven randomly chosen students in each class level at Oxnard University. Do the data show a significant difference in mean GPAs? GPA for Randomly Selected Students in Four Business Majors Accounting Finance Human Resources Marketing 2.48 3.16 2.93 3.54 2.19 3.01 2.89 3.71 2.62 3.07 3.48 2.94 3.15 2.88 3.33 3.46 3.56 3.33...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT