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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
//***************************************************************************
//
// File: Parks_Driver.cpp
//
// Student:
//
// Assignment: Program #7
//
// Course Name: Programming II
//
// Course Number:
//
// Due:
//
//
// This is the driver (main) function program
//
//
// Other files required:
// 1. Parks.h – header file
// 2. Parks.cpp – prototypes of Parks.h
//
//**************************************************************************
#include <iostream>
#include <string>
#include <fstream>
#include "Parks.h"
using namespace std;
//********************************************************
void loadParks(Parks us_parks[], const int SIZE);
void outputParks(Parks us_parks[], const int SIZE);
int findOldest(Parks us_parks[], const int SIZE);
int findNewest(Parks us_parks[], const int SIZE);
int findLargest(Parks us_parks[], const int SIZE);
int findSmallest(Parks us_parks[], const int SIZE);
//********************************************************
int main()
{
const int SIZE = 59;
Parks us_parks[SIZE];
loadParks(us_parks, SIZE);
findOldest(us_parks, SIZE);
findNewest(us_parks, SIZE);
findLargest(us_parks, SIZE);
findSmallest(us_parks, SIZE);
outputParks(us_parks, SIZE);
cout << "worked" << endl;
return 0;
}
//********************************************************
void loadParks(Parks us_parks[], const int SIZE)
{
string temp_str[59];
int temp_int[59];
double temp_dbl[59];
fstream inFile;
inFile.open("park_data.txt", ios::in);
for (int i = 0; i < SIZE; i++)
{
getline(inFile, temp_str[i]);
us_parks[i].setNAME(temp_str[i]);
getline(inFile, temp_str[i]);
us_parks[i].setLocation(temp_str[i]);
getline(inFile, temp_str[i]);
us_parks[i].setMonth(temp_str[i]);
inFile >> temp_int[i];
us_parks[i].setDay(temp_int[i]);
inFile >> temp_int[i];
us_parks[i].setYear(temp_int[i]);
inFile >> temp_dbl[i];
us_parks[i].setArea(temp_dbl[i]);
inFile.ignore();
}
inFile.close();
}
//********************************************************
void outputParks(Parks us_parks[], const int SIZE)
{
fstream outFile;
outFile.open("a7.txt", ios::out);
for (int i = 0; i < SIZE; i++)
{
us_parks[i].Print_Parks(outFile);
}
outFile.close();
}
int findOldest(Parks us_parks[], const int SIZE)
{
int loc = 0;
for (int i = 0; i < SIZE; i++)
{
if (us_parks[i].getYear() < us_parks[loc].getYear())
loc = i;
}
return loc;
}
int findNewest(Parks us_parks[], const int SIZE)
{
int loc = 0;
for (int i = 0; i < SIZE; i++)
{
if (us_parks[i].getYear() > us_parks[loc].getYear())
loc = i;
}
return loc;
}
int findLargest(Parks us_parks[], const int SIZE)
{
int loc = 0;
for (int i = 0; i < SIZE; i++)
{
if (us_parks[i].getArea() > us_parks[loc].getArea())
loc = i;
}
return loc;
}
int findSmallest(Parks us_parks[], const int SIZE)
{
int loc = 0;
for (int i = 0; i < SIZE; i++)
{
if (us_parks[i].getArea() < us_parks[loc].getArea())
loc = i;
}
return loc;
}
|
prototype file
//***************************************************************************
//
// File: Parks.cpp
//
// Student:
//
// Assignment: Program #7
//
// Course Name: Programming II
//
// Course Number:
//
// Due:
//
//
// This is the prototype file
//
//
// Other files required:
// 1. Parks.h – Header file
// 2. Parks_Driver.cpp – Driver File
//
//**************************************************************************
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "Parks.h"
using namespace std;
//********************************************************
Parks::Parks()
{
name = "";
location = "";
month = "";
day = 0;
year = 0;
area = 0;
}
//********************************************************
Parks::~Parks()
{
name = "";
location = "";
month = "";
day = 0;
year = 0;
area = 0;
}
//********************************************************
Parks::Parks(const Parks &p)
{
name = p.name;
location = p.location;
month = p.month;
day = p.day;
year = p.year;
area = p.area;
}
//********************************************************
void Parks::Print_Parks(fstream &outFile)
{
outFile << "Name: " << name << endl
<< "Location: " << location << endl
<< "Established: " << month << " " << day
<< ", " << year << endl << "Area: " <<
setprecision(2) << fixed <<
area << " acres" << endl << endl;
}
|