ooo Sprint F 227 AM 68 HW 11 HW11 Graded out of 100 This hom
Solution
#include <iostream>
#include <fstream>
using namespace std;
//declare req variables
int upper[100];
int lower[100];
//function to read data frm file
int readFromFile(int x)
{
int count=0,uCount=0,lCount=0;
ifstream myfile(\"data.txt\");
float no;
while (myfile >> no)
{
cout<<no<<\"\\t\";
if(no>x)
{
upper[uCount]=no;
uCount++;
count++;
}
else
{
lower[lCount]=no;
lCount++;
count++;
}
}
return count;
}
//function to display upper array elements
void displayUpper()
{
cout<<\"\ Upper array (values greater than input value) \";
cout<<\"\ --------------------\ \";
int count=0;
float avg=0;
while(upper[count]!=0)
{
avg+=upper[count];
count++;
}
if(count!=0)
avg/=count;
cout<<\"Number of values: \"<<count;
cout<<\"\\tAverage: \"<<avg<<endl;
for(int i=0;i<count;i++)
cout<<upper[i]<<\" \";
}
//fucntion to display lower array elements
void displayLower()
{
cout<<\"\ Lower array (values greater than input value) \";
cout<<\"\ --------------------\ \";
int count=0;
float avg=0;
while(lower[count]!=0)
{
avg+=lower[count];
count++;
}
if(count!=0)
avg/=count;
cout<<\"\ Number of values: \"<<count;
cout<<\"\\tAverage: \"<<avg<<endl;
for(int i=0;i<count;i++)
cout<<lower[i]<<\" \";
}
//main fucntion which triggers
int main()
{
int x,count=0;
cout << \"Enter value of x: \";
cin>>x;
if(x!=-1)
{
count=readFromFile(x);
}
cout<<\"\ Number of values in the file: \"<<count;
cout<<\"\ Input value entered : \"<<x;
displayUpper();
displayLower();
return 0;
}
Sample Output:
Enter value of x: 3
3 6 3 8 5 8 5
Number of values in the file: 7
Input value entered : 3
Upper array (values greater than input value)
--------------------
Number of values: 5 Average: 6.4
6 8 5 8 5
Lower array (values greater than input value)
--------------------
Number of values: 2 Average: 3
3 3


