1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valentina_108 [34]
3 years ago
8

The ability to write functions is one of the more powerful capabilities in C++. Functions allow code to be reused, and provides

a mechanism for introducing the concept of modularity to the programming process. In addition to the concept of functions, C++ allows complex programs to be organized using header files (.h files) that contain the prototypes of functions and implementation files that (.cpp files) that contain the implementation (definition) of the functions.
In this programming assignment you will be asked to implement a number of useful functions using a header file and an implementation file. You will place the prototypes for your function in a .h file, and implement these functions in a .cpp file. You will need to write a driver (a program designed to test programs) to test your functions before you upload them.
[edit]Deliverables:
main.cpp
myFunctions.cpp
myFunctions.h
[edit]Function:
[edit]max
Precondition
two integer values exist
Postcondition
The value of the largest integer is returned.
The original integers are unchanged
If the integers have the same value then the value of either integer is returned.
Return
integer
Description
Function returns the value of the larger of two integers.
Prototype:
int max ( int, int )
Sample Parameter Values
m n max(m,n)
5 10 10
-3 -6 -3
Computers and Technology
1 answer:
Lunna [17]3 years ago
6 0

Answer:

The header file in C++ is as follows

myFunction.h

void max(int a, int b)

{

if(a>b)

{

 std::cout<<a;

}

else

{

 std::cout<<b;

}

<em>}</em>

The Driver Program is as follows:

#include<iostream>

#include<myFunction.h>

<em>using namespace std;  </em>

int main()

{

int m,n;

cin>>m;

cin>>n;

max(m,n);

<em>}</em>

Explanation:

It should be noted that, for this program to work without errors, the header file (myFunction.h) has to be saved in the include directory of the C++ IDE software you are using.

For instance; To answer this question I used DevC++

So, the first thing I did after coding myFunction.h is to save this file in the following directory  ..\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\

Back to the code

myFunction.h

void max(int a, int b)  {

-> This prototype is intialized with integer variables a and b

if(a>b)  -> If the value of a is greater than b;

{

 std::cout<<a;  -> then the value of variable a will be printed

}

else

-> if otherwise,

{

 std::cout<<b;

-> The value of b will be printed

}

}

Driver File (The .cpp file)

#include<iostream>

#include<myFunction.h>  -> This line includes the uesr defined header

using namespace std;  

int main()

{

int m,n;  -> Two integer variables are declared

      cin>>m;  -> This line accepts first integer input

      cin>>n;  -> This line accepts second integer input

max(m,n);

-> This line calls user defined function to return the largest of the two integer variables

}

You might be interested in
Long-term memory used by the computer:
Fynjy0 [20]
The long term memory used by the computer is called “RAM”
6 0
2 years ago
Read 2 more answers
Gemima's classmate Tristan sent her an Excel table that shows the amount of vitamin C in seafood. She wants to
Kipish [7]
Answer: Link and use destination styles

Explanation: First copy the table on Excel you want to include in Word, now go to your Word document and press Ctrl + V to paste the contents into the Word file. In order to link, you have to click on the Paste Options button at the bottom right and choose either Match Destination Table Style and Link to Excel or Keep Source Formatting and Link to Excel.
7 0
3 years ago
Read 2 more answers
How far away in hours is georgia from oklahoma?
Allushta [10]

Answer: car 15h 34m

hope this helps

3 0
3 years ago
Read 2 more answers
Each computer on a network requires a unique way to identify itself and to refer to other computers. This is accomplished by usi
monitta

Answer: True

Explanation: I would know i have gotten dosed plenty of times on video games

4 0
2 years ago
Read 2 more answers
How many cells are included in the range A1:B3
GenaCL600 [577]
Your answer would be 6 cells 

4 0
3 years ago
Other questions:
  • How long before a speech should you begin practicing?
    10·2 answers
  • Given two double variables, best value and second best value, write some code that swaps their values. declare any additional va
    13·1 answer
  • : How does the founder of Wikipedia keep a tight reign on accuracy? HELP PLEZ AT LEAST A PARGRAPH PLES
    6·1 answer
  • Write a basic program that performs simple file and mathematical operations.
    6·1 answer
  • Please Do Solve it guys...
    6·1 answer
  • Which code must be included to use Turtle Graphics?
    14·2 answers
  • Design an if-then statement ( or a flowchart with a single alternative decision structure that assigns 20 to the variable y and
    5·1 answer
  • "love takes off masks we fear we cannot live without and cannot live within" what is the meaning to this quote?​
    12·1 answer
  • HEEEEELPPP!!!BRAINLIEST!!! THIS IS URGENT!!!
    10·1 answer
  • 19) If you want to find your lowest paid, full time employee (with "FT" in column B and each employee's salary found in column C
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!