1.Create a funtion called sroot() in C++ language that returns the square root of its argument.Overload sroot() three ways: have it return the square root...

      

1.Create a funtion called sroot() in C++ language that returns the square root of its argument.Overload sroot() three ways: have it return the square root of an integer, a long integer, and a double.(use the sqrt() standard library fubction)

2.Create a function called min() in C++ language that returns the smaller of the two numeric arguments used to call the function.Overload min() so it accepts characters, integers, and doubles as arguments.

3.Create a function called sleep() using C++ language that pauses the computer for a number of seconds specified by its single argument.Overload sleep() so it can be called with an integer.Demonstrate that your function work by including them in a short program.

4.Write a C++ program using the I/O to input two integers from the keyboard and then display the result of raising the first to power of the second.Example if a user enters 2 and 4, the result is 2^4, or 16

  

Answers


Davis
1.#include
#include
using namespace std;
//overload sroot() for integer, longs, and doubles.
int sroot (int i);
long sroot (long i);
double sroot (double i);
int main()
{
cout << "Square root of 90.34 is: " << (sroot(90.34);
cout << "\n";
cout << "square root of 90L is: << sroot(90L);
cout << "\n";
cout << " Square root of 90 is: " << sroot (90);
return 0;
}
\\Return square root of an integer.
int sroot(int i)
{
cout << "computing integer root\n";
return (int) sqrt (( double) i);
}
\\Return square root of long.
long sroot (long i)
{
cout << "computing long root\n";
return (long) sqrt ((double) i);
}
\\Return square root of double.
double sroot (double i)
{
cout << "computing double root\n";
return sqrt(i);
}

2.//Overload the min() function.
include
#include
using namespace std;
char min(char a, char b);
int min (int a, int b);
double min (double a, double b);
int main()
{
cout << "Min is: "<cout << "Min is: "<< min(10, 20) << "\n";
cout <<"Min is: "<< min(0.2234, 99.2) << "\n";
return 0;
}
//min() for chars
char min(char a, char b)
{
return tolower(a)}
//min() for ints
int min(int a, int b)
{
return a}
//min() for doubles
double min(double a, double b)
{
return a}

3.#include
using namespace std;
//Overload sleep to accept integer or char * argument
void sleep(int n);
void sleep(char *n);
//Charge this value to fit your processor speed.
#define DELAY 100000
int main()
{
cout << '.';
sleep(3);
cout <<'.';
sleep("2");
cout << '.';
return 0;
}
//sleep() with integer argument.
void sleep(int n)
{
long i;
for( ; n; n--)
for(i=0; i}
//Sleep() with char * argument.
void sleep(char *n)
{
long i;
int j;
j = atoi (n);
for( ; j; j--)
for( i=0; i}

4.#include
using namespace std;

int main()
{
int b, e, r;
cout <<"Enter base: ";
cin >> b;
cout <<"Enter exponent: ";
cin >>e;
r = 1;
for ( ; e; e--) r=r *b;
cout << "Result: "<< r;
return 0;
}
Githiari answered the question on May 3, 2018 at 19:03


Next: Explain four factors influencing tax shifting
Previous: Write two ionic equations to show aluminium hydroxide as amphoteric

View More Computer Studies Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions