Question

Asked Oct 24, 2019

Use the Design Recipe to write a function weighted_total(number_list,weights) that consumes a list of numbers and a list of weights and returns the weighted total of the numbers. If the numbers are [1,2,3] and the weights are [0.1,0.5,0.4] then the weighted total should be 1 * 0.1 + 2 * 0.5 + 3 * 0.4 = 2.3

Think about what needs to happen before using a loop, during the loop, and after the loop finishes. In this question you are required to use a for loop, and **not** allowed to use the sum function.

Step 1

The given list of numbers is [1, 2, 3].

The given weights are [0.1, 0.5, 0.4].

weighted_total(number_list, weights) function is used to perform multiplication of the given list of numbers and given weights and return total weights of the number.

In the main function,

Take a integer type variable numberList[] that store 1,2 and 3.

Take a floating type variable weights[] that store 0.1, 0.5, and 0.4.

Create a variable totalWeight that stores total weighted value return by function weighted_total.

Call function weighted_total with numberList and weights parameters.

And dis...

Tagged in

Q: Business example: Precision Tools sells a line of high-quality woodworking tools. When customers pla...

A: Context diagram:The Context Diagram shows the system being viewed as a single high-level entity and ...

Q: How would you modify the dynamic programming algorithm for the coin collecting problem if some cells...

A: Coin collecting problemIn a n-m board, several coins are placed in such a way no more than one coin ...

Q: What was Networking?

A: Networking:Networking, also known as computer networking, is the practice of transporting and exchan...

Q: Databse SQL Queries. Need to write the SQL code for pulling the total cost of our inventory. We have...

A: A SQL query is to be written that will give the total cost of inventory. Two tables are given named ...

Q: In Lab 2, you created a menu for a simple calculator program. In this lab, you will add some functio...

A: A C++ program for the given scenario is provided below;Program://Declare necessary header files#incl...

Q: What is the difference between Computer Science and Computer Engineering?

A: Difference between computer science and computer engineeringBoth computer science and engineering be...

Q: Write the pseudocode and Flowchart for a program that simulates the Magic eight ball game.

A: Pseudocode:Pseudocode is a detailed description of the algorithm of a program that is easier to read...

Q: Please put into SOP formxz + (xy + ~z)

A: A Boolean expression is said to be in the Canonical form either it has purely min-terms or max-terms...

Q: Using Java Eclipse IDE write the following program:

A: Following program prompts the user to enter 10 numbers and invokes the method public static double m...