Question

Consider the following program: #include #include #include using namespace std; int main() { int num1; int...

Consider the following program:

#include
#include
#include

using namespace std;

int main()

{
int num1;
int num2;

cout << fixed << showpoint << setprecision(2);

cout << "Enter two integers: ";
cin >> num1 >> num2; cout << endl;

if (num1 != 0 && num2 != 0)
cout << sqrt(abs(num1 + num2) + 0.5) << endl;
else if (num1 != 0)
cout << floor(num1 + 0.5) << endl;
else if (num2 != 0)
cout << ceil(num2 + 0.5) << endl;
else
cout << 0 << endl;

return 0;
}

a. What is the output if the input is -23 8?
b. What is the output if the input is 12 32?
c. What is the output if the input is 15 0?
d. What is the output if the input is 0 -36?
e. What is the output if the input is 0 0?

Homework Answers

Answer #1

Code

------------------

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()   
{
   int num1, num2;
   cout << fixed << showpoint << setprecision(2);
   cout << "Enter two integers: ";
   cin >> num1 >> num2;
   cout << endl;

   if (num1 != 0 && num2 != 0)
       cout << sqrt(abs(num1 + num2) + 0.5) << endl;
   else if (num1 != 0)  
       cout << floor(num1 + 0.5) << endl;
   else if (num2 != 0)
       cout << ceil(num2 + 0.5) << endl;
   else
       cout << 0 << endl;
   return 0;   
}

----------------------

Code Screenshot

----------------------

Code Output

---------------------

Code computes:

if both numbers not 0, the it outputs: sqrt(abs(num1 + num2) + 0.5)

if num2 = 0 and num1 != 0 output is floor(num1 + 0.5) << endl;

if num1 = 0 and num2 != 0 output is floor(num2 + 0.5) << endl;

if num1 = 0 and num2 = 0 output 0

-----------------

a. What is the output if the input is -23 8?

ANswer: 3.94

sqrt(abs(num1 + num2) + 0.5) = 3.94

-----------------
b. What is the output if the input is 12 32?

Answer: 6.67

sqrt(abs(num1 + num2) + 0.5) = 6.67

------------
c. What is the output if the input is 15 0?

Answer: 15

floor(num1 + 0.5) =15

------------
d. What is the output if the input is 0 -36?

Answer: -35

floor(num2 + 0.5) = -35

---------------


e. What is the output if the input is 0 0?

Answer: 0

-----------------

I hope this helps you,

Please rate this answer if it helped you,

Thanks for the opportunity

Know the answer?
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
Similar Questions
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main()...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main() { ​cout << "Hello, world." << endl; } Open a Word Document and copy and paste the program and the output. 2. Create a new program: #include <iostream> using namespace std; int main() { ​float num1; ​float num2 ​float avg; ​cout << "Enter two numbers" << endl; ​cin >> num1 >> num2; ​avg = num1 + num2/2; ​cout << "The average is " <<...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
What will be the output of the following code? #include <iostream> using namespace std; int main()...
What will be the output of the following code? #include <iostream> using namespace std; int main() {    char *s = "hello";    char *p = s;    cout << *(p+3) << " " << s[1] << endl; }
1. Create a new project. Type in the following program. Add a comment at the top...
1. Create a new project. Type in the following program. Add a comment at the top to include your name and the date. 2. Compile and Run with different values. What data values should you choose? Think about what we discussed in class. 3. Add code to compute the modulus. Hint: you will also have to declare a new variable. //this program demonstrates the use of various operators #include <iostream > using namespace std; int main() { int num1; int...
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile;...
C ++ #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; }...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout << "Welcome to the Calorie Count-ulator!\n"; // Get user input: cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n"; cin >> meal_choice; cout << "Enter the amount of servings (1-9):\n"; cin >> servings; // TODO: Use a switch statement to evaluate the user's meal choice // Handle error checking where appropriate // Exit the program: return 0;}
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...