Question

In: Computer Science

A person writes a project with unit conversion functions, although she doesn’t use all of them....

A person writes a project with unit conversion functions, although she doesn’t use all of them. The conversions would be useful in a library. Create the library and modify the main.c to use the library. What is the name of your library?

#include <stdio.h> // has printf()

float inches2metres(float length_in_inches);

float metres2inches(float length_in_metres);

float pounds2kg(float weight_in_pounds);

float kg2pounds(float mass_in_kg);

float hours2seconds(float time_in_hours);

float seconds2hours(float time_in_seconds);

int main(void){

int i;

float speed_mperhour, speed_inchespersec;

printf(“speed (km/hr)        speed (in/sec) \n\r”);

for (i=1; i<=100;i++)

{

      speed_inchespersec = metres2inches(i*1000.0)/hours2seconds(1.0);

      printf(“%f          %f \n\r”, i, speed_inchespersec);

}

return 0;

float inches2metres(float length_in_inches){

return (length_in_inches * 0.0254); // answer in metres

float metres2inches(float length_in_metres){

return (length_in_metres * 39.3701); // answer in inches

float pounds2kg(float weight_in_pounds){

return (weight_in_pounds * 0.453592); // answer in kilograms

float kg2pounds(float mass_in_kg){

return (mass_in_kg * 2.20462) // answer in pounds

float hours2seconds(float time_in_hours){

return (time_in_hours * 3600.0) // answer is seconds

float seconds2hours(float time_in_seconds){

return (time_in_seconds / 3600.0) // answer is hours

Solutions

Expert Solution

To create a library we first need to

1. create a header file which contains function prototypes
2. create a source file which contains the implementation of all these functions
3. Create library object file which can then be used in other programs

Below we first create header file mylib.h then implementation file mylib.c and the create object file and then use this library in main function


// Header file
#ifndef _MYLIB_H_
#define _MYLIB_H_

  
// function prototype for different functions exported by this library:
   float inches2metres(float length_in_inches);
   float metres2inches(float length_in_metres);
   float pounds2kg(float weight_in_pounds);
   float kg2pounds(float mass_in_kg);
   float hours2seconds(float time_in_hours);
   float seconds2hours(float time_in_seconds);

#endif


// Implementation file mylib.c

#include "mylib.h"

float inches2metres(float length_in_inches)
{
return (length_in_inches * 0.0254); // answer in metres
}
float metres2inches(float length_in_metres)
{
return (length_in_metres * 39.3701); // answer in inches
}
float pounds2kg(float weight_in_pounds)
{
return (weight_in_pounds * 0.453592); // answer in kilograms
}
float kg2pounds(float mass_in_kg)
{
   return (mass_in_kg * 2.20462) // answer in pounds
}
float hours2seconds(float time_in_hours)
{
   return (time_in_hours * 3600.0) // answer is seconds
}
float seconds2hours(float time_in_seconds)
{
   return (time_in_seconds / 3600.0); // answer is hours
}

// Create library object file

gcc -o mylib.o -c mylib.c

// Use mylib.h in main function

#include <stdio.h> // has printf()
#include "mylib.h" // importing functions defined in mylib.c library


int main(void){
int i;
float speed_mperhour, speed_inchespersec;
printf(“speed (km/hr) speed (in/sec) \n\r”);
for (i=1; i<=100;i++)
{
speed_inchespersec = metres2inches(i*1000.0)/hours2seconds(1.0);
printf(“%f %f \n\r”, i, speed_inchespersec);
}
return 0;


Related Solutions

A person writes a project with unit conversion functions, although she doesn’t use all of them....
A person writes a project with unit conversion functions, although she doesn’t use all of them. The conversions would be useful in a library. Create the library and modify the main.c to use the library. What is the name of your library? C PROGRAMMING #include <stdio.h> // has printf() float inches2metres(float length_in_inches); float metres2inches(float length_in_metres); float pounds2kg(float weight_in_pounds); float kg2pounds(float mass_in_kg); float hours2seconds(float time_in_hours); float seconds2hours(float time_in_seconds); int main(void){ int i; float speed_mperhour, speed_inchespersec; printf(“speed (km/hr)        speed (in/sec) \n\r”); for...
Although the Bank of Canada doesn’t use changes in reserve requirements to manage the money supply,...
Although the Bank of Canada doesn’t use changes in reserve requirements to manage the money supply, the central bank of Albernia does. The commercial banks of Albernia have $100 million in reserves and $1000 million in chequable deposits; the initial required reserve ratio is 10%. The commercial banks follow a policy of holding no excess reserves. The public holds no currency, only chequable deposits in the banking system. a) How will the money supply change if the required reserve ratio...
For the Assembly Department, unit materials cost is $4 and unit conversion cost is $8. All...
For the Assembly Department, unit materials cost is $4 and unit conversion cost is $8. All material costs are added at the beginning of the process and conversion costs are applied uniformly throughout the process. If there are 9900 units in ending work in process 65% complete as to conversion costs, the costs to be assigned to the ending inventory are A.$77220. B.$118800. C.$91080. D. $104940.
if one of the lobes of the cerebrum were damaged, would the person lose all functions...
if one of the lobes of the cerebrum were damaged, would the person lose all functions of that lobe?
Although 90% of all desktop computers use Windows as their operating system, there are two popular...
Although 90% of all desktop computers use Windows as their operating system, there are two popular alternatives - Apple's Mac OS and the Linux open-source operating system. In this assignment, you will investigate an operating system other than the one you usually use to see how it handles common operating system functions. Note: A popular Linux OS is Ubuntu (As an open-source operating system it is FREE). If you choose to test Linux you can use this link for easy...
Use R functions search and objects to find all possible R built-in functions related to exp...
Use R functions search and objects to find all possible R built-in functions related to exp distribution. rexp should be one of them. dexp is another one. Explain what the following two lines of codes do: curve(dexp, from=0, to=4)
Following are the most important file management functions available in C. Use any 6 of them...
Following are the most important file management functions available in C. Use any 6 of them in your program and show the output. Function purpose fopen () Creating a file or opening an existing file fclose () Closing a file fprintf () Writing a block of data to a file fscanf () Reading a block data from a file getc () Reads a single character from a file putc () Writes a single character to a file getw () Reads...
B. MONOPOLY A corporation buys up all the individual one-person businesses and operates them as one...
B. MONOPOLY A corporation buys up all the individual one-person businesses and operates them as one corporation. The individuals work for the corporation as employees. There is now one corporation (Washington Physical Therapy Company) providing this service to everyone in the metropolitan area.   Technology and the actual services do not change. For the Corporation: Fixed cost per day: $4,000 (this is 100 times $40) Variable cost per day for the Company (travel, supplies, etc.) based on existing operations of all...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array to test, thanks. get_location_of_min This function takes a matrix as a 2-D array of integers with NUM_COLS width, the number of rows in the matrix and two integer pointers. The function finds the location of the minimum value in the matrix and stores the row and column of that value to the memory location pointed to by the pointer arguments. If the minimum value...
Describe the role(s) and functions of a project manager. Use your own personal experiences to describe...
Describe the role(s) and functions of a project manager. Use your own personal experiences to describe why these are important. Your answer should be no shorter than three typed pages. And, you must cite information from ALL thirteen chapters of the book (even the ones we did not specifically cover in class). For example, a project manager must effectively communicate with team members (ch.1) *I dont expect anyone to write anywhere near 3 pages for me, but if you really...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT