SlideShare a Scribd company logo
1 of 7
Download to read offline
Educational Objectives: After successfully completing this assignment, the student should be
able to accomplish the following:
Use a loop structure to read user input of unknown size through std::cin and store it in an array.
Use conditional branching to selectively perform computational tasks.
Declare (prototype) and define (implement) functions.
Declare and define functions with arguments of various types, including pointers, references,
const pointers, and const references.
Call functions, making appropriate use of the function arguments and their types.
Make decisions as to appropriate function call parameter type, from among: value, reference,
const reference, pointer, and const pointer.
Create, edit, build and run multi-file projects using the Linux/Emacs/Make environment
announced in the course organizer.
Operational Objectives: Create a project that computes the mean and median of a sequence of
integers received via standard input.
Deliverables: Files: stats.h, stats.cpp, main.cpp, makefile, log.txt. Note that these files constitute
a self-contained project.
Assessment Rubric: The following will be used as a guide when assessing the assignment:
Please self-evaluate your work as part of the development process.
Background
Given a finite collection of n numbers:
The mean is the sum of the numbers divided by n, and
The median is the middle value (in case n is odd) or the average of the two middle values (in
case n is even).
Note that to find the median of a collection of data, it is convenient to first sort the data, that is,
put the data in increasing (or non-decreasing) order. Then the median is just the middle datum in
the sorted sequence (or the average of the two middle data, if there are an even number).
One of the more intuitive sort algorithms is called Insertion Sort, which operates on an array
a[0..n-1] of elements. The idea is to "insert" the value of a[i] into the sub-array a[0..i-1] at the
largest possible index that results in the expanded sub-array a[0..i] sorted. We insert at the
highest possible index in order not to place the value ahead of any previously inserted elements
with the same value. The subarray a[0..i-1] is assumed to be sorted at the beginning of each
insertion step. The base case consists of a one-element array a[0..0], which is always sorted.
Here is a "pseudocode" description of the algorithm:
The inner loop copies all elements in a[0..i-1] up one index until the correct place for t is found.
Then put t in that place.
Procedural Requirements:
Begin a log file named log.txt. This should be an ascii text file in cop3330/proj1 with the
following header:
This file should document all work done by date and time, including all testing and test results.
Create and work within a separate subdirectory cop3330/proj1. Review the COP 3330 rules
found in Introduction/Work Rules.
Copy all of the files from LIB/proj1. These should include:
In addition you should have the script submit.sh in either your .bin or your proj1 as an executable
command.
Create three more files
complying with the Technical Requirements and Specifications stated below.
Turn in four files stats.h, stats.cpp, main.cpp, and makefile using the submit script.
Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to
submit projects. If you do not receive the second confirmation with the contents of your project,
there has been a malfunction.
After submission, take Quiz 1 in Blackboard. This quiz covers these areas:
Casting; integer and floating point arithmetic.
Function calls
Loops
This assignment
Course Syllabus
Note that the quiz may be taken several times. The highest of the grades will be recorded and
count as 20 points (40 percent of the assignment).
Technical Requirements and Specifications
The project should compile error- and warning-free on linprog with the command make stats.x.
The number of integers input by the user is not known in advance, except that it will not exceed
100. Numbers are input through standard input, either from keyboard or file re-direct. The
program should read numbers until a non-digit or end-of-file is encountered or 100 numbers have
been read.
Once the input numbers have been read, the program should calculate the mean and median and
then report these values to standard output.
The source code should be structured as follows:
Implement separate functions with the following prototypes:
I/O is handled by function main(); no other functions should do any I/O
Function main() calls Mean() and Median()
Function Median() calls Sort()
The source code should be organized as follows:
Prototypes for Mean, Median, and Sort should be in file stats.h
Implementations for Mean, Median, and Sort should be in file stats.cpp
Function main should be in file main.cpp
The Sort() function should implement the Insertion Sort algorithm.
When in doubt, your program should behave like the distributed executable example stats_i.x in
area51. Identical behavior is not required, but the general I/O behavior should be the same. In
particular, the data input loop should not be interupted by prompts for a next datum - this will
make file redirect cumbersome. Just ask for the data one time, then read until a non-digit or end
of file is encountered.
Hints
An example executables is distributed as [LIB]/area51/stats_i.x. The suffix indicates it is
compiled to run on the Intel/Linux architecture (linprog machines).
To run a sample executable, follow these steps: (1) Copy the appropriate executable into your
space where you want to run it: log in to linprog and enter the command "cp
[LIB]/area51/stats_i.x .". (2) Change permissions to executable: "chmod 700 stats_i.x". (3)
Execute by entering the name of the executable. If you want to run it on a data file "data1", use
input redirect as in: "stats_i.x < data1". If you want the output to go to another file, use output
redirect: "stats_i.x < data1 > data1.out".
A working makefile is distributed and may be used in the submission - provided that you have
read and understood the makefile, so that when a makefile is required in the future you will know
how to create one.
Test files can be created using the program ranint.cpp, which is distributed as part of the
assignment and is compiled by the supplied makefile. To create random data files for testing,
first build ranint.x with the command
and then execute. Note that the program expects 3 command line arguments - (1) file name, (2)
upper bound on size of integers, and (3) number of elements to generate. It will remind you if
you forget. Here are examples:
(Forgot to give arguments.)
The less-than character in the command:
stats.x < data1
is a Unix/Linux operation that redirects the contents of data1 into standard input for stats.x.
Using > redirects program output. For example, the command:
stats.x < data1 > data1.out
sends the contents of data1 to standard input and then sends the program output into the file
data1.out. These are very handy operations for testing programs.
It is sometimes simpler to develop the code in a single file (such as project.cpp) that can be
edited in one window and test-compiled with a single command (such as g++ -Wall -Wextra -
ostats.x project.cpp) and split the file up into the deliverables after the initial round of testing and
debugging.
Note that the array in which input is stored is passed to the functions as a pointer. In the case of
Mean(), this pointer is const, indicating that the elements of the array may not be changed by the
call. However in the case of Median(), the array element values are allowed to change. These
values are in fact changed by the call toSort().
The function Sort() operates on the array input as a pointer. When the function returns, the values
of the array should be in increasing order.
The insertion sort algorithm requires a nested pair of loops (one inside the other).
Sorting the data is essential to calculate the median: when in an array that is sorted, the middle
(two) values are those contained in the middle (two) indices of the array.
The middle index of an array of n elements, when n is odd, is [(n-1)/2]. The middle two indices,
when n is even, are [n/2 - 1] and [n/2].
Be careful when subtracting 1 from an unsigned integer type such as size_t.
Solution
Homework 2: StatsHomework 2: StatsFinding the mean and median of numerical data
Educational Objectives: After successfully completing this assignment, the student should be
able to accomplish the following: Use a loop structure to read user input of unknown size
through std::cin and store it in an array.Use conditional branching to selectively perform
computational tasks.Declare (prototype) and define (implement) functions.Declare and define
functions with arguments of various types, including pointers, references, const pointers, and
const references.Call functions, making appropriate use of the function arguments and their
types.Make decisions as to appropriate function call parameter type, from among: value,
reference, const reference, pointer, and const pointer.Compile and run a C++ program in the
Unix/Linux environment using g++.
Operational Objectives: Create a project that computes the mean and median of a sequence of
integers received via standard input.
Deliverables: Four files: stats.h, stats.cpp, main.cpp, makefile. Note that these files
constitute a self-contained project.Background
Given a finite collection of n numbers: The mean is the sum of the numbers divided by n,
andThe median is the middle value (in case n is odd) or the average of the two middle values
(in case n is even).
Note that to find the median of a collection of data, it is convenient to first sort the data,
that is, put the data in increasing (or non-decreasing) order. Then the median is just the middle
datum in the sorted sequence (or the average of the two middle data, if there are an even
number).
One of the simplest sort algorithms is called Selection Sort, which operates on an array of
elements and has a computation which can be described in one sentence: For each element of
the array, find the smallest element with equal or higher index in the array and swap these two
elements. Here is a "pseudocode" description of the algorithm: for i in [0...n) // for each
element of array A k = i // find the smallest element following it for j in [i+1...n) if A[j] <
A[k] k = j endif endfor // now A[k] is the smallest element following A[i] swap the
values in A[i] and A[k] endfor
(You could test whether A[k] < A[i] before the swap, but it is not clear this would speed
up the process - swapping may be faster than testing.) Procedural Requirements:
Create and work within a separate subdirectory cop3330/hw2. Review the COP 3330 rules
found in Introduction/Work Rules.
Copy these files LIB/hw2/makefile LIB/hw2/hw2submit.sh
from the course distribution library into your project directory.
Create three more files stats.h stats.cpp main.cpp
complying with the Technical Requirements and Specifications stated below.
Turn in four files stats.h, stats.cpp, main.cpp, and makefile using the hw2submit.sh submit
script.
Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu
to submit projects. If you do not receive the second confirmation with the contents of your
project, there has been a malfunction.Technical Requirements and Specifications
The project should compile error- and warning-free on linprog with the command make
stats.x.
The number of integers input by the user is not known in advance, except that it will not
exceed 100. Numbers are input through standard input, either from keyboard or file re-direct.
The program should read numbers until a non-digit or end-of-file is encountered or 100
numbers have been read.
Once the input numbers have been read, the program should calculate the mean and median
and then report these values to standard output.
The source code should be structured as follows: Implement separate functions with the
following prototypes: float Mean (const int* array, size_t size); // calculates mean of data in
array float Median (int* array, size_t size); // calculates median of data in array void Swap
(int& x, int& y); // interchanges values of x and y void Sort (int* array, size_t size); // sorts the
data in array I/O is handled by function main(); no other functions should do any
I/OFunction main() calls Mean() and Median()Function Median() calls Sort()Function Sort()
calls Swap()
The source code should be organized as follows: Prototypes for Mean, Median, Sort, and
Swap should be in file stats.hImplementations for Mean, Median, Sort, and Swap should be in
file stats.cppFunction main should be in file main.cpp
The Sort() function should implement the Selection Sort algorithm.
When in doubt, your program should behave like the distributed executable examples in
stats_i.x and stats_s.x in area51. Identical behavior is not required, but the general I/O
behavior should be the same. In particular, the data input loop should not be interupted by
prompts for a next datum - this will make file redirect cumbersome. Just ask for the data one
time, then read until a non-digit or end of file is encountered. Hints Sample executables
are distributed in [LIB]/area51. These are named stats_i.x and stats_s.x. The suffixes indicate
which of the two architectures the executable is compiled on: *_i.x runs on Intel/Linux and
*_s.x runs on Sun/Unix. To run a sample executable, follow these steps: (1) Decide which
architecture you want to use. The program machines are 32-bit Sun architecture running
Sun's version of Unix, and the linprog machines are Intel 64-bit architecture running Linux.
(2) Copy the appropriate executable into your space where you want to run it. For example, if
you are logged in to program enter the command "cp [LIB]/area51/stats_s.x .". (3) Change
permissions to executable: "chmod 700 stats_s.x". (4) Execute by entering the name of the
executable. If you want to run it on a data file "data1", use input redirect as in: "stats_s.x <
data1". If you want the output to go to another file, use output redirect: "stats_s.x < data1 >
data1.out". Two test files are distributed in [LIB]/hw2. To run the sample executable on
a file, say data1, first make sure you have an executable copy of the program and the data file,
then enter the command:
stats.x < data1
This is a Unix/Linux operation that redirects the contents of data1 into standard input for
stats.x. Using > redirects program output. For example, the command:
stats.x < data1 > data1.out
sends the contents of data1 to standard input and then sends the program output into the file
data1.out. These are very handy operations for testing programs. It is sometimes simpler
to develop the code in a single file (such as project.cpp) that can be edited in one window and
test-compiled with a single command (such as g++ -Wall -Wextra -ostats.x project.cpp) and
split the file up into the deliverables after the initial round of testing and debugging. Note
that the array in which input is stored is passed to the functions as a pointer. In the case of
Mean(), this pointer is const, indicating that the elements of the array may not be changed by
the call. However in the case of Median(), the array element values are allowed to change.
These values are in fact changed by the call to Sort(). The function Sort() operates on the
array input as a pointer. When the function returns, the values of the array should be in
increasing order.The selection sort algorithm requires a nested pair of for loops (one inside the
other).The function Swap() encapsulates the chore of swapping two values. Your sort
implementation should call Swap whever two values need to be swapped. Note that the two
parameters for Swap are passed by reference, so that the function acts on the values in the
calling routine. Sorting the data is essential to calculate the median: when in an array that
is sorted, the middle (two) values are those contained in the middle (two) indices of the array.
The middle index of an array of n elements, when n is odd, is [(n-1)/2]. The middle two
indices, when n is even, are [n/2 - 1] and [n/2]. Be careful when subtracting 1 from an
unsigned integer type such as size_t.Look at the code examples in Chapter 3 of the lecture notes
to find simple ways to structure your main I/O loop.

