Binary array search (string) and array sort not working

Hey guys, wondering if anybody could take a quick look at this and let me know why my arrays aren't sorting or searching correctly. My brain is way too burned out to think straight right now, so any help that you can provide is much appreciated!

prog6.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
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
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#include "Car.h"

void readFile (ifstream&, Car[]);
void sortByModel (Car[], Car*[]);
void searchByModel (Car[], Car*[], string, int&);
void assignPointers (Car[], Car*[]);

int main()
{
    Car* carPtr[10];
    Car carArray[10];

    ifstream fin;
    string ifName;
    string modelSearch;
    int searchResult;

    cout << "Enter the name of the file you want to open: ";
    cin >> ifName;

    fin.open(ifName.c_str());

    if (fin.fail())
    {
        cout << "Could not open the specified file.";
    }

    readFile (fin, carArray);

    assignPointers(carArray, carPtr);

    sortByModel (carArray, carPtr);

    for (int z=0; z < 10; z++)
    {
        carArray[z].print();
    }

    cout << "Enter a vehicle model to search: ";
    cin >> modelSearch;
    searchByModel (carArray, carPtr, modelSearch, searchResult);

    if (searchResult >= 0)
    {
        cout << "Your vehicle model was found in array position " << searchResult
             << ".";
    }

    else
    {
        cout << "Your vehicle model was not found in the array.";
    }


}

void readFile (ifstream&inFile, Car carArr[])
{
    for (int i=0; i < 10; i++)
    {
        string aMake, aModel;
        int aYear;
        double aValue;
        getline(inFile, aMake);
        getline(inFile, aModel);
        inFile >> aYear;
        inFile >> aValue;
        carArr[i].setMake(aMake);
        carArr[i].setModel(aModel);
        carArr[i].setYear(aYear);
        carArr[i].setValue(aValue);
        inFile.ignore(100, '\n');
        inFile.ignore(100, '\n');

        if(inFile.eof())
        {
            break;
        }

    }

}

void assignPointers(Car carArr[], Car*carPoint[])
{
    for (int j=0; j < 10; j++)
    {
        carPoint[j] = &(carArr[j]);
    }
}


void sortByModel (Car carArr[], Car*carPt[])

{

    int minPos = 0;
    int tempVal;

    for (int i=10; i < 10; i++)
    {
        for (int k=minPos+1; k < 10; k++)
        {
            if (carArr[k].getModel() < carArr[minPos].getModel())
            {
                tempVal = k;
                k = minPos;
                minPos = tempVal;

            }

        }
    minPos++;
    }
}

void searchByModel (Car carArr[], Car*carPt[], string modelIn, int&itemFound)
{

//  int modelBinary;
//  modelBinary = modelIn;
//  int newArr[10];
//
//  for (int j=0; j < 10; j++)
//  {
//      newArr[j] = carArr[j].getModel();
//  }



    for (int i=0; i < 10; i++)
    {

        if (modelIn == carArr[i].getModel())
        {
            itemFound = i;
        }

        else
        {
            itemFound = -1;
        }

    }
}


Car.h
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
/*************************
* Jade Scholz            *
* CSCI 123 - Spring 2012 *
* Program # 4            *
* Due 05.04.12           *
*************************/


#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>

using namespace std;



class Car
{
    private:            // Fields for Car class
        string make;
        string model;
        int year;
        double value;
    public:
        Car (string, string, int, double);
        Car ();
        void setMake (string);  // Sets car make
        void setModel (string); // Sets car model
        void setYear (int);     // Sets car year
        void setValue (double); // Sets car value
        string getMake();       // Returns car make
        string getModel();      // Returns car model
        int  getYear();         // Returns car year
        double getValue();      // Returns car value
        void print(ofstream&);  // Prints data to output file
        void print();           // Prints data to screen
        ofstream outFile;
};

Car::Car(string make, string model, int year, double value) // Initialize
{}

Car::Car() : make("no make"), model("no model"), year(2012), value(0.00) // Set defaults
{}

void Car::setMake(string carMake )  // Sets car make
{
    make = carMake;
}

void Car::setModel(string carModel )    // Sets car model
{
    model = carModel;
}

void Car::setYear(int carYear)          // Sets car year
{
    year = carYear;             // If year is less than 1769, more than 2012, returns 2012
    if (year < 1769 || year > 2012)
    {
        year = 2012;
    }
}

void Car::setValue(double carValue) // Sets car value (sets to 0 if negative)
{
    value = carValue;
    if (value < 0)
    {
        value = 0.00;
    }
}

string Car:: getMake()      // Returns car make
{
    return make;
}

string Car::getModel()      // Returns car model
{
    return model;
}

int Car::getYear()          // Returns car year
{
    return year;
}

double Car::getValue()      // Returns car value
{
    return value;
}

void Car::print(ofstream&outFile)       // Prints car data out to file
{
    outFile << setw(6) << left << year << setw(15) << left << make << setw(20) << left
         << model << setw(10) << setprecision(2) << fixed << right << value << endl;

}

void Car::print()                       // Prints car data out to screen
{
    cout << setw(6) << left << year << setw(15) << left << make << setw(20) << left
         << model << setw(10) << setprecision(2) << fixed << right << value << endl;
}


cars.txt
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
Ford
Mustang
2000
12312.00

Ford
Mustang
2005
32918.00

Ford
Mustang
2012
65230.00

Ford
F-350 Super Duty
2011
82152.00

BMW
M5
2006
67982.00

Aston Martin
V8 Vantage
2009
98231.00

Lamborghini
Aventador
2011
123151.00
Topic archived. No new replies allowed.