-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputControl.cpp
71 lines (58 loc) · 1.23 KB
/
InputControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <fstream>
#include <string>
#include "InputControl.h"
using namespace std;
InputControl::InputControl()
{
}
InputControl::InputControl(string n)
{
getInput(n);
}
InputControl::~InputControl()
{
}
double* InputControl::getInput(string inputFile)
{
string line;
double temp;
int i=0;
ifstream file;
file.open(inputFile);
if(file.fail()) //checks to make sure file is valid
{
cout<<"Invalid File! Please try again."<<endl;
inputFile = again();
}
getline(file, line);
temp = atof(line.c_str());
size = temp;
arr = new double[size];
while(getline(file, line))
{
temp = atof(line.c_str());
arr[i] = temp;
i++;
}
file.close();
return arr;
}
int InputControl::getSize()
{
return size;
}
string InputControl::again()
{
string inputFile;
cout<<"Enter input file name: "<<endl;
cin>>inputFile;
ifstream file(inputFile);
if(file.fail()) //checks to make sure file is valid
{
cout<<"Invalid File! Please try again."<<endl;
inputFile = again();
}
file.close();
return inputFile;
}