Question

In: Computer Science

C++ The minimum function. (a) Write a function that takes two integers and returns the value...

C++ The minimum function.

(a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of the smaller one according to the less-than operation. Test the function in main() using the integer and character types.

Solutions

Expert Solution

a.#include<iostream.h>

using namespace std;

int min(int a,int b)

{

if(a<b)

return a;

else

return b;

}

int main()

{

int a=1;int b=4;

min(a,b);

int x=-100;int y=100;

min(x,y);

int e=7;int f=60;

min(e,f);

int m=1000;int n=50;

min(m,n);

int c=-50;int d=-90;

min(c,d);

return 0;

}

b)#include<iostream.h>

using namespace std;

char min(char a,char b);

{

if(a<b)

return a;

else

return b;

}

int main()

{

char x,y;

x='c';y='d';

min(c,d);

char m,n;

m='+';n='-';

min(m,n);

char c,d;

c='x';d='a;

min(c,d);

char u,v;

u='A';v='B';

min(u,v);

char e,f;

e='Y';f='Z';

min(e,f)_;

return 0;

}

c.#include<iostream.h>

using namespace std;

class Minimum

{

public:

int a,b;

void min()

{

if(a<b)

return a;

else

return b;

}

};

int main()

{

Minimum x;

x.a=5;x.b=6;

x.min();

Minimum m;

m.a=10;m.b=20;

m.min();

Minimum d;

d.a=-100;d.b=100;

d.min();

Minimum t;

t.a=-20;t.b=40;

t.min();

Minimum v;

v.a=-1000;v.b=-2000;

v.min();

return 0;

}


Related Solutions

C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
Write a recursive function named multiply that takes two positive integers as parameters and returns the...
Write a recursive function named multiply that takes two positive integers as parameters and returns the product of those two numbers (the result from multiplying them together). Your program should not use multiplication - it should find the result by using only addition. To get your thinking on the right track: 7 * 4 = 7 + (7 * 3) 7 * 3 = 7 + (7 * 2) 7 * 2 = 7 + (7 * 1) 7 *...
Write a Scheme function that takes two integers and returns the list of all integer numbers...
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20) Please explain every step.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Write a C function hwkOneA, that takes a long int x as well as two integers...
Write a C function hwkOneA, that takes a long int x as well as two integers n and m as arguments, and returns a long int. Here is the function declaration: long int hwkOneA (long int x, int n, int m); The function should swap nibble n and m of a long int x (64-bit integer). A nibble is a four-bit aggregation. For this problem, the index of the most significant nibble is 0, and the index of the least...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers called months and days to store the month and day of each date generated, a constant array of 12 integers called num_of_days that specify the number of days of each of the 12 months and an integer called size that specifies how many dates to generate and randomly generates size dates, storing the generated months in months array and generated days in days array....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT