1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AfilCa [17]
3 years ago
8

Using a conditional expression, write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUser

s. Ex: if numUsers is 8 and updateDirection is 1, numUsers becomes 9; if updateDirection is 0, numUsers becomes 7. Hint: Start with "numUsers = ...".
Sample program:

#include

int main(void) {
int numUsers = 0;
int updateDirection = 0;

numUsers = 8;
updateDirection = 1;



printf("New value is: %d\n", numUsers);

return 0;
}
Computers and Technology
1 answer:
jeyben [28]3 years ago
3 0

Answer:

if(updateDirection==1){

   numUsers++;

}

else if(updateDirection==0){

   numUsers--;

}

Explanation:

The if and else if conditional statement above accomplishes this.

if the first condition is true (updateDirection==1), numUsers is increemented by 1 (numUsers++)

else if the second condition is true (updateDirection==0), numUsers is decreemented by 1 (numUsers--)

See a complete C++ code below:

<em>#include <iostream></em>

<em>using namespace std;</em>

<em>int main()</em>

<em>{</em>

<em>int numUsers = 0;</em>

<em>int updateDirection = 0;</em>

<em />

<em>numUsers = 8;</em>

<em>updateDirection = 0;</em>

<em />

<em>if(updateDirection==1){</em>

<em>    numUsers++;</em>

<em>}</em>

<em>else if(updateDirection==0){</em>

<em>    numUsers--;</em>

<em>}</em>

<em>cout<<"New value is: "<< numUsers<<endl;</em>

<em>return 0;</em>

<em>}</em>

You might be interested in
Write a method reverse that takes an array as an argument and returns a new array with the elements in reversed order. Do not mo
mr Goodwill [35]

Answer:

public class ArrayUtils

{

//function to reverse the elements in given array

public static void reverse(String words[])

{

//find the length of the array

int n = words.length;

//iterate over the array up to the half

for(int i = 0;i < (int)(n/2);i++)

{

//swap the first element with last element and second element with second last element and so on.

String temp;

temp = words[i];

words[i] = words[n - i -1];

words[n - i - 1] = temp;

}

}

public static void main(String args[])

{

//create and array

String words[] = {"Apple", "Grapes", "Oranges", "Mangoes"};

//print the contents of the array

for(int i = 0;i < words.length;i++)

{

System.out.println(words[i]);

}

//call the function to reverse th array

reverse(words);

//print the contents after reversing

System.out.println("After reversing............");

for(int i = 0;i < words.length;i++)

{

System.out.println(words[i]);

}

}

Explanation:

4 0
2 years ago
Define a class named ComparableSquare that extends Square (defined above) and implements Comparable. Implement the compareTo met
Alexxx [7]

Answer:

/*********************************************************************************

* (The ComparableCircle class) Define a class named ComparableCircle that        *

* extends Circle and implements Comparable. Draw the UML diagram and implement   *

* the compareTo method to compare the circles on the basis of area. Write a test *

* class to find the larger of two instances of ComparableCircle objects.         *

*********************************************************************************/

public class Exercise_13_06 {

/** Main method */

public static void main(String[] args) {

 // Create two instances of ComparableCircle objects

 ComparableCircle comparableCircle1 = new ComparableCircle(12.5);

 ComparableCircle comparableCircle2 = new ComparableCircle(18.3);

 // Display comparableCircles

 System.out.println("\nComparableCircle1:");

 System.out.println(comparableCircle1);

 System.out.println("\nComparableCircle2:");

 System.out.println(comparableCircle2);

 // Find and display the larger of the two ComparableCircle objects

 System.out.println((comparableCircle1.compareTo(comparableCircle2) == 1  

  ? "\nComparableCircle1 " : "\nComparableCircle2 ") +  

  "is the larger of the two Circles");

}

}

3 0
3 years ago
Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1
-BARSIC- [3]

Answer:

#required generator function

def count_seq():

   #starting with number 2. using string instead of integers for easy manipulation

   n='2'

   #looping indefinitely

   while True:

       #yielding the integer value of current n

       yield int(n)

       #initializing an empty string

       next_value=''

       #looping until n is an empty string

       while len(n)>0:

           #extracting first digit (as char)

           first=n[0]

           #consecutive count of this digit

           count=0

           #looping as long as n is non empty and first digit of n is same as first

           while len(n)>0 and n[0]==first:

               #incrementing count

               count+=1

               #removing first digit from n

               n=n[1:]

           #now appending count and first digit to next_value

           next_value+='{}{}'.format(count,first)

       #replacing n with next_value

       n=next_value

#testing, remove if you don't need this

if __name__ == '__main__':

   #creating a generator from count_seq()

   gen=count_seq()

   #looping for 10 times, printing next value

   for i in range(10):

       print(next(gen))

Explanation:

6 0
4 years ago
Electronically, or on paper draw a Binary Search Tree using the values below. Note: Insert each value into the tree in order fro
maria [59]

Answer:

A.)  in order traversal - 9 32 35 14 27 25 2 7 29

B.) pre-order traversal - 25 14 32 9 35 27 7 2 29

C.) post-order traversal - 9 35 32 27 14 2 29 25

Explanation:

Given - 25, 14, 7, 32, 27, 2, 29,9,35

To find - On a separate electronic page or sheet of paper:

1. List the values using in order traversal

2. List the values using pre-order traversal

3. List the values using post-order traversal

Proof -

Given values are -

25, 14, 7, 32, 27, 2, 29,9,35

1.)

In order is -

9 32 35 14 27 25 2 7 29

2.)

Pre-order is - (Root left right)

List nodes of first time visit

25 14 32 9 35 27 7 2 29

3.)

Post-order is - (Left Right Root)

List nodes of third time visit

9 35 32 27 14 2 29 25

5 0
3 years ago
As Jason walks down the street, a large raven starts squawking at him and flapping its wings. Jason thinks to himself ‘That bird
UNO [17]

Answer:

Answer to the following question is anthropomorphism.

Explanation:

Anthropomorphism is considered as the error in the following context of the scientific reductionism. Anthropomorphize is the source of an error that needs to reconsider.

Anthropomorphism is an attribute of the human qualities, emotions, thoughts, motivation, intentions, and characteristics to the non-living beings or the nonhuman beings, things or objects.

8 0
3 years ago
Other questions:
  • How do type declaration statements for simple variables affect the readability of a language, considering that some languages do
    10·1 answer
  • The arrow next to All Programs indicates _____. that this item cannot be selected that this was the most recently used item the
    7·2 answers
  • Numeric data is stored in ___________ for direct processing.
    10·2 answers
  • What is the definition of framerate?
    7·1 answer
  • The ____ function displays the highest value in a range.
    15·2 answers
  • If you press the key corresponding to letter A on the keyboard, what process is carried out inside the CPU to display the letter
    10·1 answer
  • Which of the following is a name for the place an information services and support professional might work? software development
    15·2 answers
  • A Tracking Gantt chart is based on the percentage of work completed for project tasks or the actual start and finish dates. True
    12·1 answer
  • In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '
    8·1 answer
  • Although your project has been accepted by the customer, the contract with the system vendor specifies that it will support the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!