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

Write a decision statement to check that the value of an integer |variable \"x\"

ID: 3822812 • Letter: W

Question

Write a decision statement to check that the value of an integer |variable "x" is between 45 and 75. If it is, display YES, otherwise display NO. Make sure to include 45 and 75 as true values. Write a separate decision statement if display Here if the value of a variable "state" is NY or NJ. If it is not, display There. Make sure to declare all variables used. Write a code snippet that includes a loop to input 12 positive integers and display the highest value entered without using arrays. The values will be doubles. You must validate that the input values are positive, (TCO 7) A variable declared inside of a for-loop body has its scope _____. within the variable within the entire loop limited in the body of the loop limited to the statement line (TCO 9) The accessor methods are sometimes called _____. getters accessors setters None of the above

Explanation / Answer

Write a decision statement to check that the value of an integer variable x is between
45 and 75. If it is, display YES, otherwise display NO. Make sure to include 45, and 75 as true values.
if(x >= 45 && x <= 75)
   cout << "YES";
else
   cout << "NO";
  
Write a separate decision statement if display Here if the value of a variable state is
NY or NJ. If it is not, display There. Make sure to declare all variables used.
if(state.compare("NY") == 0 || state.compare("NJ") == 0)
   cout << "Here";
else
   cout << "There";

Write a code snipped that includes a loop to input 12 positive integers and display the
highest value entered without using arrays. The values will be doubles. You must validate
that the input values are positive.
double value, highest
for(int i = 0; i < 12; i++)   //Makes sures this loop runs for 12 values.
{
    cout << "Enter value # " << i+1 << ": ";
    cin >> value;   //Reads a value from user.
    if(value <= 0)   //If the value is not positive.
    {
       cout << "Only positive values please..." << endl;
       i--;   //Stay on the same value.
       continue;   //Skip all the remaining steps, and go ahead with the beginning.
    }
    if(i == 0)   //If the read value is the first.
        highest = value;   //Assign it to the highest.
    else       //If not.
        if(value > highest)   //Compare it with the highest value, and update if needed.
            highest = value;     
}  
cout << "The highest of the values entered is: " << highest << endl; //Print the highest value.

2. A variable declared inside a for loop body has it scope:
   limited in the body of the loop.
12. The accessor methods are sometimes called:
   getters. This is because they'll fetch the values to outside the class.

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