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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
const int MAX=40; // max amounts of car rentals
const int N=10; // this helps with formating
const int L=20; // this helps with columns with
struct apttype //this will hold the data from the 1st input file
{
string Make; //Make of the car
string Model; //average points per game
string LicenseNum; //Plate Numbers
char cartype; //this will read the letter of compact or standard....
string cartypename; // this will hold the name of compact or standard....
string Status; // this will let hold the available status
};
struct apttype_Rented //this will hold the inventory data
{
string Make2;
string Model2;
string LicenseNum2;
char cartype2;
string cartypename2;
string Status2;
};
int search(apttype[], int, string); // this will search the invertory list to the 1st input
void read_apt_data(apttype[],int&); // this will read the 1st input file
void read_apt_data_Rented(apttype[],apttype_Rented[],int&, int&); // this will read the inventory
void print_report(apttype[],apttype_Rented[], int, int); // this will print to the output file
void fixname(string&);// this will fix the names of make and models
void fixnameCapital(string&); // this will capitalize all plate numbers
void sort(apttype[],int); // this was added but not sure if ill sort the list.
int main()
{
apttype myapts[MAX]; //list max from 1st input file
apttype_Rented myapts2[MAX]; //list max from 2nd input file
int n=0; //# of elements in 1st input
int m=0; //# of elements in 2nd input
read_apt_data(myapts,n);
read_apt_data_Rented(myapts,myapts2,n,m);
sort(myapts,n);
print_report(myapts,myapts2,n,m);
return 0;
}
void fixname(string& name) // this will Capitalized only the first letter only
{
name[0] = toupper(name[0]);
for (int i=1;i<name.length();i++)
name[i]=tolower(name[i]);
}
void fixnameCapital(string& name) // this will make all the letters capitalized.
{
for (int i=0;i<name.length();i++)
name[i]=toupper(name[i]);
}
void read_apt_data(apttype apts[],int& n) // this will ask for the 1st input file
{
ifstream infile;
string filename;
ofstream out;
cout << "Enter the Name of the Input file" << endl;
cin >> filename;
infile.open(filename.c_str());
string cartypename;
string Status = "Available";
n = 0;
if(infile.is_open())
{
infile >>apts[n].LicenseNum;
while (infile)
{
fixnameCapital(apts[n].LicenseNum);
infile >> apts[n].Make;
fixname(apts[n].Make);
infile >> apts[n].Model;
fixname(apts[n].Model);
infile >> apts[n].cartype;
if (toupper(apts[n].cartype) == 'S')
apts[n].cartypename = "Standard";
else if (toupper(apts[n].cartype) == 'C')
apts[n].cartypename = "Compact";
else if (toupper(apts[n].cartype) == 'P')
apts[n].cartypename = "Premium";
apts[n].Status = "Available";
n++;
infile >>apts[n].LicenseNum;
}
infile.close();
}
else
cout<<"Error: file\"" <<filename<<"\" was not opened\n";
}
void read_apt_data_Rented(apttype apts[],apttype_Rented apts2[],int& n, int& m)
{
ifstream infile2;
string filename2;
cout << "Enter the Name of the Inventory file" << endl;
cin >> filename2;
infile2.open(filename2.c_str());
string cartypename2;
string Status2 = "Rented";
n = 0;
m = 0;
if(infile2.is_open())
{
infile2>>apts2[m].LicenseNum2;
while (infile2)
{
fixnameCapital(apts2[m].LicenseNum2);
apts2[m].Status2 = "Rented";
m++;
infile2>>apts2[m].LicenseNum2;
}
infile2.close();
}
else
cout<<"Error: file\"" <<filename2<<"\" was not opened\n";
}
void print_report(apttype apts[], apttype_Rented apts2[] ,int n, int m)
{
ofstream out;
string outfilename;
cout <<"Enter the name of the output file \n";
cin >> outfilename;
out.open(outfilename.c_str(),ios::app);
out<< "==========================================="<< endl;
out<< "==========================================="<< endl<<endl;
out<<endl<<left<<setw(N)<<"License#"
<<setw(N)<<"Make"
<<setw(N)<<"Model"
<<setw(N)<<"Car Type"
<<setw(N)<<"Status"
<<endl;
for (int i=0; i<n; i++)
{
out<<left<<setw(N)<<apts[i].LicenseNum
<<setw(N) <<apts[i].Make
<<setw(N)<<apts[i].Model
<<setw(N)<< apts[i].cartypename
<<setw(N)<<apts[i].Status<<endl;
}
/* This is where i need the search to be called were it would take input file 2
and find the matches inside of the 1st file. */
int place;
string target = "";
string myapts;
for(int j=0; j<m; j++)
{
apts2[j]>>target;
out<<target<<"";
place = search(myapts, n, target);
if (place >= 0)
out<<"found at position "<< place;
else
out<<"not found"; out<<endl;
}
out.close();
}
void sort(apttype myapts[],int n)
{
apttype temp; //place holder when values are interchanged \
for (int i=0; i < n-1; i++)
for (int j=0; j < n-(i+1); j++)
if (myapts[j].Model < myapts[j+1].Model)
{
temp = myapts[j];
myapts[j] = myapts[j+1];
myapts[j+1] = temp;
}
}
int search(string myapts[], int n, string target) //This will search the inventory
{
for(int i = 0; i < n; i++)
if (myapts[i]==target)
return i;
return -1;
}
|