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
kow [346]
3 years ago
15

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targe

tValue. Otherwise, print "Not equal".
Computers and Technology
2 answers:
Likurg_2 [28]3 years ago
3 0

Answer:

The program to this question as follows:

Program:

targetValue = 0.3333 #defining variable targetValue and assign value

sensorReading = 0.0 #defining variable sensorReading and assign value

sensorReading = 1.0/3.0 #calculate value in sensorReading variable

Val=sensorReading - targetValue

#calculate the difference and store in Val variable

if (Val < 0.0001): #use of if block to check condition

  print ("Equal")  #print value

else:  #else block

  print ("Not equal") #print value

Output:

Equal

Explanation:

In the above Python program code, there are two variables "targetValue and sensorReading" is defined, in which targetValue store a value, that is "0.3333", and sensorReading holds a value, that is "0.0".

  • In the next step, the "Val" variable is defined, that calculate the difference between both variable, that conditional statement is used.
  • In if block, if the value is less then "0.0001", it will print value "Equal", otherwise, it will go to the else block, that will print "Not equal".
Anna11 [10]3 years ago
3 0

Full Question

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Otherwise, print "Not equal". Ex: If targetValue is 0.3333 and sensorReading is (1.0/3.0), output is: Equal

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double targetValue;

double sensorReading;

cin >> targetValue;

cin >> sensorReading;

if (/* Your solution goes here */) {

cout << "Equal" << endl;

} else {

cout << "Not equal" << endl;

} return 0;

}

Answer:

if (abs(targetValue - sensorReading) <= 0.0001)

Explanation:

Replace

if (/* Your solution goes here */) {

With

if (abs(targetValue - sensorReading) <= 0.0001)

Two values are considered to be close enough if the difference between the values is 0.0001

Splitting the codes into bits;

abs

targetValue - sensorReading

<=

0.0001

The keyword abs is to return the absolute value of the expression in bracket.

This is needed because the expression in the bracket is expected to return a positive value.

To do this the absolute keyword is required.

targetValue - sensorReading returns the difference between the variables

<= compares if the difference falls within range that should be considered to be close enough

0.0001 is the expected range

You might be interested in
________an approach to database and software development that emphasizes "individuals and interactions over processes and tools,
dimulka [17.4K]

Answer:

Agile software development

Explanation:

Agile software development  model is a blend of iterative and steady procedure models with center around process flexibility and consumer loyalty by fast conveyance of working programming item. Nimble Methods break the item into little gradual forms. These assembles are given in emphases.

So in blank space there will be Agile software development

7 0
3 years ago
Alex writes down a string with four digits. (Since this is a string, not a number, it can start with a $0.$ For example, Alex co
Artist 52 [7]

Answer: The answers to all parts of this question are based on "automatic string". The condition is also provided which states that the string the machine outputs is the same string (4-digit string) which is fed to the machine as input.

Explanation: (a) The string will not remain automatic string if it contains a digit greater or equal to $5$. As we know that machine should print the same string which is fed into it. In this case the machine will insert a 0 in place of $5$. So the number is inserting a 0 when it is output by the counting machine. For example if we input $2152$ machine will print "$0120$" which shows that the digits are not the same as fed to the machine. If we take string $0702,$ which is given in the question, we see that machine prints out "$2010$" which means that number is inserting a 0 so automatic string cannot contain a digit greater than $5$

(b) The same answer as given in (a). For example the if we write $4220$ machine prints out "$1020$".  So the automatic string cannot contain $4.$

(c) This is a bit tricky as machine count the digit $3$. Lets take an example string $3303$. the machine prints out "$1003$". It counts three BUT its not an automatic string because the string printed out is different from the string that was fed to the machine. So automatic string cannot contain $3.$

(d) Now we know that an automatic string cannot contain digits 3,4,5 and above. So it can contain digits 0,1 and 2 with 0 at the end as the automatic string cannot contain digit 3 or above.Lets take a few examples of strings with combinations of 0,1 and 2 to check if they are automatic strings.

  • $1220$ the machine prints $1120$ which is not the same as fed into machine so its not an automatic string.
  • $2020$ the machine prints out "$2020$". Its 2 times "$0$", 0 times "$1$",2 times "$2$" and 0 times "$3$" which is the same as fed to machine so $2020$ is an automatic string.
  • $1210$  is an automatic string as the machine prints out "$1210$" which is the same string fed to machine.
8 0
3 years ago
What are software applications?
navik [9.2K]

Answer:

files that are stored on the computer

Explanation:

there is an actual definition, but it isnt listed here. Application software is commonly defined as any program or number of programs designed for end-users. That's it, in a nutshell.

4 0
3 years ago
Read 2 more answers
Which of the following are examples of system software?
Nastasia [14]

Answer:

system softwear -operating system

-system sequrity utilities

5 0
3 years ago
Read 2 more answers
Given an int variable k that has already been declared, use a while loop to print a single line consisting of 88 asterisks. Use
Grace [21]

Answer:

True

Explanation:

The while loop is going to be executed until the condition is false.

Since <em>k</em> is initially equal to 1, the loop will execute 88 times. One asterisk will be printed and <em>k</em> will be incremented by one during each iteration.

When <em>k</em> becomes 89, the condition will be false (89 is not smaller or equal to 88) and the loop will stop.

6 0
3 years ago
Other questions:
  • You should use a ____ chart to compare values side by side, broken down by category.
    9·1 answer
  • Jeanne writes a song, and Raul wants to perform
    6·2 answers
  • _______ Originally , the art of maganing engines; in its modern and extended sense
    7·1 answer
  • 1. The first popular animated feature film was 1937’s Snow White and the Seven Dwarfs. (1 point)
    8·1 answer
  • _______medium is a secondary storage medium that uses magnetic techniques to store and retrieve data on disks or tapes coated wi
    9·1 answer
  • PLZ ANSWER THESE QUESTIONS FOR 30 POINTS AND BRAINLIEST!
    9·1 answer
  • How does segmenting your network increase network security?
    8·1 answer
  • g write a recursive function that prints out all the even numbers between x and y inclusive if x is odd then the print out will
    5·1 answer
  • Imagine you’re at lunch. Your nose smells pizza. Your legs move over to where hot lunch is being served. You have to balance the
    9·2 answers
  • (3 marks)
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!