Sort Assignment

Here is my code for my linear search, can someone please help me fix my errors. I got no clue how to fix them!

Class
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Vehicle Class
class Car
{
protected:
	string make;  //make
    string model; // model
    string color;  // color
    int	year;  // year
    int mileage;  // miles on car
	int VIN;  //Vin Number of car

public:
		//Constructor that will set information for a new car
	void New_vehicle (string a, string b, string c, int d, int e, int f) 
	{make = a; model = b; color = c; year = d; mileage = e; VIN = f;}
	
	Car(); //Default constructor
	Car(string, string, string, int, int,int);
	//mutator and accessor functions
	void setMake(string);
    void setModel(string);
    void setColor(string);
    void setYear(int);
    void setMileage(int);
	void setVIN(int);

    string getMake();
    string getModel();
    string getColor();
    int getYear();
    int getMileage();
	int getVIN();

	//Check mileage to see if valid
    void valid_mileage(int);
    void car_details();
    string string_car_details();
};

//Sets to default values
Car::Car() {
	make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;
	VIN = 0;
}
	// My Vehicle set up(Make, model, color, year, type,bedsize, bike, mileage)
Car::Car(string make, string model, string color, int year, int mileage, int VIN) {
	Car::make =  make;
	Car::model = model;
	Car::color = color;
	Car::year = year;
    valid_mileage(mileage);
	Car::VIN = VIN;
}

void Car::setMake(string make) {
    Car::make = make;
}

void Car::setModel(string model) {
    Car::model = model;
}

void Car::setColor(string color) {
    Car::color = color;
}

void Car::setYear(int year) {
    Car::year = year;
}

void Car::setMileage(int mileage) {
    valid_mileage(mileage);
}

void Car::setVIN(int VIN) {
	Car::VIN = VIN;
}


string Car::getMake() {
    return make;
}
string Car::getModel() {
    return model;
}
string Car::getColor() {
    return color;
}
int Car::getYear() {
    return year;
}
int Car::getMileage() {
    return mileage;
}

int Car::getVIN() {
	return VIN;
}


void Car::valid_mileage(int mileage) {
    if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "WARNING! You have entered invalid mileage!\n";
	}
    }

	void Car::car_details() {
	    cout << "The current car is a " << year << ' ' << color << ' '
	    << make << ' ' << model << " with " << mileage << " miles.\n";
	}

	string Car::string_car_details() {
	    stringstream buf;
	    buf << "The current car is a " << year << ' ' << color << ' '
	    << make << ' ' << model << " with " << mileage << " miles.\n";
	    return buf.str();
	}



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
#include "CarClass.h"
using namespace std;

int searchList(int Vin);

int main() {
        
	        string temp;
		int tempInt;
        int current_vehicle=0; 
		int results; //results of linear search
		
			//Array of 9 cars
	Car Car_array[9] = {Car("Porsche","911","Silver", 2005, 18990, 1237362727), 
						Car("Ford","Mustang","Red", 2007, 49842, 7337372239),
						Car("Chevrolet","Beretta","Black", 1989, 90332, 2873644922),
						Car("Ford","Focus","White", 2008, 150, 9236498273),
						Car("Voltzwagon","Jetta","Black", 2006, 28002, 4673992056),
						Car("Rolls Royce","Ghost","Silver", 2005, 10000, 9292983855),
						Car("Mazda","626","Blue", 2002, 84754, 7364646463),
						Car("Toyota","Camry","Red", 2004, 50332, 2133737227),
						Car("Bugatti","Veyron 16.4","White", 2010, 5, 5712893401)
						};
	
	//Linear Search for VIN Number
	{
		int results = searchList( 2873644922);

		if (results == -1)
			cout << "You did not have a car with the VIN Number 2873644922.\n\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number 2873644922.\n\n";
		}
	}
		return 0;

}



ERRORS:

1>------ Build started: Project: Sorting, Configuration: Debug Win32 ------
1> Car.cpp
1>\car.cpp(15): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(15): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(17): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(17): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(18): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(18): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(19): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(19): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(20): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(20): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(22): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(22): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(11): warning C4101: 'results' : unreferenced local variable
1>\car.cpp(9): warning C4101: 'tempInt' : unreferenced local variable
1>Car.obj : error LNK2019: unresolved external symbol "int __cdecl searchList(int)" (?searchList@@YAHH@Z) referenced in function _main
1> \Sorting.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hint: VIN cannot be an int.
Then please help me pan, I am so confused on this assignment, please show me how it should be then!
Here is my new CPP file


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
#include "CarClass.h"
int search(Car[], string, int);

int main() {
        
	const int SIZE = 9;
			
	//Array of 9 cars
	Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727), 
							Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
							Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
							Car("Ford", "Focus", "White", 2008, 150, 9236498273),
							Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
							Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
							Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
							Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
							Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

	int desiredVin;
	int manualVIN= 2873644922;
	int pos;
	char doAgain;

	pos = search(Car_array, SIZE, manualVIN); 

		
	//Linear Search for VIN Number

		if (pos == -1)
			cout << "You did not have a car with the VIN Number 2873644922.\n\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number 2873644922.\n\n";
		}
	
		return 0;

}


Now I am getting these errors and it looks the same as my book example??
ERRORS:

1>------ Build started: Project: Sorting, Configuration: Debug Win32 ------
1> Car.cpp
1>\car.cpp(10): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(10): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(12): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(12): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(13): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(13): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(14): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(14): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(15): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(15): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(17): warning C4305: 'argument' : truncation from '__int64' to 'int'
1>\car.cpp(17): warning C4309: 'argument' : truncation of constant value
1>\car.cpp(19): warning C4101: 'desiredVin' : unreferenced local variable
1>\car.cpp(22): warning C4101: 'doAgain' : unreferenced local variable
1>Car.obj : error LNK2019: unresolved external symbol "int __cdecl search(class Car * const,int,int)" (?search@@YAHQAVCar@@HH@Z) referenced in function _main
1> Sorting.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Oh and guys I am understanding my searching but the set up of the search confuses me!

1
2
int search(Car[], string, int);
I added this to my code
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
#include "CarClass.h"
using namespace std;

int search(Car[], string, int);

int main() {
       
    const int SIZE = 9;
           
    //Array of 9 cars
    Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727),
                            Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
                            Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
                            Car("Ford", "Focus", "White", 2008, 150, 9236498273),
                            Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
                            Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
                            Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
                            Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
                            Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

    int desiredVin;
    int manualVIN= 2873644922;
    int pos;
    char doAgain;

    pos = search(Car_array, SIZE, manualVIN);

       
    //Linear Search for VIN Number

        if (pos == -1)
            cout << "You did not have a car with the VIN Number 2873644922.\n\n";
        else
        {
            cout << "You do have a car on the lot with the VIN Number 2873644922.\n\n";
        }
   
        return 0;

}

int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array
   int position = -1;     // Used to record position of search value
   bool found = false;    // Flag to indicate if the value was found

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag
         position = index;      // Record the value's subscript
      }
      index++;                  // Go to the next element
   }
   return position;             // Return the position, or -1
}// End search
   



Errors:

1>------ Build started: Project: Sorting, Configuration: Debug Win32 ------

1> Car.cpp

1>\sorting\sorting\car.cpp(12): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(12): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(14): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(14): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(15): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(15): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(16): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(16): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(17): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(17): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(19): warning C4305: 'argument' : truncation from '__int64' to 'int'

1>\sorting\sorting\car.cpp(19): warning C4309: 'argument' : truncation of constant value

1>\sorting\sorting\car.cpp(26): error C2664: 'search' : cannot convert parameter 2 from 'const int' to 'std::string'

1> No constructor could take the source type, or constructor overload resolution was ambiguous

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I got it to work guys! I changed my top line to this!

1
2
3

int search(Car[], int, int);


Topic archived. No new replies allowed.