More Related Content

Similar to Educational Objectives After successfully completing this assignmen.pdf

Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
fileop report
fileop reportfileop report
fileop reportJason Lu
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to rmanikanta361
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptxKishoreRedla
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interviewprashant patel
 
Cost effort.ppt
Cost effort.pptCost effort.ppt
Cost effort.pptJayaprasanna4
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptxkrushnaraj1
 
compiler design
compiler designcompiler design
compiler designIshwor2
 

Similar to Educational Objectives After successfully completing this assignmen.pdf (20)

Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
fileop report
fileop reportfileop report
fileop report
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
CPP homework help
CPP homework helpCPP homework help
CPP homework help
 
Lab1
Lab1Lab1
Lab1
 
ch 2. Python module
ch 2. Python module ch 2. Python module
ch 2. Python module
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Cost effort.ppt
Cost effort.pptCost effort.ppt
Cost effort.ppt
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Python
PythonPython
Python
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 
Vedic Calculator
Vedic CalculatorVedic Calculator
Vedic Calculator
 
C programming
C programmingC programming
C programming
 
compiler design
compiler designcompiler design
compiler design
 

More from rajeshjangid1865

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfrajeshjangid1865
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfrajeshjangid1865
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfrajeshjangid1865
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfrajeshjangid1865
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfrajeshjangid1865
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfrajeshjangid1865
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfrajeshjangid1865
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfrajeshjangid1865
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdfrajeshjangid1865
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfrajeshjangid1865
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfrajeshjangid1865
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfrajeshjangid1865
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfrajeshjangid1865
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfrajeshjangid1865
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfrajeshjangid1865
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfrajeshjangid1865
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfrajeshjangid1865
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfrajeshjangid1865
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfrajeshjangid1865
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfrajeshjangid1865
 

More from rajeshjangid1865 (20)

write Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdfwrite Ocaml programe to add all numbers in a list the solution .pdf
write Ocaml programe to add all numbers in a list the solution .pdf
 
why is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdfwhy is lifelong learning important for Engineers Give an example to.pdf
why is lifelong learning important for Engineers Give an example to.pdf
 
Which of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdfWhich of the following is true of aldol reactions1.The thermodyna.pdf
Which of the following is true of aldol reactions1.The thermodyna.pdf
 
Using at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdfUsing at least two examples (whenever applicable), concisely discuss .pdf
Using at least two examples (whenever applicable), concisely discuss .pdf
 
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdfTransforming Cultures from Consumerism to Sustainability - Essay.pdf
Transforming Cultures from Consumerism to Sustainability - Essay.pdf
 
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdfTrane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
Trane has 145 marbles. He gives 20 to Katie, 52 to Gwen, and 31 to Yu.pdf
 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdf
 
The table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdfThe table below gives the probabilities of combinations of religion a.pdf
The table below gives the probabilities of combinations of religion a.pdf
 
The effects Poverty in SocietySolution Poor children are at gre.pdf
The effects Poverty in SocietySolution  Poor children are at gre.pdfThe effects Poverty in SocietySolution  Poor children are at gre.pdf
The effects Poverty in SocietySolution Poor children are at gre.pdf
 
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdfSuppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
Suppose 1.01g of FeCl3 is placed in a 10.0ml volumetric glass, water.pdf
 
Specialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdfSpecialized regions on the cell surface through which cells are joine.pdf
Specialized regions on the cell surface through which cells are joine.pdf
 
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdfSection 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
Section 404 of the Sarbanes Oxley Act requires auditors of a public .pdf
 
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdfReiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
Reiji and Tuneko Okazaki conducted a now classic experiment in 1968 .pdf
 
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdfProblem 2-1A Suppose the following items are taken from the 2017 bala.pdf
Problem 2-1A Suppose the following items are taken from the 2017 bala.pdf
 
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdfPrepare a 2017 income statement for Shanta Corporation based on the f.pdf
Prepare a 2017 income statement for Shanta Corporation based on the f.pdf
 
Organizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdfOrganizations need to have a pool of managerial talent to take on jo.pdf
Organizations need to have a pool of managerial talent to take on jo.pdf
 
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdfObjective Manipulate the Linked List Pointer.Make acopy of LList..pdf
Objective Manipulate the Linked List Pointer.Make acopy of LList..pdf
 
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdfMilitarism Alliances Imperialism Nationalism Class, the powder keg.pdf
Militarism Alliances Imperialism Nationalism Class, the powder keg.pdf
 
In the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdfIn the subject of cryptography, what policy or organizational challe.pdf
In the subject of cryptography, what policy or organizational challe.pdf
 
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdfis Google making us stupid Nicholas Carr Summarize Article. https.pdf
is Google making us stupid Nicholas Carr Summarize Article. https.pdf
 

