Download Sample Program

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Bootstrapping (statistics) wikipedia , lookup

Taylor's law wikipedia , lookup

Karhunen–Loève theorem wikipedia , lookup

Fisher–Yates shuffle wikipedia , lookup

Law of large numbers wikipedia , lookup

Transcript
CmpE 150.01 - PASCAL
Project 3
Due May, 9, until 5:00pm
Project Description
In this project you will write a program that will utilize procedures and functions. Here you will
implement a simple statistics tool. The program should be able to calculate mean, standard deviation,
variance, skew, standard error.
In the beginning of the program the user will be asked for a password. If he can’t enter the right
password, he should have 2 more chances. After the third trial the program should exit giving an error
message. In case the user enters the correct password another menu should be displayed.This menu
will have the following choices.

Enter the seed for randomly generated data : The program generates the data using a seed and
random number generator. This menu allows the user to determine the seed for input. It will
also get the total number of numbers to be created. A sample program for finding random
numbers with given seed is given at the end of the document.

Calculate the mean: The formula for calculating mean is below.
_
x
1
N
N
x
j 1
j
x1 , x 2 , x N  numbers in the input file
N  Number of elements in the input file.
_
x  The mean of the numbers.

Calculate the variance: This menu will allow the user to calculate the variance of the input.
The variance is calculated with the following formula:
2
N
_
1


var x1 , x 2 , x N  
x

x



j
N  1 j 1 

x1 , x 2 , x N  numbers in the input file
N  Number of elements in the input file.
_
x  The mean of the numbers.

Calculate standard deviation : In this menu you will calculate the standart deviation of the
data in the input file. This is the square root of the variation.

Calculate skew:
_


x

x
1
j


Skewx1 , x2 , x N   

N j 1 standard deviation 


N
3

Calculate standard error : The standart error is calculated with the following formula.
Stderr x1 , x2 , x N  

Standard Deviation
N
Exit : Exits from the program.
You must at least define the following routines.

Mean : Calculates the mean of numbers given the seed for random number generator.

Stderr : Calculates the standard error of the numbers given the seed for random number generator.

Standard deviation : Calculates the standard deviation of the numbers given the seed for random
number generator.

Variance : Calculates the variance of the numbers given the seed for random number generator.

Skewness : Calculates the skew of the numbers.

Chkpasswd : Checks whether the pasword is right. In our project the password is hardcoded. That is it
is predetermined and needs no update, also cannot be changed by user. This routine will check whether
the password given as a parameter is right or not. If it is right then returns true else false.
Note that you may not calculate results every time user asks for them, you can keep their values after first call of
the procedure or function (optional).
Your program is assumed to perform some error checkings. Some of these are listed below:
1.
2.
3.
4.
Invalid inputs in seed
Invalid inputs in random number boundaries
Invalid inputs in menu
Invalid inputs in number of numbers
The menu can be very simple.
Sample Program
program first (input, output);
var
i, num:integer;
{ Finds a random number between start and last numbers and returns it as in parameter num}
procedure nextrand(start,last : integer; var number :integer);
var
rnd : integer ;
begin
rnd := random(last-start+1);
number := rnd+start;
end;
begin
{Initialize the random number generator with seed 100}
Randseed:=100;
for i:=1 to 5 do
begin
{take next random number,which will certainly be between 12 and 100}
nextrand(12,100,num);
write(' ',num);
end;
writeln; writeln('Finish!');
{Reinitialize the random number generator with seed 100}
Randseed :=100;
for i:=1 to 5 do
begin
{take next random number, just like previous loop}
nextrand(12,100,num);
write(' ',num);
end;
writeln; writeln('Same numbers!')
end.
Sample Output
A sample run of the program is given below:
Enter your password: tolga
Wrong password.
Enter your password: tommy
Welcome to the phonebook.
Menu:
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 1
Enter the seed: 100
Enter the number of numbers to be created:100
Ok!
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 2
Standard deviation is: 3,73 (the value is just an example!)
OK?
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 4
Standard error is: 0,122 (the value is just an example!)
Ok?
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 3
The mean is: ****
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 5
The variance is: 11,97
Ok?
(the value is just an example!)
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 6
The skew is: ***
Enter random seed.
Calculate standard deviation
Calculate mean.
Calculate standard error.
Calculate variance.
Calculate skew.
Exit
Enter your choice: 7
Goodbye! Copyright (2000) by somebody.
Material to Submit
1.
2.
3.
4.
You will submit the executable file (*.exe) and program code (*.pas) in a diskette.
You will also submit the print-out of the program code (*.pas) .
The source code should be fully commented, and indented. The identifier names should be
meaningful and self-explanatory. (These will be evaluated as well as the execution of your
program.)
You will submit a sample run which contains enough executions (at least 4 different
operations) to show that your program works.
You can use only the features covered in the class until the end of the procedures and
functions. You are not allowed to use any non-standard construct. Cheaters will be
severely punished. Late projects will not be accepted.
For further questions, see Tolga Ciftci at ETA203.
You can obtain a copy of this description from Seçkin Photocopy. The project description is
also available on-line http://www.cmpe.boun.edu.tr/courses/cmpe150/pascal .
Note: You can use shift-printscreen combination from MS-DOS screen, to print output of
your program. You must prepare and execute executable of your program, in order to be able
to print output.