Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 6: Functions Problem Number: 11082 Write the definition of a function na

ID: 3580394 • Letter: C

Question

Chapter 6: Functions

Problem Number: 11082

Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then the function prints the message "no solution for a=0" and returns. If the value of "b squared" – 4ac is negative, then the code prints out the message "no real solutions" and returns. Otherwise the function prints out the largest solution to the quadratic equation.

Problem Number: 10637

Write the definition of a function max that has three int parameters and returns the largest.

Problem Number: 11084

Write the definition of a function named newbie that receives no parameters and returns true the first time it is invoked (when it is a "newbie"), and that returns false every time that it is invoked after that.

Problem Number: 11092

Write the definition of a function named rotate4ints that is passed four int variables. The function returns nothing but rotates the values of the four variables: the first variable, gets the value of the last of the four, the second gets the value of the first, the third the value of the second, and the last (fourth) variable gets the value of the third. So, if i, j, k, and m have (respectively) the values 15, 47, 6 and 23, and the invocation rotate4ints(i,j,k,m) is made, then upon return, the values of i, j, k, and m will be 23, 15, 47 and 6 respectively.

Problem Number: 11090

Assume that a function named swapdoubles has been defined and is available for use in this exercise: that function receives two variables of type double and exchanges their values. Write the definition of a function named sort3 that is passed three double variables. The function returns nothing but modifies the values of these variables so they are in sorted order. So, if a, b and c have (respectively) the values 3.14, 2.71, and 3.04, and the invocation sort3(a,b,c) is made, then upon return, the values of a, b and c will be 2.71, 3.04, and 3.14 respectively.

Problem Number: 11093

Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of the two values. Define one of these functions to apply to type double, another to type int and a third to type char.

Problem Number: 11094

Write the definition of a function named panic. The function prints the message "unrecoverable error" and then terminates execution of the program, indicating failure..

Problem Number: 11094

Assume you need to test a function named inOrder. The function inOrder receives three int arguments and returns true if and only if the arguments are in non-decreasing order: that is, the second argument is not less than the first and the third is not less than the second. Write the definition of driver function testInOrder whose job it is to determine whether inOrder is correct. So testInOrder returns true if inOrder is correct and returns false otherwise.

For the purposes of this exercise, assume inOrder is an expensive function call, so call it as few times as possible!

Problem Number: 10803

Assume that x is a variable that has been declared as an int and been given a value. Assume that oneMore is a function that receives a single integer parameter and returns a value that is one greater than its argument. (So if you pass 7 to oneMore it will return 8. Thus, the expression oneMore(9) has the value 10.

Write an expression whose value is four more than x without using the standard C++ arithmetic operators (*,+, etc.). Instead, use calls to oneMore to accomplish this.

In this exercise you must write this as a single expression -- you must not write any statements. Also, you may only use the oneMore function-- no other functions or operators.

Explanation / Answer

Problem Number: 11082

#include<iostream.h>
#include<conio.h>
void quadratic(double a,double b,double c);
int main()
{
   double a,b,c;
   clrscr();
   char ch[100];
   cout<<"Enter a,b,c values:"<<endl;
   cin>>a>>b>>c;
   quadratic(a,b,c);
   getch();
   return 0;
}
void quadratic(double a,double b,double c)
{
   double det;
   det=(b*b)-(4*a*c);
   char ch[500];
   if(a==0.0)
   {
   cout<<"no solution for a=0";

   }
   else if(det<0.0)
   {
   cout<<"no real roots";
   }
   else
   {
       double r1=(-b+det)/(2*a);
       double r2=(-b-det)/(2*a);
       cout<<"Roots are: "<<r1<<" "<<r2;
   }

}

Problem Number: 10637

#include <iostream.h>
#include<conio.h>
int findMax(int,int,int);
int main() {
   int x,y,z;
   clrscr();
   cout<<"Enter three values:";
   cin>>x>>y>>z;
   int max = findMax(x,y,z);
   cout<<"The maximum value is:"<<" "<<max<<endl;
   return 0;
}
int findMax(int x,int y, int z) {
int max = x > y ? (x > z ? x : z) : (y > z ? y : z) ;
return max;
}

Problem Number: 11093

#include<iostream.h>
#include<conio.h>
void max(int d1,int d2)
{
if(d1 > d2) {
   cout<<"The largest value is:"<<d1;
}
else{
   cout<<"The Largest value is:"<<d2;
}
}


void max(double d1,double d2)
{
if(d1 > d2) {
   cout<<"The largest value is:"<<d1;
}
else{
   cout<<"The Largest value is:"<<d2;
}
}


void max(char d1,char d2)
{
if(d1 > d2) {
   cout<<"The largest value is:"<<d1;
}
else{
   cout<<"The Largest value is:"<<d2;
}
}

int main()
{
   clrscr();
   max(4,5);
   cout<<" ";
   max('A','B');
   cout<<" ";
   max(4.67,8.79);
   return 0;
}

Problem Number: 11094

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
panic();
int main() {
   clrscr();
   panic();
getch();
return 0;
}

panic() {
   cout<<"UnRecoverable Error...";
   exit(EXIT_FAILURE);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote