Write a pseudo code for the following #include <iostream> #include <cmath> #incl
ID: 3778741 • Letter: W
Question
Write a pseudo code for the following
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
float deviation(float sum, float mean, float P);
float mean(float vector[], int size);
float sum(float vector[], int size);
int main()
{
ifstream inFile;
float A;
int size = 0;
const int Numlist = 1000;
float totSum;
float avg = 0.0;
int max = 100;
int min = 11;
double m = 71.47;
double s = 20.98;
double List[Numlist];
inFile.open("input.txt");
if (inFile.fail())
{
cout << "Error: cannot open input.txt" << endl;
exit(EXIT FAILURE);
}
for (int count = 0; count < Numlist; ++count){
inFile >> List[count];
if (!inFile)break;
}
float standard_deviation[100];
inFile >> P;
while ((!inFile.eof()) && (size<Numlist))
{
standard_deviation[size] = P;
size++;
inFile >> P;
}
totSum = sum(standard_deviation, size);
average = mean(standard_deviation, size);
cout << "Standard Deviation = " << deviation(totalSum, avg, size) << endl;
cout << "Mean = " << mean(average) << endl;
cout << "Maximum Score = " << max << endl;
cout << "Minimum Score = " << min << endl;
cout << "Range = " << (max - min) << endl;
cout << "Grade" << " " << "Number of Scores" << " " << endl;
system("pause");
return 0;
}
//-----------------------------
//func sum
//-----------------------------
float sum(float vector[], int size)
{
float theSum;
theSum = 0.0;
for (int P = 0;P < size; P++)
{
theSum += vector[P];
}
return theSum;
}
//-----------------------------
//Mean m Func
//-----------------------------
float mean(float vector[], int size)
{
float sum = 0.0, mean = 0.0;
for (int a = 0; a < size; a++)
{
mean += vector[size];
}
if (size == 0)
mean = 0.0;
else
mean = mean / size;
return mean;
}
//-----------------------------
//Dev func
//-----------------------------
float deviation(float sum, float mean, float P)
{
double S;
double U;
U = (pow(sum - mean, 2));
S = (sqrt(U / P));
return S;
}
Explanation / Answer
Initialize size to 0;
Initialize Numlist to 1000;
Initialize avg to 0.0;
Initialize max to 100;
Initialize min to 11;
Initialize m to 71.47;
Initialize s to 20.98;
Open input.txt file
If the file opening is failed
Print cannot open input.txt
Exitfailure
For each count equals to zero and count less than numlist
Infile equals to list of count
If not in file
Break.
Size of standarad deviation array to 100
Infile equal to p
While infile not equal to end of the file and size less than number list
Standard deviation of array size equals to p
Size is incremented by 1
And infile equal to p
Call function sum with the arguments Standard deviation,size
Assign sum to totsum
Call function mean with the arguments Standard deviation,size
And assign mean to average
Print Standard deviation
Print mean
Print maximum score
Print minimum score
Print range
Print grade
System pause
Return 0
// Call function sum
Initialize sum equals to 0
For each p equals to zero and p less than size
Add the sum to vector array of p
Return the sum
// Call function mean
Initialize sum equals to 0
Initialize mean equals to 0
For each a equals to zero and a less than size
Add the mean to vector array of size
If the size equals to 0
Then
Mean equals to 0
Else
Mean equals to mean divided by size
Return mean.
// call function deviation
U equals to (sum-mean)2
S equals to square root of u divided by p
Return s
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.