-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
48 lines (40 loc) · 1.15 KB
/
Main.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
#include "Perimeter.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
//Open file and check if it opened successfully
ifstream inputFile("input.txt");
if (!inputFile) {
cout << "Error - Nonexisting Input File" << endl;
system("pause");
return -1;
}
//Open output file
ofstream outputFile("output.txt");
//Get dimensions of grid
int rowInput, column, cell;
inputFile >> rowInput;
inputFile >> column;
//Initialize 2 dimensional vector to be size of grid
vector<int> columnVector(column);
vector<vector<int> > islandPerimeter(rowInput, columnVector);
//Process remainder of input file into vector
for (int i = 0; i < islandPerimeter.size(); i++) {
for (int j = 0; j < islandPerimeter[i].size(); j++) {
inputFile >> cell;
islandPerimeter[i][j] = cell;
}
}
//calculate the perimeter with used defined function
int perimeter = calc_perimeter(islandPerimeter);
//Output perimeter to output file
outputFile << "Perimeter: " << perimeter;
//Close the files
outputFile.close();
inputFile.close();
//system("pause");
return 0;
}