Concept explainers
What is the output of the following
#include <iostream>
void friendly();
void shy(int audienceCount);
int main()
{
using namespace std;
friendly();
shy(6);
cout << “One more time: \n”;
shy (2);
friendly ();
cout << “End of program. \n”;
return 0;
}
void friendly ()
{
using namespace std;
cout << “Hello \n”;
}
void shy(int audienceCount)
{
using namespace std;
if (audienceCount < 5)
return;
cout << “Goodbye \n”;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Problem Solving with C++, Student Value Edition
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Modern Database Management (12th Edition)
Computer Science: An Overview (12th Edition)
Database Concepts (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- Given the following code segment, what is output to the screen? char name1[20] = "Sean"; char name2[20] = "Pierce"; strcpy(name1,name2); cout << name1 << " " << name2; Group of answer choices Pierce Pierce Sean Sean Sean Pierce None of these ================== Given the following code segment, what is output to the screen? void assignments(int&, int); int main() { int output = 0, input = 5; assignments(output, input); cout << output << endl; } void assignments(int& myOutput, int myInput) { if (myInput < 0) myOutput = -2; else if (myInput == 0) myOutput = 0; else myOutput = myInput; } Group of answer choices 5 0 -2 None of these ============== A void function can be used in an assignment. Group of answer choices True Falsearrow_forwardHello, I was making a hangman simulation in C++. The code runs, but not fully. Could you identify the error and fix it? #include<iostream>#include<cstring> // for string class functions#include<fstream>#include <cctype>using namespace std; int main(){// define variable to get the response from user "Yes" or "No"string response;// Define index variableint w = 0;// define number of words that need to be guessed by the user assume 4const int WORDS = 4;// loopdo{// we will define the hangman bodyconst char body[] = "o/|\\|\\";// here we define the wordsstring words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOICIDE"};// fetch size or lengthstring xword(words[w].length(),'*');// define iterator to fetch the wordsstring::iterator i, ix = xword.begin();// define number of words to prompt for the userchar letters[26]={"\0"};// Now we define the variables which will be used in the simulationint n =0, xcount = xword.length();bool found = false, solved = false, hung =…arrow_forwardHello, I was making a hangman simulation in C++. The code runs, but not fully. Could you identify the error and fix it? #include<iostream>#include<cstring> // for string class functions#include<fstream>#include <cctype>using namespace std; int main(){// define variable to get the response from user "Yes" or "No"string response;// Define index variableint w = 0;// define number of words that need to be guessed by the user assume 4const int WORDS = 4;// loopdo{// we will define the hangman bodyconst char body[] = "o/|\\|\\";// here we define the wordsstring words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOICIDE"};// fetch size or lengthstring xword(words[w].length(),'*');// define iterator to fetch the wordsstring::iterator i, ix = xword.begin();// define number of words to prompt for the userchar letters[26]={"\0"};// Now we define the variables which will be used in the simulationint n =0, xcount = xword.length();bool found = false, solved = false, hung =…arrow_forward
- #include <iostream> using namespace std; void additionProblem(int topNumber, int bottomNumber) { int userAnswer; cout << "\n\n\n " << topNumber << " + " << bottomNumber << " = "; cin >> userAnswer; cin.ignore(1000, 10); int theAnswer = topNumber + bottomNumber; if (theAnswer == userAnswer) cout << " Correct!" << endl; else cout << " Very good, but a better answer is " << theAnswer << endl; } // additionProblem int main() { additionProblem(8, 2); additionProblem(4, 8); additionProblem(3, 7); additionProblem(4, 10); additionProblem(11, 2); } // main The above code needs to be modified according to the image I've attatched.arrow_forwardplease provide the answers to the points in this variable trace Trace through the program below. Indicate value of each of the variables or parameters at the indicated points in the program. Enter 'U' if the variable or parameter is undefined or does not exist at that point. #include <iostream.h>void test (int, int &);int y;void main (void){int x;x = 5; y = 6; // point #1 test (x, y); // point #3}void test (int a, int &b){int c; y = 1; a = 3; b = 9; c = 5; // point #2} Point #1, Variable x Point #1, Variable y Point #1, Variable a Point #1, Variable b Point #1, Variable c Point #2, Variable x Point #2, Variable y Point #2, Variable a Point #2, Variable b Point #2, Variable c Point #3, Variable x Point #3, Variable y Point #3, Variable a Point #3, Variable b Point #3, Variable carrow_forwardWhat is the output? #include <stdio.h> int main(void) { double dividend = 0.0; double divisor = 0.0; printf("%lf\n", dividend / divisor); dividend = 3.0; printf("%lf\n", dividend / divisor); return 0; } Question 5 options: inf nan nan inf inf 0.0 nan 0.0arrow_forward
- Show the output of the following code: #include <iostream> using namespacestd; class A { public: int x; int y; int z; A(): x(1), y(2), z(3) { } }; int main() { A a; A* p1 = &a; a.x = 2; A a1; p1 = &a1; cout << p1->x << " " << (*p1).y << " "<< p1->z; return 0; }arrow_forwardBy default, which one of the following types of values will be thrown when the below function is executed?def abstractAdd(a,b,c):print(a+b+c) Choose an answer A None B bool C str D intarrow_forwardplease help me with this c++ code, and I did not understand why the output is x=10 y=20. Please explain to me. #include<iostream> using namespace std; class Test { private: int x; int y; public: Test(int x = 0, int y = 0) { this->x = x; this->y = y; } Test &setX(int a) { x = a; return *this; } Test &setY(int b) { y = b; return *this; } void print() { cout << "x = " << x << " y = " << y << endl; } }; int main() { Test obj1(5, 5); // Chained function calls. All calls modify the same object // as the same object is returned by reference obj1.setX(10).setY(20); obj1.print(); return 0; }arrow_forward
- What is the output of the following C++ code? #include <iostream> using namespace std; class class0 { public: virtual ~class0(){} protected: char p; public: char getChar(); }; class class1 : public class0 { public: void printChar(); }; void class1::printChar() { cout << "True" << endl; } int main() { class1 c; c.printChar(); return 1; }arrow_forwardFor the following code, what should be filled in the blank (....) for the string to be outputted 100 times? string str = "Hello\n";int i = 0;do{ cout << str;}while(++i < ....); Group of answer choices 99 100 98 101 None of the above ========================== A variable has ___________ scope when it is declared within { }. Group of answer choices block global variable None of these ===================== For the following code, what is the valid scope for variable "var"? int main(){ for(int var = 0; var < 5; var++){ function1(var); } return 0;} Group of answer choices Only in Main Only in the for-loop Both the for-loop and main Both for-loop and function1 Only in function1 All of the abovearrow_forward2. Consider the following program. #include <iostream> using namespace std; void summer(int&, int); void fall(int, int&); int x; int main() { int intNum1 = 2; int intNum2 = 5; x = 6; summer(intNum1, intNum2); cout << intNum1 << " " << intNum2 << " " << x << endl; fall(intNum1, intNum2); cout << intNum1 << " " << intNum2 << " " << x << endl; return 0; } void summer(int& a, int b) { int intNum1; intNum1 = b + 12; a = 2 * b + 5; b = intNum1 + 4; } void fall(int u, int& v) { int intNum2; intNum2 = x; v = intNum2 * 4; x = u - v; } Answer the following questions: a. What is the output? Consider variable scope. b. Considering the function summer, parameter 1 is called by reference. What is passed into the function for parameter 1, i.e., what value does parameter 1 receive? c. Again, considering the function summer, parameter 2 is called by value. What occurs in memory for parameter 2 and local…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education