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
saveliy_v [14]
3 years ago
12

Assume you are programming an embedded microcontroller in C and want your code to follow good software engineering practices, be

as portable as possible, and not be wasteful of memory. You need to select a variable that can hold an integer from 0 to 132. What is the best choice for the variable type?
Engineering
2 answers:
Olegator [25]3 years ago
5 0

Answer:

unsigned char

Explanation:

Selecting best data type depends upon the application. Memory and portability are some of the considerations while selecting a data type.

For the given scenario, we need to store an integer in the range of 0 to 132.

Lets have a look at some of the options available for variable data types.

Type: signed char

storage size: 1 byte

Range: -128 to 127

Type: unsigned char

storage size: 1 byte

Range: 0 to 255

Type: int

storage size: 2 byte

Range: -32,768 to 32,767

Unsigned char would be best choice since we need to store only positive integers and it gives us range 0 to 255 which is more than enough for our case and storage size is also least. Other data types are simply too big to consider for this scenario and hence they will be a wasteful of memory.

Please note that the name of data type is "char" but that doesn't mean that we cannot store integer values in it. In-fact in embedded micro-controller environment, char is often used for storing one byte integers.

insens350 [35]3 years ago
4 0

Answer:

unsigned char

Explanation:

The different data types with their sizes and range are given as follows,

  • char - 1 byte - Value: -128 - 127
  • unsigned char- 1 byte - Value: 0 - 255

All other data types including integers, float, double require 2 bytes or more. Therefore, the data type with the smallest size that can hold values from 0 to 132 is unsigned char.

You might be interested in
/* Function findBestVacation * duration: number of vacation days * prefs: prefs[k] indicates the rate specified for game k * pla
alexira [117]

Answer:

This is the C++ code for the above problem:

#include<bits/stdc++.h>

using namespace std;

int computeFunLevel(int start, int duration, int prefs[], int ngames, int plan[]) {

if(start + duration > 365) { //this is to check wether duration is more than total no. of vaccation days

return -1;

}

int funLevel = 0;

for(int i=start; i<start+duration; i++) { //this loop runs from starting point till

//start + duration to sum all the funlevel in plan.

funLevel = funLevel + prefs[plan[i]];

}

return funLevel;

}

int findBestVacation(int duration, int prefs[], int ngames, int plan[]) {

int max = 0, index = 0, sum = 0 ;

for(int i=1; i<11; i++){ //this loop is to run through whole plan arry

sum = 0; //sum is initialized with zero for every call in plan ,

//in this case loop should run to 366,but for example it is 11

//as my size of plan array is 11

for(int j=0; j<duration; j++) { // this loop is for that index to index+duration to calc

//fun from that index

sum = sum + prefs[plan[i]];

}

if(sum>max) { //this is to check max funlevel and update the index from which max fun can be achieved

max = sum;

index = i;

}

}

return index;

}

int main() {

int ngames = 5;

int prefs[] = { 1,2,0,5,2 };

int plan[] = { 0,2,0,3,3,4,0,1,2,3,3 };

int start = 1;

int duration = 4;

cout << computeFunLevel(start, duration, prefs, ngames, plan) << endl;

cout << computeFunLevel(start, 555, prefs, ngames, plan) << endl;

cout << findBestVacation(4, prefs, ngames, plan) << endl;

}

The screen of the program is given below.

3 0
2 years ago
Can u say what’s this
tatuchka [14]

Answer:

particles of a solid object packed together

7 0
2 years ago
Read 2 more answers
Going green means: increasing one's initiatives toward a concern for the environment. increasing one's bottom line, before any o
Tcecarenko [31]

Answer:

Going green means increasing one's initiatives toward a concern for the environment.

Explanation:

Going green involves all the knowledge and practices that can lead to more environmentally friendly and ecologically responsible decisions and lifestyles, which would protect and sustain the natural resources present in the environment for both present and future generations.

8 0
3 years ago
Exhaust gas from a furnace is used to preheat the combustion air supplied to the furnace burners. The gas, which has a flow rate
Monica [59]

Answer:

The total tube surface area in m² required to achieve an air outlet temperature of 850 K is 192.3 m²

Explanation:

Here we have the heat Q given as follows;

Q = 15 × 1075 × (1100 - t_{A2}) = 10 × 1075 × (850 - 300) = 5912500 J

∴ 1100 - t_{A2} = 1100/3

t_{A2}  = 733.33 K

\Delta \bar{t}_{a} =\frac{t_{A_{1}}+t_{A_{2}}}{2} - \frac{t_{B_{1}}+t_{B_{2}}}{2}

Where

\Delta \bar{t}_{a} = Arithmetic mean temperature difference

t_{A_{1} = Inlet temperature of the gas = 1100 K

t_{A_{2} = Outlet temperature of the gas = 733.33 K

t_{B_{1} =  Inlet temperature of the air = 300 K

t_{B_{2} = Outlet temperature of the air = 850 K

Hence, plugging in the values, we have;

\Delta \bar{t}_{a} =\frac{1100+733.33}{2} - \frac{300+850}{2} = 341\tfrac{2}{3} \, K = 341.67 \, K

Hence, from;

\dot{Q} = UA\Delta \bar{t}_{a}, we have

5912500  = 90 × A × 341.67

A = \frac{5912500  }{90 \times 341.67} = 192.3 \, m^2

Hence, the total tube surface area in m² required to achieve an air outlet temperature of 850 K = 192.3 m².

4 0
3 years ago
Discuss with your neighbor your brain as a computer.
Misha Larkins [42]
Senors are a type of device that produce a amount of change to the output to a known input stimulus.
Input signals are signals that receive data by the system and outputs the ones who are sent from it. Hope this helps ;)
6 0
3 years ago
Other questions:
  • What are the challenges posed by strategic information systems, and how should they be addressed?
    10·1 answer
  • Which is the correct order for handwashing
    11·2 answers
  • After a capacitor is fully chargerd, a small amount of current will flow though it. what is this current called?
    14·1 answer
  • Consider two water tanks filled with water. The first tank is 8 m high and is stationary, while the second tank is 2 m high and
    12·2 answers
  • As the impurity concentration in solid solution of a metal is increased, the tensile strength:________.a) decreasesb) increasesc
    9·1 answer
  • A 3-phase induction motor is being driven at a frequency of 80 Hz, and the motor speed is 1000 rpm. How many poles does the moto
    8·1 answer
  • Michelle is the general manager of a power plant. This morning, she will meet with city officials to discuss environmental issue
    5·1 answer
  • A river has an average rate of water flow of 59.6 M3/s. This river has three tributaries, tributary A, B and C, which account fo
    10·1 answer
  • In an RL parallel circuit, VT = 240 V, R = 330 Ω, and XL = 420 Ω. What is the Apparent Power (VA)?
    9·1 answer
  • Thermal energy measured by?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!