help with inventory functions

i am needing help defining functions for this inventory program. any help would be appreciated. here is my program so far:

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

struct UsedCarID {
char StockNumber[20];
int Year;
char Make[20];
char Model[20];
char Color[20];
int Mileage;
char VIN[20];
char License[20];
int InternetPrice;
int RetailPrice;
};

int main()
{ 
	int count = 0, choice, a, b, c, d, e, f, g, h;
	string temp;
	ifstream infile;

	cout << "what is the inventory file that needs to be used? "<< endl;
	cin >> "filename";
	
	infile.open ("filename");
	if (infile.fail()){
		cout << "\n...Error opening the file" << endl;
		exit (1);
	}
	while (!infile.eof()) {
		getline(infile,temp);
		count++;
	}

	infile.seekg (0, ios::beg);

	UsedCarID *carinfo;
	carinfo=new UsedCarID[count];

	for (int i=0; i<count; i++) {
		infile >> carinfo[i].StockNumber;
		infile >> carinfo[i].Year;
		infile >> carinfo[i].Make;
		infile >> carinfo[i].Model;
		infile >> carinfo[i].Color;
		infile >> carinfo[i].Mileage;
		infile >> carinfo[i].VIN;
		infile >> carinfo[i].License;
		infile >> carinfo[i].InternetPrice;
		infile >> carinfo[i].RetailPrice;
	}
	
	cout << "which criteria would you like to search for a vehicle?" <<endl;
	cout << "1 - List of cars with specified Internet Price" <<endl;
	cout << "2 - List of cars with specified Mileage" <<endl;
	cout << "3 - List of cars made within a specified range of Years." <<endl;
	cout << "4 - List of cars with a specified Make" <<endl;
	cout << "5 - List of cars whose VIN ends with 4 specified digits" <<endl;
	cout << "6 - Exit" <<endl;
	cin >> choice;

	switch (choice) {
	case 1: 
		cout << "what internet price do you want to search for?" <<endl;
		cout << "Minimum value - " <<endl;
		cin >> a;
		cout << "maximum value - " <<endl;
		cin >> b;
		break;
		
	case 2:
		cout << "what mileage do you want to search for?" <<endl;
		cout << "Minimum value - " <<endl;
		cin >> c;
		cout << "maximum value - " <<endl;
		cin >> d;
		break;
	case 3:
		cout << "what year do you want to search for?" <<endl;
		cout << "Minimum value - " <<endl;
		cin >> e;
		cout << "maximum value - " <<endl;
		cin >> f;
		break;
	case 4:
		cout << "what Make do you want to search for?" <<endl;
		cout << "Make - " <<endl;
		cin >> g;
		
		break;
	case 5:
		cout << "what last 4 VIN numbers do you want to search for?" <<endl;
		cout << "last 4 VIN numbers - " <<endl;
		cin >> h;
		
		break;
	case 6:
		return(0);
		break;
	}


	cout<<endl;
	return 0;
}
Can you give complete problem statement?
User must be prompted for the name of the inventory file.
Each car’s record must be stored in a structure with tag UsedCarID and defined as
follows:
struct UsedCarID {
char StockNumber[20];
int Year;
char Make[20];
char Model[20];
char Color[20];
int Mileage;
char VIN[20];
char License[20];
int InternetPrice;
int RetailPrice;
};
Depending on the number of records in the inventory file, the
program must allocate sufficient amount of memory dynamically.
the program must be able to respond to queries using the following menu.
1 List of cars with Internet Price within a user-supplied range.
2 List of cars with Mileage within a user-supplied range.
3 List of cars made within a user-supplied range of Years.
4 List of cars with a user-supplied Make.
5 List of cars whose VIN ends with 4 user-specified digits.
6 Exit
Each of the above must be implemented as a user-defined function call.
Record of car(s) meeting the specified search conditions must be outputted to the console
with the aid of a user-defined function and in the format shown in the attachment.
If no cars meet the specified search conditions, the user must be notified as such.
Here are 2 functions defined,one of them should be called in case 1 after cin>>b;

Funcitons are:

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
void ShowCarInfo(UserCarID carinfo)
{
    cout <<endl<< carinfo.StockNumber;
    cout <<endl<< carinfo.Year;
    cout << endl<<carinfo.Make;
    cout <<endl<< carinfo.Model;
    cout <<endl<< carinfo.Color;
    cout <<endl<< carinfo.Mileage;
    cout << endl<<carinfo.VIN;
    cout <<endl<< carinfo.License;
    cout <<endl<< carinfo.InternetPrice;
    cout << endl<<carinfo.RetailPrice
}

void SearchCarsForInternetPriceRange(int low,int high,UserCarID * carsinfo,int count)
{
 int searchcount = 0; 
 int i=0;

 cout<<endl<<"The car(s) information whose price is in range "<<low<<"  to "<<high<<" : ";

 for(i=0;i<count;i++)
{
 if((carsinfo[i].InternetPrice >= low) && (carsinfo[i].InternetPrice <= high))
 {
	ShowCarInfo(carsinfo[i]);
	searchcount++;
 }
}

if(searchcount == 0)
{
	cout<<endl<<"No cars found having internet price in the range "<< low<<"  to "<<high;
}
}


and case 1 has to be modified like

1
2
3
4
5
6
7
8
9
case 1: 
		cout << "what internet price do you want to search for?" <<endl;
		cout << "Minimum value - " <<endl;
		cin >> a;
		cout << "maximum value - " <<endl;
		cin >> b;

                                SearchCarsForInternetPriceRange(a,b,carinfo,count);
		break;


Hope this helps coding further...
Last edited on
yes it was very helpful. thanks a million!!
Topic archived. No new replies allowed.