answer.
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
igomit
18 days ago
8

Assume that a function named swapdoubles has been defined and is available for use in this exercise: that function receives two

variables of type double and exchanges their values. Write the definition of a function named sort3 that is passed three double variables. The function returns nothing but modifies the values of these variables so they are in sorted order. So, if a, b and c have (respectively) the values 3.14, 2.71, and 3.04, and the invocation sort3(a,b,c) is made, then upon return, the values of a, b and c will be 2.71, 3.04, and 3.14 respectively.
Computers and Technology
1 answer:
Natasha_Volkova [897]18 days ago
6 0
The provided C++ code is designed to sort three double variables: void sort3(double &a, double &b, double &c). The logic within functions attempts to ensure that these values are ordered correctly, implementing swaps accordingly.
You might be interested in
Su now wants to highlight several inventors in her presentation, so she decides to use the underline color option.
Harlamova29_29 [932]

Answer:

1. The home tab

2. Font group

3. The small arrow at the bottom right of the font command group.

4. Under "Font" heading (then "All text" subheading)

Explanation:

This explanation will guide Su in completing her task.

1. Navigate to the home tab;

2. From the home tab, Su will access a variety of command groups, but for her needs, she requires the Font command group.

3. A tiny arrow can be found at the bottom left of the font command group section; clicking it will unveil the font dialogue.

4. Within the font dialogue, there are two headings. The "font" heading and the "character spacing" heading.

For her purposes, she must focus on the "Font" heading, which includes various subheadings. To reach the underline color option, she needs to select the "All text" subheading.

Refer to the attached image for guidance.

7 0
1 month ago
Write an if-else statement to describe an integer. Print "Positive even number" if isEven and is Positive are both true. Print "
Harlamova29_29 [932]

Answer:

Below is the explanation for the C code.

Explanation:

#include <stdio.h>

#include <stdbool.h>

int main(void) {

int userNum;

bool isPositive;

bool isEven;

scanf("%d", &userNum);

isPositive = (userNum > 0);

isEven = ((userNum % 2) == 0);

if(isPositive && isEven){

  printf("Positive even number");

}

else if(isPositive &&!isEven){

  printf("Positive number");

}

else{

  printf("Not a positive number");

}

printf("\n");

return 0;

}

6 0
1 month ago
Debug the program so it prints the factorial of a positive integer entered by the user. This is calculated by multiplying all th
Natasha_Volkova [897]
The primary issue was declaring int prod within the while loop, which caused prod to reset to 1 each time the loop executed.
3 0
21 day ago
Describe a strategy for avoiding nested conditionals. Give your own example of a nested conditional that can be modified to beco
maria [879]

Answer:

To prevent nested conditionals, one can utilize logical expressions like the AND operator.

A recommended approach is creating an interface class with a method designed for a shared function. This design approach is known as the strategy design pattern. The conditional statements can be consolidated into this method. Subsequently, each class can implement this interface and invoke that shared method as needed by constructing instances of subclasses and calling the common method for those objects. This illustrates polymorphism.

Explanation:

Nested conditionals occur when if or else if statements are placed within another condition. For instance:

if( condition1) {

//runs when condition1 is true

  if(condition2) {

//runs when both condition1 and condition2 are true

  }  else if(condition3) {

 //when condition1 is true and condition3 is also true

} else {

 //condition1 is true but neither condition2 nor conditions3 are satisfied

}  }

Excessive nested conditionals can complicate the program, rendering it hard to read or comprehend, particularly if there's improper indentation. Debugging also becomes challenging when there are numerous nested statements.

Thus, several strategies can be adopted to eliminate nested conditionals, such as utilizing a switch statement.

For instance, I’ll present an example of the strategies discussed earlier:

Logical Expressions Usage:

A method to avoid nested conditionals is by employing logical expressions with logical operators like the AND operator. The previous nested conditionals can be reframed as:

