Write a program that will find several trait of a collection

Assignment Help Computer Engineering
Reference no: EM132087384

Overview

In this lab, you will write a program that will find several traits of a collection of NN numbers. Get the value of NN before scanning each value in the collection of NN numbers.

You can assume NN will be an integer, but you must check that it is greater than or equal to 0 (0=N0=N).

If the value of NN provided by the user is outside of the expected range, the program should print an error and prompt the user again for NN.

It should continue to do this until the user enters a number that is valid.

Once you have the value of NN, your program must loop that many times, calling a get_input() function to get the next value in the collection from the user. With these values, you are to calculate and display the following information:

Smallest Number

Largest Number

Average

Range of values (e.g. how many between smallest and largest?)

standard deviation =vSN-a2=SN-a2, where SS is the sum of squares of the values in the collection, and aa is the average.

Analysis

To write this program (or any program) it helps to first identify what the inputs and outputs of the program should be. It also helps to identify any supporting data required by the formulas, for example, values required by the formula but not explicitly output to the user.
In this case, the program is asking for several number as input, and produces as output several traits of that particular collection of numbers.

Inputs

N=N= An integer value, this is how many numbers are in the number collection. Should be greater than or equal to zero.

List of numbers = NN different numbers, input one after the other. These should be real numbers (data type double or float).

Supporting Data

sum = The sum of all of the numbers in the list so far

sum_squares = The sum of the squares of all the numbers in the list so far

Outputs

lowest = The lowest number in the list

highest = The highest number in the list

average = The average of all the numbers

range = The difference between the highest and lowest number. Should be positive or 0.

standard deviation = The standard deviation, as calculated by the above formula.

Algorithm Design

Pseudocode is a way to write an algorithm in a language agnostic sort of way. It is up to you, the programmer, to translate these generic instructions into C statements. Remember to look at the examples on the class website if you get stuck on exactly what syntax to use.

function get_n(): set N = -1 loop: do { Prompt user for a value of N if N < 0: print error message else break // ends loop end if } while ( N < 0 ) return N end function function main(): set N = get_N(); set lowest = DBL_MAX, highest = -DBL_MAX; loop from 0 -> N: current = get_input() if current < lowest: set lowest = current if current > highest: set highest = current set sum = sum + current set sum_squares = sum_squares + current^2 end loop set range = highest - lowest if n == 0: set average = 0, std_dev = 0; else: set average = sum / n set std_dev = square_root( ( sum_squares / n ) - average^2 ) end if print out all results end function
Implementation Hints

This should be added with your other include statements:

#include <float.h>
Then, during your loop, save the current input value into highest if it is greater than the current value of highest, and save it into lowest if the value is less than the current value in lowest.

You may want to re-use your get_input() function from Lab 2. You'll call it repeatedly from inside a loop, to get all of the values in the collection.

double get_input(void) { /* your code here */ }
You should write a second function, get_n(), that takes in an integer instead of a real number. You will count to this number using a loop, and you should only ever use integers for that purpose. This function should use a do...while loop to prompt the user to input a value that is greater than or equal to 0, and continue prompting the user until they enter such a value.

Use a for loop to count from 0 to NN.

Calculate the values of sum and sum_squares inside the for loop, as running totals.

Keep track of the lowest and highest values as you see them during the for loop as well.

After the for loop is complete, you have enough information to calculate the rest of the required data.

In order to use the sqrt and pow functions, you will need to include the math standard library. This should be added with your other include statement:

#include <math.h>
In addition, when you compile your program, you should include the -lm flag, so that the math library will be included in the build.

To find the highest and lowest number, set the variable highest to the lowest possible value for a double, and the variable lowest to the highest possible double value. If you include the standard library <float.h>, you can use the pre-defined constant DBL_MAX for this purpose.

double highest = -DBL_MAX, lowest = DBL_MAX;
You will need to check for the case when NN is zero, and handle that gracefully (e.g. no divide by zero errors, just return 0 instead).

Compile & Test

Compile your program using this gcc command. c99 is a shortcut for running gcc -std=c99, which uses the C99 standard instead of the default C89 standard. -lm includes the math libraries.

$ c99 lab3.c -lm -o program3

Reference no: EM132087384

Questions Cloud

Determine how many of each item should be ordered : Imagine that you are a merchant and need to keep better tabs on your merchandise to know when to reorder supplies.
Nodes of ranvier in a myelinated nerve : What would happen if you lost the nodes of Ranvier in a myelinated nerve? Would the message travel faster, slower
Write a program that will find several trait of a collection : Write a program that will find several traits of a collection of NN numbers. Get the value of NN before scanning each value in the collection of NN numbers.
Why do pain receptors do not undergo adaptation : Why do pain receptors do not undergo adaptation, but other receptor types do?
Calculate the sum of the digits in the odd-numbered position : Calculate the sum of the digits in the odd-numbered position (first, third, ..., eleventh). Multiply this sum by three.
Develop a portfolio of draft planning documentation : BSBPMG522 Undertake project work Assignment - You will determine the scope of a project and develop a portfolio of draft planning documentation
Can you find illusions for other senses : Why is it easier to fool the eyes, compared to fooling to your sense of touch? Can you find illusions for other senses? How do they work?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd