The compressed bitstream requires a total of 62 bits when we use Huffman for the string "it was the age of wisdom it was the age of foolishness".
Let's go through the process to construct the Huffman coding tree and calculate the compressed bitstream.
Step 1: Calculate the frequency of each character in the string.
Character | Frequencyspace | 12
w | 2
e | 2
a | 2
t | 4
h | 4
i | 4
s | 4
o | 4
f | 2
l | 2
g | 2
d | 2
m | 2
Step 2: Create a leaf node for each character with its frequency.
(12) space
(2) w
(2) e
(2) a
(4) t
(4) h
(4) i
(4) s
(4) o
(2) f
(2) l
(2) g
(2) d
(2) m
Step 3: Merge the two nodes with the lowest frequencies into a new internal node, whose frequency is the sum of the frequencies of its children. Repeat this process until there is only one node left.
(12) space
/ \
(4) s \
(8)
/ \
(4) t \
(4)
/ \
(2) h \
(2)
/ \
(2) o \
(2)
/ \
(2) w (2)
Step 4: Assign a 0 to the left branch and a 1 to the right branch of each internal node. This creates the Huffman coding tree.
(12) space
/ \
0 (4) s \
(8)
/ \
0 (4) t \
(4)
/ \
0 (2) h \
(2)
/ \
0 (2) o \
(2)
/ \
0 (2) w 1 (2)
Step 5: Generate the Huffman codes for each character by traversing from the root to each leaf node, assigning 0 for left branches and 1 for right branches.
Character | Huffman Codespace | 0
w | 111
e | 110
a | 101
t | 10
h | 01
i | 00
s | 011
o | 010
f | 0011
l | 0010
g | 0001
d | 0000
m | 0000
Step 6: Encode the original string using the generated Huffman codes.
Original String: "it was the age of wisdom it was the age of foolishness"
Encoded Bitstream: 00 111 10 010 00 011 01 00 011 10 010 00 011 01 00 0011 00 0010 00 0001 00 0000 00 0000
Step 7: Calculate the number of bits required for the compressed bitstream.
The compressed bitstream requires a total of 62 bits.
Learn more about bit: https://brainly.com/question/32332260
#SPJ11
true or false: since liquid can be considered as incompressible, the volume flow rates into and out of a steady flow device will remain constant.
Answer:
True
Explanation:
Since liquid can be considered as incompressible, the volume flow rates into and out of a steady flow device will remain constant. True, For a steady, incompressible flow, since the density is constant, it implies that the total volumetric flow rates entering and leaving a control volume are the same.
What does The vehicle dashboard includes
Answer: The vehicle dashboard includes the speedometer, tachometer, fuel gauge, temperature gauge, oil pressure gauge, and voltmeter.
Explanation:
Utility company power lines carry what kind of current?
Answer:
Alternating
Explanation:
Insert, into an empty binary search tree, entries with keys 30, 40, 24, 58, 48, 26, 11, 13 (in this order). Draw the tree after each insertion.
After each insertion, the binary search tree maintains its property, with left children being less than their parent, and right children being greater than their parent
When inserting the keys 30, 40, 24, 58, 48, 26, 11, 13 into an empty binary search tree, the tree evolves as follows:
1. Insert 30:
- 30
2. Insert 40:
- 30
\
40
3. Insert 24:
- 30
/ \
24 40
4. Insert 58:
- 30
/ \
24 40
\
58
5. Insert 48:
- 30
/ \
24 40
\
58
/
48
6. Insert 26:
- 30
/ \
24 40
\ \
26 58
/
48
7. Insert 11:
- 30
/ \
24 40
/ \ \
11 26 58
/
48
8. Insert 13:
- 30
/ \
24 40
/ \ \
11 26 58
\ /
13 48
Know more about insertion here:
https://brainly.com/question/30667459
#SPJ11
.
5. The maximum scaffold height not requiring toeboards is 20 feet.
A. True
B. False
Water flows around a 6-ft diameter bridge pier with a velocity of 12 ft/s. Estimate the force (per unit length) that the water exerts on the pier. Assume that the flow can be approximated as an potential fluid flow around the front half of the cylinder, but due to flow seperation, the average pressure on the rea half is constant and approximately equal to 1/2 the pressure at point A.
Answer: hello the diagram related to your question is missing please the third image is the missing part of the question
Fx = 977.76 Ib/ft
Explanation:
Estimate the force that water exerts on the pier
V = 12 ft/s
D( diameter ) = 6 ft
first express the force on the first half of the cylinder as
Fx1 = - \(-2\int\limits^\pi _\frac{\pi }{2} {Ps*cos\beta *a} \, d\beta\) ---------------- ( 1 )
where ; Fy = 0
Ps = Po + 1/2 Pv^2 ( 1 - 4 sin^2β ) ------------- ( 2 )
Input equation (2) into equation ( 1 ) (note : assuming Po = 0 )
attached below is the remaining part of the solution
Which of the following is NOT used to stabilize a vehicle involved in a collision?
A. Strut
B. Cribbing
C. Nader pin
D. Step chock
Among the options provided, the Nader pin is NOT used for stabilization.
So, the correct answer is C.
Instead, it is a component of the vehicle door latch system that helps secure the door.
In a vehicle collision scenario, various tools and techniques are employed to stabilize the vehicle and ensure safety.
On the other hand, a strut (A) is a support device that holds the vehicle in place, cribbing (B) consists of wooden or plastic blocks placed beneath the vehicle to prevent movement, and step chocks (D) are wedge-shaped supports placed under the tires to prevent rolling.
These three tools contribute to vehicle stabilization, while the Nader pin does not.
Hence, the answer is C.
Learn more about stabilization at https://brainly.com/question/3193722
#SPJ11
Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. - Guess only the suit of the card. - Guess both the face value and the suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
how am I going to do this, I have a friend that might be able to help I will check
In certain island of the Caribbean there are N cities, numbered from 1 to N . For each ordered pair of cities (u, v) you know the cost c[u][v] > 0 of flying directly from u to v. In particular, there is a flight between every pair of cities. Each such flight takes one day and flight costs are not necessarily symmetric. Suppose you are in city u and you want to get to city v. You would like to use this opportunity to obtain a frequent flyer status. In order to get the status, you have to travel on at least minDays consecutive days. What is the minimum total cost c(u, v) of a flight schedule that gets you from u to v in at least minDays days? Design a dynamic programming to solve this problem. Assume you can access c[x][y] for any pair x, y in constant time. You are also given N, u, v and minDays ≤N
Hint: one way to solve this problem is using dynamic states similar to those on Bellman-Ford’s algorithm.
Answers Needed:
(a) Define the entries of your table in words. E.g., T (i) or T (i, j) is ....
(b) State recurrence for entries of table in terms of smaller subproblems.
(c) Write pseudocode for your algorithm to solve this problem.
(d) Analyze the running time of your algorithm.
The running time of the algorithm is O(N^4), because there are four nested loops, each of which runs for N iterations.
(a) Define the entries of your table in words:
T(i, j, k) is the minimum total cost of a flight schedule that gets you from city i to city j in exactly k days.
(b) State recurrence for entries of table in terms of smaller subproblems:
T(i, j, k) = min { T(i, l, k-1) + c[l][j] } for all l in {1, ..., N}
This means that the minimum total cost of a flight schedule from city i to city j in exactly k days is the minimum of the total cost of a flight schedule from city i to city l in k-1 days plus the cost of a direct flight from city l to city j, for all possible intermediate cities l.
(c) Write pseudocode for your algorithm to solve this problem:
```
// Initialize the table with infinity for all entries
for i in {1, ..., N}:
for j in {1, ..., N}:
for k in {1, ..., N}:
T(i, j, k) = infinity
// Base case: the cost of a direct flight from city i to city j in 1 day is c[i][j]
for i in {1, ..., N}:
for j in {1, ..., N}:
T(i, j, 1) = c[i][j]
// Fill in the table using the recurrence
for k in {2, ..., N}:
for i in {1, ..., N}:
for j in {1, ..., N}:
for l in {1, ..., N}:
T(i, j, k) = min(T(i, j, k), T(i, l, k-1) + c[l][j])
// The answer is the minimum total cost of a flight schedule from city u to city v in at least minDays days
answer = min { T(u, v, k) } for all k in {minDays, ..., N}
```
(d) Analyze the running time of your algorithm:
The running time of the algorithm is O(N^4), because there are four nested loops, each of which runs for N iterations.
Learn more about The running time of the algorithm:
https://brainly.com/question/14553308
#SPJ11
Users regularly log on with a username and password. However, management wants to add a second authentication factor for any users who launch the gcga application. The method needs to be user-friendly and non-disruptive. Which of the following will BEST meet these requirements?An authentication applicationTPMHSMPush notifications
Push notifications would likely be the best option for adding a second authentication factor that is user-friendly and non-disruptive.
An authentication application, such as a token generator or authenticator app, could also be a good choice, as it would allow users to easily complete the second authentication step without having to remember additional passwords or codes.
TPM (Trusted Platform Module) and HSMs (Hardware Security Modules) are hardware-based security measures that can provide additional protection for sensitive data, but they may not be as user-friendly or non-disruptive as the other options.
It's worth considering the specific needs and requirements of your organization and the users in deciding which option to choose.
Learn more about authentication, here https://brainly.com/question/29752591
#SPJ4
T/F : ASD loading combination is shown in a) and LRFD loading combination is shown in b).
a) D+L+(Lr or S or R)
b) 1.2D+1.6L+0.5(Lr or S or R)
True. The statement is true. In structural engineering, ASD (Allowable Stress Design) and LRFD (Load and Resistance Factor Design) are two common methods used for designing structures and determining loading combinations.
In ASD, the loading combination is typically represented as:
a) D+L+(Lr or S or R)
where:
D represents dead load,
L represents live load,
Lr represents roof live load, and
S and R represent other specified loads.
On the other hand, in LRFD, the loading combination is represented as:
b) 1.2D+1.6L+0.5(Lr or S or R)
where:
D represents factored dead load,
L represents factored live load,
Lr represents factored roof live load, and
S and R represent factored other specified loads.
The factors (1.2, 1.6, and 0.5) in the LRFD loading combination account for the higher safety margins required in the design process.
Learn more about engineering here
https://brainly.com/question/28321052
#SPJ11
Even in the Max A/C mode, some systems provide for up to 50 percent fresh air.
Recirculated air is the primary source of air in the MAX cooling position. A customer reports that no matter what temperature range is selected on the control panel, the passenger compartment temperature is either consistently too hot, cold, or stays the same.
What Max A/C systems provide for to 50 percent fresh air?Pressurization is necessary for a refrigeration system. If the compressor is removed, the refrigerant in the air conditioner remains stationary.
Therefore, The high-pressure gas refrigerant reaches the condenser after exiting the compressor, where it changes from a gas to a liquid.
Learn more about fresh air here:
https://brainly.com/question/24644166
#SPJ1
What flow type occurs when the heat exchanger has multiple passes and baffles?
Cross flow
Laminar flow
Parallel flow
Hybrid flow
A body of weight 300N is lying rough
horizontal plane having
a Coefficient of friction as 0.3
Find the magnitude of the forces which can move the
body while acting at an angle of 25 with the horizonted
Answer:
Horizontal force = 89.2 N
Explanation:
The frictional force = coefficient of friction * magnitude of the force (weight of the body) * cos theta
Substituting the given values, we get -
Frictional Force = 0.3*300 * cos 25 = 89.2 N
Horizontal force = 89.2 N
Hierarchy of hazard control
Answer:
A system for controlling risk in the workspace.
Suppose that all the dislocations in 3000 mm3 of crystal were somehow removed and linked end to end. Given 1 m =0.0006214 mile, how far (in miles) would this chain extend for dislocation densities of (a) 10^4 mm^-2 (undeformed metal)? (b) 10^10 mm-2 (cold-worked metal)?
Answer:
please let me know the answer to this because I need to know as well. thanks
duo-servo drum brake systems are being discussed. technician a says the primary shoe lining is often thicker than the secondary shoe lining. technician b says the primary shoe typically has more lining surface area than the secondary shoe. who is correct?
Neither A nor B, as the secondary shoe of a duo servo drum brake has 70% greater braking power than the primary shoe.
The secondary shoe has more lining than the primary shoe since it handles the majority of the braking.
Drum brakes are still often utilised on the rear axles of modern automobiles and are ubiquitous on classic cars. The duo-servo drum break, self-adjusting drum brake can produce as much stopping force as a disc brake and will give many, many miles of maintenance-free driving, even though disc brakes are easier to use and more resistant to heat fade.
Duo-servo drum brake systems have a pair of brake shoes connected by an adjuster at the bottom and a hydraulic wheel cylinder towards the top. Above the wheel cylinder, the highest tips of the shoes rest against an anchor pin.
Learn more about Duo servo drum brake here:
https://brainly.com/question/14937026
#SPJ4
An insulated vertical cylinder Contains 0.1 kg Argon gas with the help of a frictionless non- conducting piston as shown in the figure . The mass of the piston is 5kg and initially rest on the bottom of the cylinder. The cylinder connected to nitrogen tank at 100 bar to a pipeline fitted with the valve The valve is opened and nitrogen slowly enters the cylinder. During this process the piston is lifted and to height of 10cm by Nitrogen gas. The initial pressure and temperature of argon are 300K and 1 bar. The final temperature of argon gas is 320K for argon R = 0.208 kJ/kgK and r = 1.67 Find the net work done by the Nitrogen
The net work done by the Nitrogen in lifting the mass and the pressure is; W_n = 0.6257 kJ
What is the net work done?We are given;
Mass of argon; m_a = 0.1 kg
mass of piston; m_p = 5 kg
Pressure 1; p₁ = 100 kPa
Temperature 1; T₁ = 300 K
Temperature 2; T₂ = 320 K
Ideal gas constant; R = 0.208 kJ/kg.K
γ = 1.67
Since the reaction is adiabatic and slowly reversible, then we will use the formula; PV^(γ) = C
Thus, work done by argon is;
W_ar = [m_a * R(T₁ - T₂)]/(γ - 1)
W_ar = [0.1 * 0.208(300 - 320)]/(1.67 - 1)
W_ar = -0.6028 kJ
Work done by nitrogen will be;
W_n = |W_ar| + (m_p * g * m_a)/1000
W_n = 0.6028 + (5 * 9.81 * 0.1)/1000
W_n = 0.6257 kJ
Read more about net work done at; https://brainly.com/question/25573309
A certain printer requires that all of the following conditions be satisfied before it will send a HIGH to la microprocessor acknowledging that it is ready to print: 1. The printer's electronic circuits must be energized. 2. Paper must be loaded and ready to advance. 3. The printer must be "on line" with the microprocessor. As each of the above conditions is satisfied, a HIGH is generated and applied to a 3-input logic gate. When all three conditions are met, the logic gate produces a HIGH output indicating readiness to print. The basic logic gate used in this circuit would be an): A) NOR gate. B) NOT gate. C) OR gate. D) AND gate.
Answer:
D) AND gate.
Explanation:
Given that:
A certain printer requires that all of the following conditions be satisfied before it will send a HIGH to la microprocessor acknowledging that it is ready to print
These conditions are:
1. The printer's electronic circuits must be energized.
2. Paper must be loaded and ready to advance.
3. The printer must be "on line" with the microprocessor.
Now; if these conditions are met the logic gate produces a HIGH output indicating readiness to print.
The objective here is to determine the basic logic gate used in this circuit.
Now;
For NOR gate;
NOR gate gives HIGH only when all the inputs are low. but the question states it that "a HIGH is generated and applied to a 3-input logic gate". This already falsify NOR gate to be the right answer.
For NOT gate.
NOT gate operates with only one input and one output device but here; we are dealing with 3-input logic gate.
Similarly, OR gate gives output as a high if any one of the input signals is high but we need "a HIGH that is generated and applied to a 3-input logic gate".
Finally, AND gate output is HIGH only when all the input signal is HIGH and vice versa, i.e AND gate output is LOW only when all the input signal is LOW. So AND gate satisfies the given criteria that; all the three conditions must be true for the final signal to be HIGH.
Implement a Java method sumArray that is passed a double array a as its parameter and returns the sum of the values contained within the array a.
To implement a Java method sumArray that returns the sum of the values in a given double array, you can write the following code.
This method takes in a double array as its parameter and initializes a variable called "sum" to zero. It then iterates through the array using a for loop, adding each value in the array to the sum. Finally, it returns the total sum of the values in the array. The sumArray method starts by creating a variable called "sum" and setting it equal to zero. This variable will be used to keep track of the total sum of the array values. For each index in the array, the method adds the value at that index to the "sum" variable using the += operator. This will accumulate the sum of all the values in the array.
```java
public static double sumArray(double[] a) {
double sum = 0;
for (int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
```
To know more about Java method visit:-
https://brainly.com/question/16996584
#SPJ11
for an 8 story office building, how many pounds of steel would you expect to have per square foot of building space? 8 psf 10 psf 13 psf 18 psf 35 psf
The amount of steel you would expect to have per square foot of building space in an 8-story office building is 10 psf.
In an 8-story office building, the weight of steel per square foot of building space can vary depending on the design and construction specifications. However, as a general guideline, a typical steel-framed office building would have around 10 pounds of steel per square foot of building space. This includes the weight of structural steel columns, beams, and other components necessary to support the building's weight and provide structural integrity.
It's important to note that the actual weight of steel can vary based on factors such as the building's design, height, and intended use. Therefore, it's always recommended to consult with a structural engineer or architect for a more precise estimation based on the specific requirements of your project.
Know more about building space, here:
https://brainly.com/question/29889520
#SPJ11
Briefly explain what is meant by a subcritical refrigeration cycle, and list its four process.
A subcritical refrigeration cycle is a type of refrigeration cycle that operates below the critical point of the refrigerant. The critical point is the temperature and pressure at which the refrigerant transitions between the liquid and gas phases without any distinction between them.
In a subcritical cycle, the refrigerant remains in the liquid phase during the entire cycle.
The four processes involved in a subcritical refrigeration cycle are:
Compression: The refrigerant enters the compressor as a low-pressure vapor and is compressed to a higher pressure and temperature.
Condensation: The compressed refrigerant flows into the condenser, where it releases heat to the surroundings and changes from a high-pressure vapor to a high-pressure liquid.
Expansion: The high-pressure liquid refrigerant enters the expansion valve or throttle valve, where its pressure is reduced, causing it to partially vaporize and cool.
Evaporation: The partially vaporized refrigerant flows into the evaporator, where it absorbs heat from the surrounding environment, completing the cooling process. The refrigerant then returns to the compressor to start the cycle again.
In a subcritical refrigeration cycle, the cooling effect is achieved through the evaporation of the refrigerant in the evaporator, while the condenser rejects heat to the surroundings.
Learn more about refrigerant here
https://brainly.com/question/29510163
#SPJ11
what could happen if the engine was uncowled during the starting and operating procedures
If an engine fails during rollout or just before takeoff, immediately shut both throttles and land the aircraft safely. Before reaching a safe single engine speed right away after takeoff, drop your nose to increase velocity.
What is the engine starting procedure?Closing the throttle, turning off the fuel pump, setting the mixture control to idle cutoff, and simply cranking the engine is the most reliable hot start method I've found.
What is the procedure for engine failure?If an engine fails during rollout or just before takeoff, immediately shut both throttles and land the aircraft safely. Before reaching a safe single engine speed right away after takeoff, drop your nose to increase velocity. If you are unable to climb, close both throttles and land straight ahead.
What happens if engine fails during take off?The typical practice for the majority of aircraft would be to abandon takeoff if an engine failed during takeoff. In small aircraft, the pilot should turn the throttles down to idle, activate the speed brakes (if provided), and apply the brakes as needed if the engine fails before VR (Rotation Speed).
To learn more about engine procedure refer to:
https://brainly.com/question/18428188
#SPJ1
When you lift an object by moving only your forearm, the main lifting muscle in your arm is the biceps. Suppose the mass of a forearm is 1.00 kg. If the biceps is connected to the forearm at a distance = 3.50 cm from the elbow, how much force must the biceps exert to hold a 600 g ball at the end of the forearm at distance dball=37.0 cm from the elbow, with the forearm parallel to the floor?
To calculate the force that the biceps must exert to hold a 600 g ball at the end of a forearm that has a mass of 1.00 kg and is parallel to the floor, we can use the principles of torque and equilibrium.
First, we need to calculate the torque of the forearm due to its weight, which is acting at its center of mass (which we can assume is at the midpoint of the forearm). The weight of the forearm can be calculated as W_forearm = m_forearm * g, where m_forearm = 1.00 kg is the mass of the forearm and g = 9.81 m/s^2 is the acceleration due to gravity. The distance from the elbow to the midpoint of the forearm is L_forearm/2 = 17.5 cm, or 0.175 m. Therefore, the torque due to the weight of the forearm is:τ_forearm = W_forearm * L_forearm/2 = (1.00 kg * 9.81 m/s^2) * 0.175 m = 1.71 NmNext, we need to calculate the torque due to the weight of the ball, which is acting at a distance of dball = 37.0 cm from the elbow. The weight of the ball can be calculated as W_ball = m_ball * g, where m_ball = 0.600 kg is the mass of the ball. Therefore, the torque due to the weight of the ball is:τ_ball = W_ball * dball = (0.600 kg * 9.81 m/s^2) * 0.370 m = 2.24 NmFinally, we need to calculate the force that the biceps must exert to hold the ball at equilibrium, i.e. when the torque due to the weight of the forearm is equal and opposite to the torque due to the weight of the ball. Since the torque due to a force is τ = F * d, where F is the force and d is the distance from the point of application of the force to the pivot point (which is the elbow in this case), we can write:F_biceps * d_biceps = τ_ball - τ_forearmwhere d_biceps = 3.50 cm = 0.035 m is the distance from the elbow to the point where the biceps is attached to the forearm. Substituting the values for τ_ball and τ_forearm, we get:
To learn more about biceps click on the link below:
brainly.com/question/15246326
#SPJ11
what should we what point should be considered while writing scientific name
When you write a scientific name using the binomial nomenclature system, there are a few things to think about such as those given below.
What is writing scientific nameGenus and species: The scientific name has two parts—the genus name and the species name. When you print them, they should be written in slanted letters called italics. If you write them by hand, you can underline them instead. For instance, humans.
Capitalization: The name of the group is always written with a capital letter, while the specific name is written with small letters. For instance, consider the bacteria called Escherichia coli.
Read more about scientific name here:
https://brainly.com/question/30598476
#SPJ1
in an uncontrolled intersection, where two vehicles approach the intersection at approximately the same time, who must yield?
The vehicle on the left must yield to the vehicle on the right.
What is vehicle
Vehicle is a means of transportation that is used to travel from one place to another. It can be a car, truck, motorcycle, bus, train, boat, airplane, or any other device used to transport people or goods. Vehicles are powered by an engine, either internal combustion or electric, and can be operated manually or automatically. Vehicles can come in different shapes and sizes, from large commercial trucks to small motorbikes. Vehicle safety features, such as seatbelts, airbags, and antilock brakes, are important for ensuring the safety of passengers and other road users.
To know more about vehicle
https://brainly.com/question/24745369
#SPJ4
Write a python script using while loop which display the number list with an increment of 3 between 1 and 25. Display the output in one row as shown.
Answer:
num_count = 0
while num_count < 25:
print(num_count)
num_count += 3
Explanation:
A while loop statement is defined in the python source code above. An integer variable 'num_count' is defined and continuously incremented by three in the loop until it is greater than 25. the output of the while loop between 1 and 25 is print on the screen.
Pie charts should have no more than eight segments. True or False?
Answer:
Explanation:
Pie charts generally should have no more than eight segments.
You've used your windows workstation to map a drive to a shared folder on a Windows server. Which protocol was used to access the share?
The protocol used to access the shared folder on a Windows server from a Windows workstation is the Server Message Block (SMB) protocol.
This protocol allows for the sharing of files, printers, and other resources between different computers on a network. When a user maps a drive to a shared folder on a Windows server, they are essentially creating a virtual connection between their workstation and the server.
This connection is established using the SMB protocol, which is the most commonly used protocol for file sharing on Windows networks. SMB allows for the transfer of files and other data between different devices on a network, and provides the necessary security and authentication mechanisms to ensure that only authorized users are able to access shared resources.To know more about Server Message Block visit:
https://brainly.com/question/31619483
#SPJ11
Integer dataSize is read from input. Then, strings and integers are read and stored into string vector colorList and integer vector quantityList, respectively. Lastly, string colorAsked is read from input.
Find the sum of the elements in quantityList where the corresponding element in colorList is equal to colorAsked.
For each element in colorList that is equal to colorAsked, output "Index " followed by the element's index. End with a newline.
Ex: If the input is:
3
lavender 25 lavender 22 gray 161
lavender
Then the output is:
Index 0
Index 1
Total: 47
#include
#include
using namespace std;
int main() {
int numElements;
string colorAsked;
int sumQuantity;
unsigned int i;
cin >> numElements;
vector colorList(numElements);
vector quantityList(numElements);
for (i = 0; i < colorList.size(); ++i) {
cin >> colorList.at(i);
cin >> quantityList.at(i);
}
cin >> colorAsked;
/*answer here*/
cout << "Total: " << sumQuantity << endl;
return 0;
}
Where the above condition is given, here's the solution:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int numElements, sumQuantity = 0;
string colorAsked;
unsigned int i;
cin >> numElements;
vector<string> colorList(numElements);
vector<int> quantityList(numElements);
for (i = 0; i < colorList.size(); ++i) {
cin >> colorList.at(i);
cin >> quantityList.at(i);
}
cin >> colorAsked;
for (i = 0; i < colorList.size(); ++i) {
if (colorList.at(i) == colorAsked) {
cout << "Index " << i << endl;
sumQuantity += quantityList.at(i);
}
}
cout << "Total: " << sumQuantity << endl;
return 0;
Learn more about vectors on:
https://brainly.com/question/13322477
#SPJ1