if(condition1 && condition2){ //only runs when both condition1 and condition2 are true

} else if(condition1 && condition3) {

executes only if both condition1 and condition3 are true

} else if(condition1 ){

//condition1 is satisfied but neither condtion2 nor condtion3 are true  }

This can be further simplified to one condition as:

if(!condition3){

// when  condition1 and condition2 are both satisfied

}

else

// condition3 is met

Now, consider a simple instance dealing with whether to attend school based on certain conditions.

if (temperature< 40)

{

   if (busArrived=="yes")

   {

       if (!sick)

       {

           if (homework=="done")

           {

               printf("Go to school.");

           }

       }                    

   }

}

Here, nested conditionals are evident. This can be restructured into a solitary conditional using the AND logical operator.

if ((temperature <40) && (busArrived=="yes") &&

(!sick) && (homework=="done"))

{    cout<<"Eligible for promotion."; }

The alternate method is utilizing an interface. For example, you can

abstract class Shape{

//declare a method common to all sub classes

  abstract public int area();

// same method that varies by formula of area for different shapes

}

class Triangle extends Shape{

  public int area() {

     // implementation of area code for Triangle

return (width * height / 2);

  }

}

class Rectangle extends Shape{

  public int area() {

     // implementation of area code for Rectangle

    return (width * height)

  }

}

Now, you can readily create Rectangle or Triangle instances and invoke area() for any of those objects, resulting in execution of the appropriate version accordingly.

4 0
1 month ago
A method countDigits(int num) of class Digits returns the remainder when the input argument num(num &gt; 0) is divided by the nu
ivann1987 [930]

Answer:

#include <iostream>

using namespace std;

class Digits

{

   public:

   int num;

   int read()       //method to read num from user

   {

       cout<<"Enter number(>0)\n";

       cin>>num;

       return num;

   }

   int digit_count(int num)  //method to count number of digits of num

   {

       int count=0;

       while(num>0)    //loop till num>0

       {

           num/=10;

           count++;   //counter which counts number of digits

       }

       return count;

   }

   int countDigits(int num)   //method to return remainder

   {

       int c=digit_count(num); //calls method inside method

       return num%c;  

   }

};

int main()

{

   Digits d;    //object of class Digits is created

   int number=d.read();   //num is read from user

   cout<<"\nRemainder is: "<<d.countDigits(number);  //used to find remainder

   return 0;

}

Output:

Enter number(>0)

343

Remainder is: 1

Explanation:

The program has a logical error that needs rectification. A correctly structured program calculates the remainder when a number is divided by the count of its digits. A class named Digits is created, consisting of the public variable 'num' and methods for reading input, counting digits, and calculating the remainder.

  • read() - This function asks the user to enter the value for 'num' and returns it.
  • digit_count() - This function accepts an integer and counts how many digits it has, incrementing a counter until 'num' is less than or equal to 0. It ultimately returns the digit count.
  • countDigits() - This function takes an integer and delivers the remainder from dividing that number by its digit count. The digit count is computed using the 'digit_count()' method.

Finally, in the main function, a Digits object is instantiated, and its methods are utilized to produce an output.

7 0
1 month ago
Other questions:
  • A video conferencing application isn't working due to a Domain Name System (DNS) port error. Which record requires modification
    15·1 answer
  • What are the 2 things you are not sure about evaluating functions​
    7·2 answers
  • Two middle-order batsmen are compared based on their performance in their previous cricket match.
    7·1 answer
  • In this project, you’ll create a security infrastructure design document for a fictional organization. The security services and
    9·1 answer
  • Choose the person responsible for each innovation.
    10·1 answer
  • Assume that the following variables have been properly declared and initialized.
    12·1 answer
  • Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the arr
    6·1 answer
  • 7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho
    11·1 answer
  • Assign to avg_owls the average owls per zoo. Print avg_owls as an integer. Sample output for inputs: 1 2 4 3
    7·1 answer
  • This question refers to a standard deck of playing cards. If you are unfamiliar with playing cards, there is an explanation in P
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!