Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
void normals(float low[], float high[], string stars[], ifstream& input1);
void reading(float signal[], string stars[], string starsin[], ifstream& input2);
int search(string stars[], string starsin[], int position);
void anomaly(string stars[], string starsin[], float high[], float low[], float signal[], int anomalies[]);
const int MAX = 5;
const int MAX2 = 11;
int main()
{
float low[MAX], high[MAX];
string stars[MAX], starsin[MAX2];
float signal[MAX2];
ifstream input1, input2;
int anomalies[MAX] = {0};
normals(low, high, stars, input1);
reading(signal, stars, starsin, input2);
anomaly(stars, starsin, high, low, signal, anomalies);
cout << "Star Name:" << setw(20);
cout << "Low Bound:" << setw(20);
cout << " High Bound:" << endl;
for(int i = 0; i < MAX; i++)
{
cout << stars[i] << setw(13 + stars[0].length() - stars[i].length());
cout << low[i] << setw(13 + stars[0].length() - stars[1].length());
cout << high[i] << endl;
}
for(int i = 0; i < MAX; i++)
{
cout << anomalies[i] << endl;
}
system("PAUSE");
return 0;
}
void anomaly(string stars[], string starsin[], float high[], float low[], float signal[], int anomalies[])
{
int temp = 0;
for(int i = 0; i < MAX2; i++)
{
temp = search(stars, starsin, i);
if(signal[i] < low[temp] || signal[i] > high[temp])
{
anomalies[temp]++;
}
i++;
}
}
int search(string stars[], string starsin[], int position)
{
int ct = 0;
bool flag = true;
while(flag && ct < MAX)
{
if(stars[ct] == starsin[position])
{
flag = false;
}
else
{
cout << stars[ct] << endl;
cout << starsin[position] << endl;
ct++;
}
}
if(flag)
{
cout << "Error star " << starsin[position];
cout << " does not have any normals." << endl;
}
return ct;
}
void reading(float signal[], string stars[], string starsin[], ifstream& input2)
{
bool flag;
input2.open("file2");
for(int i = 0; i < MAX2; i++)
{
getline(input2, starsin[i]);
input2 >> signal[i];
getline(input2, starsin[i+1]);
}
}
void normals(float low[], float high[], string stars[], ifstream& input1)
{
input1.open("file1");
for(int i = 0; i < MAX; i++)
{
getline(input1, stars[i]);
input1 >> low[i] >> high[i];
getline(input1, stars[i+1]);
}
input1.close();
}
Ok well It reads in