Question

Write the header file true.h for the source code file true.c such that Tread, Nice and...

Write the header file true.h for the source code file true.c such that Tread, Nice and GetStatus and Math can be used in other source code files by including foo.h. This only requires a few lines of C code at most.

uint16_t Nice;

const uint32_t Tread = 7;

int8_t GetStatus() {

return (IO_STUFF -> STATUS);

}

uint32_t Math (uint32_t N) {

if (N< 2) return (N);

else return (Math(N-1) + Math(N-2));

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

If you want to make some variables and functions common for all. Then you use a "header file"

you can use the following approach :-

prepare 2 files :

1. header file

2. c file that uses this header file

myheader.h

#include <stdint.h>
// Include stdint.h in the header file since we are using uint typedefs

// variable Nice of type uint16_t
uint16_t Nice;

// function square that takes a uint16_t and returns a uint32_t
uint32_t square(uint16_t num){
return num*num;
}

// recursive function fib that is used to get the fibonacci number at Nth position
uint32_t fib (uint32_t N) {
if (N< 2) return (N);
else return (fib(N-1) + fib(N-2));
}

and

main.c

#include <stdio.h>
#include "myheader.h"
// include your header file

int main ()
{
// use the functions and variables of the header file directly
printf("%d", square(5));
printf("\n%d", Nice);
printf("\n%d", fib(4));
printf("\n%d %d %d %d", fib(0), fib(1), fib(2), fib(3));
return 0;
}

I hope I answered your question. If you need more information , feel free to comment below.

Thanks !

Add a comment
Know the answer?
Add Answer to:
Write the header file true.h for the source code file true.c such that Tread, Nice and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Refer to this header file: // Fraction class // This class represents a fraction a /...

    Refer to this header file: // Fraction class // This class represents a fraction a / b class Fraction { public: // Constructors Fraction(); // sets numerator to 1 and denominator to 1 Fraction(int num, int denom); // Setters void setNumerator(int num); void setDenominator(int denom); // getters int getNumerator()const {return num;} int getDenominator()const {return denom;} double getDecimal(){return static_cast<double> num / denom;} private: int num, denom; }; 1.Write the code for the non-member overloaded << operator that will display all of...

  • I was wondering how to do the following. This will all be in a header file...

    I was wondering how to do the following. This will all be in a header file to be called in a .cpp file. They all have to be template functions because the .cpp file will test a few different values for each function. This should be done in C++ ====== Write a variadic template for a function named problem5 that joins an arbitrary number of strings together. This function will serve as the terminating case for two strings and your...

  • Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Operator...

    Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Operator Overloading – Chapter 14 Design a class Complex for representing complex numbers and the write overloaded operators for adding, subtracting, multiplying and dividing 2 complex numbers. Also create a function that will print a complex number on the screen. Provide appropriate constructors...

  • Error: Unable to save the file in the folder...... Whats is wrong with this code.? The...

    Error: Unable to save the file in the folder...... Whats is wrong with this code.? The below code checks for the HTTP/1.1 200 OK. and if its true it divides tha pathname and hostname and after first slash in the pathname, it saves as the downloading link and have to save in the folder. but it 's not getting saved... int bytes sent; bytes sent send(sockfd, request strlen(request),0) int byte received; char buffer 10000J; bzero buffer 10000); //to make sure...

  • Linux & Unix Write a bash program to indent the code in a bash source file....

    Linux & Unix Write a bash program to indent the code in a bash source file. Conditions:     The source file will contain only printing characters, spaces, and newlines. It is not necessary to check for invalid input.     The source file will not contain comments (words beginning with #). Requirements:     Read from standard input, write to standard output.     Code inside while statements should be indented 2 spaces. Be sure your program includes all of the following:    ...

  • Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Template...

    Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Template Classes – Chapter 12 Write an example of a template function that can swap 2 generic elements. Create a C++ class vector using the class diagram shown in Figure 12.2. in Liangs textbook. Do not use the C++ provided header file <vector>...

  • Please don't use a void fuction and this is a c++ question. Thanks Write a program...

    Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...

  • Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 file...

    Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Operator Overloading – Chapter 14 Design a class Complex for representing complex numbers and the write overloaded operators for adding, subtracting, multiplying and dividing 2 complex numbers. Also create a function that will print a complex number on the screen. Provide appropriate constructors...

  • .Your solution must include header, implementation file, and test files .In C++ write a code to...

    .Your solution must include header, implementation file, and test files .In C++ write a code to Consider a graphics system that has classes for various figures rectangles, squares, triangles, circles, and so on. For example, a rectangle might have data members for Height, Width and center point, while a square and circle might have only a center point and an edge length or radius. In a well-designed system, these would be derived from a common class, Figure. You are to...

  • In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The...

    In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The class a CashRegister class has the following data members: 1) an array of 100 Item objects. 2) Cash Register Name and 3) Count of Item objects purchased. 4) Item Cash Total 5) State Tax Rate. The Item is represented as a class in an item.h file. The Item class has the following data members: 1) Name of the item 2) Cost of the item....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT