Question

QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

QUESTION 1

  1. What is the output of the following code snippet?

    int main()
    {
       bool attendance = false;
       string str = "Unknown";
       attendance = !(attendance);
       if (!attendance)
       {
          str = "False";
       }
       if (attendance)
       {
          attendance = false;
       }
       if (attendance)
       {
          str = "True";
       }
       else
       {
          str = "Maybe";
       }
       cout << str << endl;
       return 0;
    }

    False

    True

    Unknown

    Maybe

QUESTION 2

  1. What is the output of the following code snippet?

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
       string str1 = "her";
       string str2 = "cart";
       if (str1 < str2)
       {
          cout << str2;
       }
       else
       {
          cout << str1;
       }
       return 0;
    }

    her

    hercart

    cart

    There is no output due to compilation errors.

QUESTION 3

  1. Consider the following code snippet:

    bool attendance = true;
    bool failed = false;

    Which of the following if statements includes a condition that evaluates to true?

    if (attendance == "true") { ... }

    if (attendance) { ... }

    if (failed) { ... }

    if (attendance == failed) { ... }

QUESTION 4

  1. What is the value of the cost variable after the following code snippet is executed?

    int cost = 82;
    if (cost < 100) 
    { 
       cost = cost + 10; 
    }
    if (cost > 50) 
    { 
       cost = cost * 2; 
    }
    if (cost < 100) 
    { 
       cost = cost - 20; 
    }

    82

    92

    184

    164

QUESTION 5

  1. Assuming that the user provides 303 as input, what is the output of the following code snippet?

    int x;
    int y;
    x = 0;
    cout << "Please enter y: ";
    cin >> y;
    if (y > 300)
    { 
       x = y;
    }
    else 
    { 
       x = 0;
    }
    cout << "x: " << x << endl;

    x: 0

    x: 300

    x: 303

    There is no output due to compilation errors.

QUESTION 6

  1. Which of the following options checks that country is neither China nor Denmark?

    if (country != "China" || country != "Denmark")

    if !(country == "China" || country == "Denmark")

    if !(country == "China" && country == "Denmark")

    if (country != "China" || country == "Denmark")

QUESTION 7

  1. Which of the following variables is used to store a condition that can be either true or false?

    Algebraic

    Logical

    Boolean

    Conditional

QUESTION 8

  1. Which of the following operators is NOT a relational operator?

    <=

    +=

    !=

    ==

QUESTION 9

  1. Assuming that the user provides 99 as input, what is the output of the following code snippet?

    int a; 
    int b;
    a = 0;
    cout << "Please enter b: ";
    cin >> b;
    if (b > 100);
    {   a = b;}
    cout << "a: " << a << endl;

    a: 0

    a: 99

    a: 100

    There is no output due to compilation errors.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

QUESTION 1
Answer: Option d) Maybe
Explanation:
Program:

#include <iostream>
using namespace std;
int main()
{
bool attendance = false;
string str = "Unknown";
attendance = !(attendance);
if (!attendance)
{
str = "False";
}
if (attendance)
{
attendance = false;
}
if (attendance)
{
str = "True";
}
else
{
str = "Maybe";
}
cout << str << endl;
return 0;
}

Output:


QUESTION 2
Answer: Option a) her
Explanation:

Program:

#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1 = "her";
string str2 = "cart";
if (str1 < str2)
{
cout << str2;
}
else
{
cout << str1;
}
return 0;
}

Output:

QUESTION 3
Answer: Option b) if (attendance) { ... }
Explanation:

Program:

#include <iostream>
#include <string>
using namespace std;
int main()
{
bool attendance = true;
bool failed = false;
if (attendance)
{
cout <<"true";
}
else
{
cout <<"false";
}
return 0;
}

Output:


QUESTION 4
Answer: 184
Explanation:

Program:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int cost = 82;
if (cost < 100)
{
cost = cost + 10;
}
if (cost > 50)
{
cost = cost * 2;
}
if (cost < 100)
{
cost = cost - 20;
}
cout<<"cost : "<<cost;
}

Output:


QUESTION 5
Answer: 303
Explanation:

Program:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int x;
int y;
x = 0;
cout << "Please enter y: ";
cin >> y;
if (y > 300)
{
x = y;
}
else
{
x = 0;
}
cout << "x: " << x << endl;
}

Output:

QUESTION 6
Answer: Option c) if !(country == "China" && country == "Denmark")

QUESTION 7

Answer: Option c) Boolean

QUESTION 8

Answer: Option b) +=

QUESTION 9
Answer: Option b) 99
Explanation:

Program:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int a;
int b;
a = 0;
cout << "Please enter b: ";
cin >> b;
if (b > 100);
{ a = b;}
cout << "a: " << a << endl;
}

Output:

Add a comment
Know the answer?
Add Answer to:
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 51. What is the output of the following code snippet? int number = 0; int ptr_num...

    51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = &num; num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

  • What is wrong with the following code snippet? int main() { int width = 10; height...

    What is wrong with the following code snippet? int main() { int width = 10; height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; } The code snippet uses an uninitialized variable. The code snippet uses an undefined variable. The code snippet attempts to assign a decimal value to an integer variable. The code snippet attempts to assign an integer value to a decimal variable.

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • What is the output from running the following code snippet. void mystery(Queue<int>& q) { Stack<int> s;...

    What is the output from running the following code snippet. void mystery(Queue<int>& q) { Stack<int> s; while (!s.isEmptyQueue()) { s.push(q.front()); q.deleteQueue(); } while (!s.isEmptyStack()) { q.addQueue(2 * s.top()); s.pop(); } } Queue q; q.addQueue(8); q.addQueue(4); q.addQueue(18); q.addQueue(7); q.addQueue(5); mystery(q); cout << "["; while (!.isEmptyQueue()) { cout << " " << q.front(); } cout << " ]" << endl;

  • It's a C++ code. 2. Answer the following questions in a word document. 6. What is...

    It's a C++ code. 2. Answer the following questions in a word document. 6. What is the output of the following C++ code? (2, 3) int inti - 26 int int2 = 45; int intPtr - Einti; int int2Ptr - Gint2: intPtr -89; int2Ptr - 623 intiptr - int2Ptr intPtr - 80 intl -57 cout << inti «..« int2 << endl; cout << *intiptr «« int2Ptr << endl; 7. Given the following statements: int num; int numPtr write C++ statements...

  • QUESTION 10 Which of the following is the correct definition of a function that calculates the...

    QUESTION 10 Which of the following is the correct definition of a function that calculates the area of a rectangle by multiplying its length by its width? The length and width parameters are double values and the function returns a double. double area (double length, double width) return lengthwidth double area( double length, double width) double area length width return double area(double length, width) return length width area(double length, double width) return length width; QUESTION 11 What is the output...

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT