Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please I need my answer in 20 min best 0% Fall 2018 ,EPP (10am) eparated by whit

ID: 3743223 • Letter: P

Question

please I need my answer in 20 min
best

0% Fall 2018 ,EPP (10am) eparated by whitespaces. These are the model name le data. txt) Write a class that reads in a text file file contains three pieces of information s of a car, its license plate number, and its mileage. An example is given below (f Camry 2ABC334 102324 Corolla 7ABC234 12989 CRV Corolla 7LMN234 23745 Camry CRV Corolla 7ABC809 60026 7ABC564 24787 2DEE334 142090 7DEF564 42321 Corolla 7EFG234 45056 Focus Camry 2DAF304 112805 5 KNA305 105201 Implement a class carInventory that reads in such a text file. The class should have the following public member functions: CarInventory (string filename): the constructor which t of the data and reads in the data to its member variables takes in the filename rofCars: returns the number of cars in the store, ie., the number of lines in the file? (e.g.. 10 for the data file shown above) . string getModel(string license): return s the model name as a string for the input license plate number (e.g., given 7LMN234, return Corolla) . string getclosestMileage (int mileage) returns the license p the car which has the closest mileage below or equal to the input mileage. (e.g., giver 60000, return 7EFG234 since its mileage 45056 is closest to 60000). If there is no such car, return the empty string. These public member functions will be called from the provided main program and the answ printed there (see file part2.app You are free to add other (public/private) member variables and functions as needed do not change the contents of this file) .Implement all your code in one header file called CarInventory.h Class and filenames are case-sensitive. The class and filenames should be CarInventory (not Carinventory, carinventory, ...) . Simplifying assumptions: The maximum number of cars in the database is 1,000,000 Model names and licence plate numbers are a single word without spaces. Mileage is an integer . You do not need to do any error-checking when reading the data file Resources You are given files containing templates for a Stack, Queue, and Vector class. For eact data structures, you are also provided with a test program. You may use none, any, them if it will help you. You are also free to edit any of these files. All these files a in the "EPP Part 2 Files" section. You can also use the STL versions of any data st File upload: Upload CarInventory.h, along with any data structure files that you

Explanation / Answer

#ifndef CARINVENTORY_H

#define CARINVENTORY_H

#include <vector>

#include <fstream>

struct CarData {

std::string model;

std::string license;

int mileage;

};

class CarInventory {

std::vector <CarData> data;

public:

CarInventory() {}

CarInventory(std::string filename) {

std::ifstream in(filename);

CarData c;

while(in>>c.model) {

in>>c.license>>c.mileage;

data.push_back(c);

}

}

static int abs(int a) {

if(a >= 0) return a;

else return -a;

}

int numberOfCars() {

return data.size();

}

std::string getModel(std::string license) {

for(std::vector <CarData>::iterator it = data.begin(); it != data.end(); it++) {

if(it->license == license)

return it->model;

}

return "";

}

std::string getClosestMileage(int mileage) {

int min = mileage;

std::vector <CarData>::iterator min_it = data.begin();

for(std::vector <CarData>::iterator it = data.begin(); it != data.end(); it++) {

if(abs(it->mileage - mileage) < min) {

min = abs(it->mileage - mileage);

min_it = it;

}

}

return min_it->license;

}

};

#endif