Recently uploaded

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Educational Objectives After successfully completing this assignmen.pdf

  • 1. Educational Objectives: After successfully completing this assignment, the student should be able to accomplish the following: Use a loop structure to read user input of unknown size through std::cin and store it in an array. Use conditional branching to selectively perform computational tasks. Declare (prototype) and define (implement) functions. Declare and define functions with arguments of various types, including pointers, references, const pointers, and const references. Call functions, making appropriate use of the function arguments and their types. Make decisions as to appropriate function call parameter type, from among: value, reference, const reference, pointer, and const pointer. Create, edit, build and run multi-file projects using the Linux/Emacs/Make environment announced in the course organizer. Operational Objectives: Create a project that computes the mean and median of a sequence of integers received via standard input. Deliverables: Files: stats.h, stats.cpp, main.cpp, makefile, log.txt. Note that these files constitute a self-contained project. Assessment Rubric: The following will be used as a guide when assessing the assignment: Please self-evaluate your work as part of the development process. Background Given a finite collection of n numbers: The mean is the sum of the numbers divided by n, and The median is the middle value (in case n is odd) or the average of the two middle values (in case n is even). Note that to find the median of a collection of data, it is convenient to first sort the data, that is, put the data in increasing (or non-decreasing) order. Then the median is just the middle datum in the sorted sequence (or the average of the two middle data, if there are an even number). One of the more intuitive sort algorithms is called Insertion Sort, which operates on an array a[0..n-1] of elements. The idea is to "insert" the value of a[i] into the sub-array a[0..i-1] at the largest possible index that results in the expanded sub-array a[0..i] sorted. We insert at the highest possible index in order not to place the value ahead of any previously inserted elements with the same value. The subarray a[0..i-1] is assumed to be sorted at the beginning of each insertion step. The base case consists of a one-element array a[0..0], which is always sorted. Here is a "pseudocode" description of the algorithm: The inner loop copies all elements in a[0..i-1] up one index until the correct place for t is found. Then put t in that place.
  • 2. Procedural Requirements: Begin a log file named log.txt. This should be an ascii text file in cop3330/proj1 with the following header: This file should document all work done by date and time, including all testing and test results. Create and work within a separate subdirectory cop3330/proj1. Review the COP 3330 rules found in Introduction/Work Rules. Copy all of the files from LIB/proj1. These should include: In addition you should have the script submit.sh in either your .bin or your proj1 as an executable command. Create three more files complying with the Technical Requirements and Specifications stated below. Turn in four files stats.h, stats.cpp, main.cpp, and makefile using the submit script. Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit projects. If you do not receive the second confirmation with the contents of your project, there has been a malfunction. After submission, take Quiz 1 in Blackboard. This quiz covers these areas: Casting; integer and floating point arithmetic. Function calls Loops This assignment Course Syllabus Note that the quiz may be taken several times. The highest of the grades will be recorded and count as 20 points (40 percent of the assignment). Technical Requirements and Specifications The project should compile error- and warning-free on linprog with the command make stats.x. The number of integers input by the user is not known in advance, except that it will not exceed 100. Numbers are input through standard input, either from keyboard or file re-direct. The program should read numbers until a non-digit or end-of-file is encountered or 100 numbers have been read. Once the input numbers have been read, the program should calculate the mean and median and then report these values to standard output. The source code should be structured as follows: Implement separate functions with the following prototypes: I/O is handled by function main(); no other functions should do any I/O Function main() calls Mean() and Median() Function Median() calls Sort()
  • 3. The source code should be organized as follows: Prototypes for Mean, Median, and Sort should be in file stats.h Implementations for Mean, Median, and Sort should be in file stats.cpp Function main should be in file main.cpp The Sort() function should implement the Insertion Sort algorithm. When in doubt, your program should behave like the distributed executable example stats_i.x in area51. Identical behavior is not required, but the general I/O behavior should be the same. In particular, the data input loop should not be interupted by prompts for a next datum - this will make file redirect cumbersome. Just ask for the data one time, then read until a non-digit or end of file is encountered. Hints An example executables is distributed as [LIB]/area51/stats_i.x. The suffix indicates it is compiled to run on the Intel/Linux architecture (linprog machines). To run a sample executable, follow these steps: (1) Copy the appropriate executable into your space where you want to run it: log in to linprog and enter the command "cp [LIB]/area51/stats_i.x .". (2) Change permissions to executable: "chmod 700 stats_i.x". (3) Execute by entering the name of the executable. If you want to run it on a data file "data1", use input redirect as in: "stats_i.x < data1". If you want the output to go to another file, use output redirect: "stats_i.x < data1 > data1.out". A working makefile is distributed and may be used in the submission - provided that you have read and understood the makefile, so that when a makefile is required in the future you will know how to create one. Test files can be created using the program ranint.cpp, which is distributed as part of the assignment and is compiled by the supplied makefile. To create random data files for testing, first build ranint.x with the command and then execute. Note that the program expects 3 command line arguments - (1) file name, (2) upper bound on size of integers, and (3) number of elements to generate. It will remind you if you forget. Here are examples: (Forgot to give arguments.) The less-than character in the command: stats.x < data1 is a Unix/Linux operation that redirects the contents of data1 into standard input for stats.x. Using > redirects program output. For example, the command: stats.x < data1 > data1.out sends the contents of data1 to standard input and then sends the program output into the file data1.out. These are very handy operations for testing programs.
  • 4. It is sometimes simpler to develop the code in a single file (such as project.cpp) that can be edited in one window and test-compiled with a single command (such as g++ -Wall -Wextra - ostats.x project.cpp) and split the file up into the deliverables after the initial round of testing and debugging. Note that the array in which input is stored is passed to the functions as a pointer. In the case of Mean(), this pointer is const, indicating that the elements of the array may not be changed by the call. However in the case of Median(), the array element values are allowed to change. These values are in fact changed by the call toSort(). The function Sort() operates on the array input as a pointer. When the function returns, the values of the array should be in increasing order. The insertion sort algorithm requires a nested pair of loops (one inside the other). Sorting the data is essential to calculate the median: when in an array that is sorted, the middle (two) values are those contained in the middle (two) indices of the array. The middle index of an array of n elements, when n is odd, is [(n-1)/2]. The middle two indices, when n is even, are [n/2 - 1] and [n/2]. Be careful when subtracting 1 from an unsigned integer type such as size_t. Solution Homework 2: StatsHomework 2: StatsFinding the mean and median of numerical data Educational Objectives: After successfully completing this assignment, the student should be able to accomplish the following: Use a loop structure to read user input of unknown size through std::cin and store it in an array.Use conditional branching to selectively perform computational tasks.Declare (prototype) and define (implement) functions.Declare and define functions with arguments of various types, including pointers, references, const pointers, and const references.Call functions, making appropriate use of the function arguments and their types.Make decisions as to appropriate function call parameter type, from among: value, reference, const reference, pointer, and const pointer.Compile and run a C++ program in the Unix/Linux environment using g++. Operational Objectives: Create a project that computes the mean and median of a sequence of integers received via standard input. Deliverables: Four files: stats.h, stats.cpp, main.cpp, makefile. Note that these files constitute a self-contained project.Background Given a finite collection of n numbers: The mean is the sum of the numbers divided by n, andThe median is the middle value (in case n is odd) or the average of the two middle values (in case n is even). Note that to find the median of a collection of data, it is convenient to first sort the data,
  • 5. that is, put the data in increasing (or non-decreasing) order. Then the median is just the middle datum in the sorted sequence (or the average of the two middle data, if there are an even number). One of the simplest sort algorithms is called Selection Sort, which operates on an array of elements and has a computation which can be described in one sentence: For each element of the array, find the smallest element with equal or higher index in the array and swap these two elements. Here is a "pseudocode" description of the algorithm: for i in [0...n) // for each element of array A k = i // find the smallest element following it for j in [i+1...n) if A[j] < A[k] k = j endif endfor // now A[k] is the smallest element following A[i] swap the values in A[i] and A[k] endfor (You could test whether A[k] < A[i] before the swap, but it is not clear this would speed up the process - swapping may be faster than testing.) Procedural Requirements: Create and work within a separate subdirectory cop3330/hw2. Review the COP 3330 rules found in Introduction/Work Rules. Copy these files LIB/hw2/makefile LIB/hw2/hw2submit.sh from the course distribution library into your project directory. Create three more files stats.h stats.cpp main.cpp complying with the Technical Requirements and Specifications stated below. Turn in four files stats.h, stats.cpp, main.cpp, and makefile using the hw2submit.sh submit script. Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit projects. If you do not receive the second confirmation with the contents of your project, there has been a malfunction.Technical Requirements and Specifications The project should compile error- and warning-free on linprog with the command make stats.x. The number of integers input by the user is not known in advance, except that it will not exceed 100. Numbers are input through standard input, either from keyboard or file re-direct. The program should read numbers until a non-digit or end-of-file is encountered or 100 numbers have been read. Once the input numbers have been read, the program should calculate the mean and median and then report these values to standard output. The source code should be structured as follows: Implement separate functions with the following prototypes: float Mean (const int* array, size_t size); // calculates mean of data in array float Median (int* array, size_t size); // calculates median of data in array void Swap (int& x, int& y); // interchanges values of x and y void Sort (int* array, size_t size); // sorts the data in array I/O is handled by function main(); no other functions should do any
  • 6. I/OFunction main() calls Mean() and Median()Function Median() calls Sort()Function Sort() calls Swap() The source code should be organized as follows: Prototypes for Mean, Median, Sort, and Swap should be in file stats.hImplementations for Mean, Median, Sort, and Swap should be in file stats.cppFunction main should be in file main.cpp The Sort() function should implement the Selection Sort algorithm. When in doubt, your program should behave like the distributed executable examples in stats_i.x and stats_s.x in area51. Identical behavior is not required, but the general I/O behavior should be the same. In particular, the data input loop should not be interupted by prompts for a next datum - this will make file redirect cumbersome. Just ask for the data one time, then read until a non-digit or end of file is encountered. Hints Sample executables are distributed in [LIB]/area51. These are named stats_i.x and stats_s.x. The suffixes indicate which of the two architectures the executable is compiled on: *_i.x runs on Intel/Linux and *_s.x runs on Sun/Unix. To run a sample executable, follow these steps: (1) Decide which architecture you want to use. The program machines are 32-bit Sun architecture running Sun's version of Unix, and the linprog machines are Intel 64-bit architecture running Linux. (2) Copy the appropriate executable into your space where you want to run it. For example, if you are logged in to program enter the command "cp [LIB]/area51/stats_s.x .". (3) Change permissions to executable: "chmod 700 stats_s.x". (4) Execute by entering the name of the executable. If you want to run it on a data file "data1", use input redirect as in: "stats_s.x < data1". If you want the output to go to another file, use output redirect: "stats_s.x < data1 > data1.out". Two test files are distributed in [LIB]/hw2. To run the sample executable on a file, say data1, first make sure you have an executable copy of the program and the data file, then enter the command: stats.x < data1 This is a Unix/Linux operation that redirects the contents of data1 into standard input for stats.x. Using > redirects program output. For example, the command: stats.x < data1 > data1.out sends the contents of data1 to standard input and then sends the program output into the file data1.out. These are very handy operations for testing programs. It is sometimes simpler to develop the code in a single file (such as project.cpp) that can be edited in one window and test-compiled with a single command (such as g++ -Wall -Wextra -ostats.x project.cpp) and split the file up into the deliverables after the initial round of testing and debugging. Note that the array in which input is stored is passed to the functions as a pointer. In the case of Mean(), this pointer is const, indicating that the elements of the array may not be changed by the call. However in the case of Median(), the array element values are allowed to change.
  • 7. These values are in fact changed by the call to Sort(). The function Sort() operates on the array input as a pointer. When the function returns, the values of the array should be in increasing order.The selection sort algorithm requires a nested pair of for loops (one inside the other).The function Swap() encapsulates the chore of swapping two values. Your sort implementation should call Swap whever two values need to be swapped. Note that the two parameters for Swap are passed by reference, so that the function acts on the values in the calling routine. Sorting the data is essential to calculate the median: when in an array that is sorted, the middle (two) values are those contained in the middle (two) indices of the array. The middle index of an array of n elements, when n is odd, is [(n-1)/2]. The middle two indices, when n is even, are [n/2 - 1] and [n/2]. Be careful when subtracting 1 from an unsigned integer type such as size_t.Look at the code examples in Chapter 3 of the lecture notes to find simple ways to structure your main I/O loop.