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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
#include <vector>
using namespace std;
struct flight{
string name;
int miles;
flight (string, int);
};
int readFlights (string, vector<flight>& flights);
int findIndex (string [], int, string);
int main(int argc, char *argv[])
{
if(argc != 3){
cout<<"requires 2 filenames as command line arguments- a flight and a command file"
<<endl;
}
vector<flight>flights;
int capacity, size, x, i, Noflights;
string target, flightFile, commandFile, var, flight, ffn, floc, flightloc;
ifstream fin(argv[1]);
ifstream din(argv[2]);
fin.open(flightFile.c_str());
if(fin.fail()){
cout<<argv[1]<<": No such file or directory"; //first issue
return 0;}
capacity = 10;
size = 20;
i=0;
string ff_n [capacity];
int ff_m [capacity];
string flight_n [size];
int flight_m [size];
for (x=10;x<0; x--){
ff_m [x] = 0;
}
for (x=20;x<0; x--){
flight_m [x] =0;
}
for(x=10;x<0;x--){
fin >> ff_n [x];
}
din.open(commandFile.c_str());
if(din.fail()){
cout<<argv[2]<<": No such file or directory"; //first issue
return 0;
}
Noflights=readFlights (flightFile, flights);
if(Noflights==0){
return 0;
}
while(fin>>var){
if(var=="register"){
fin>>ff_n[i];
i++;
}
}
cout<<"Frequent Flyer Report"<<endl<<endl;
for(int x=0;x<capacity;x++){
cout<<left<<setw(8)<<ff_n[x]<<right<<setw(5)<<ff_m[x]<<endl; //how to run only the names without etra endls from enpty spots
fin.close();
}
return 0;
}
int readFlights (string flightFile, vector<flight>& flights){
ifstream din("flightFile");
din.open("flightFile");
int x=0;
if (din.fail()){
cout << "flight failed";
//return 1;
}
int m;
string n;
while (din >> n >> m){
x++;
flights.push_back(flight(n,m));
}
din.close();
return x;
}
flight::flight(string n, int m){
name=n;
miles=m;
}
|