Question

In: Computer Science

You should use Visual Studio to write and test the program from this problem.   Write a...

You should use Visual Studio to write and test the program from this problem.  

Write a complete program with a for loop that

  • (5 pts) uses proper variable types.
  • (10 pts) uses a for loop to read in a real numbers exactly 8 times
  • (10 pts) adds the number read in the loop to a running sum.
  • (10 pts) Computes the average of the 8 numbers as a real number.
  • (5 pts) Prints the correct result with 2 decimal places, no text with the result.
  • Your program must NOT prompt the user for each number and must only print the answer, no text. (You will lose points!)

Solutions

Expert Solution

Following is the code and output screenshot along with comments in the code.

<!-- HTML5 Structure is as follows -->
<!DOCTYPE html>
<!-- It is your choice to set langugae as english or any other language that you would like. -->
<html lang="en">
<!-- Here is the head part, where we give title to the project of file and add all the links/ scripts that we need to use in our project. -->

<head>
    <!-- meta tags are just used to tell the search engines what kind of content we are offering in our project and charset defines the documents character set. -->
    <meta charset="UTF-8">
    <!-- Here you can give a title to your project. -->
    <title>Web App</title>
</head>


<body onload="getData()">
    <!-- We will be displaying result here. -->
    <div id="result"></div>

    <!-- Adding a script tag here for javascript function that we are going to run on page load. -->
    <script>
        //Creating a function here to display the result on screen based on for loop on page load.
        function getData() {

            let numArr = [1, 2.1, 1.2, 3, 4, 5, 7, 6]; //Creating array of real numbers(8 items) to sum up using a for loop.
            let sum = 0;//Initialise the sum to 0.
            let count = 0; //Initialising the count to 0.

            // Applying a for loop on the numArr till count is 8 and printing the result on the screen.
            for (count; count <= 8; count++) {
                sum = sum + numArr[count]; //Adding the array items till count is 8

                // Checking if count is till index 7 which counts till 8 and displaying the data on screen upto two decimal points.
                if (count == 7) {
                    sum = sum / numArr.length; //Getting the average of the sum by dividing the sum with the count.
                    document.getElementById("result").innerHTML = sum.toFixed(2); //Displaying the result on screen using document upto 2 decimals.
                }
            }

        }

    </script>

</body>

</html>




Here is the Output.


I hope you find the answer helpful. I have added comments along with code. In case you have any doubt, please let me know in the comment section below. Also, please give it a thumbs up. Thank you.


Related Solutions

use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Using Visual Studio write a program that allows the user to enter multiple scores ranging from...
Using Visual Studio write a program that allows the user to enter multiple scores ranging from 0 to 100, computes the average of those scores and then writes out a letter grade using the typical grading scale. Your program will also: 1. Allow the user to enter any number of scores he or she wishes but assume there will be at least one score entered. 2. Use a sentinel-controlled loop variable to terminate the loop when the user has no...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
Please use assembly language x86 Visual Studio Write a program to add the following word size...
Please use assembly language x86 Visual Studio Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one array of size 24 to another array of size 24 using string instructions. Write 3 versions of this code. One code must copy byte at a time. One code must copy word at a time and one code must copy double word at a time. Cut and paste the array in memory to show your code is working.
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
CIS247C WEEK 2 LAB The following problem should be created as a project in Visual Studio,...
CIS247C WEEK 2 LAB The following problem should be created as a project in Visual Studio, compiled and debugged. Copy your code into a Word document named with your last name included such as: CIS247_Lab2_Smith. Also include screen prints of your test runs. Be sure to run enough tests to show the full operation of your code. Submit this Word document and the project file (zipped). The Zoo Class This class describes a zoo including some general visitor information. We...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT