//	NAME		: MEGAT IRFAN ZACKRY BIN ISMAIL (A20EC0205)
//	SECTION		: 06
//	LECTURER	: DR. HUSSEIN SALEM ALI SAMMA
//	DATE		: 17 MARCH 2021
//	TUTORIAL_1
	
#include <iostream>
#include <iomanip>
#include <fstream>
#define CONST 10
using namespace std;

// Decleare the structs
struct Engine
{
	string capacity;
	int cylinder;
};

struct Vehicle 
{
	string make, color; 
	float cost;
	Engine vehicle_engine;
};

// define functions prototype

int readVehicles(Vehicle []); 
void displaySearchOutput(Vehicle [], int, float, float); 


/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
 
Vehicle vehicles[CONST];
int numVehicles;
float min_cost, max_cost;

numVehicles=readVehicles(vehicles);
cout << "Enter your search range (min_cost,max_cost) :"<<endl;
cin >> min_cost >> max_cost;
displaySearchOutput(vehicles, numVehicles, min_cost, max_cost);


return 0;
}


int readVehicles(Vehicle data[])
{
	ifstream input ("input.txt");
	int no_items = 0;
	int i =0;
	while(!input.eof())							
	{
		input >> data[i].make;
		input >> data[i].color;
		input >>data[i].cost;
		input >> data[i].vehicle_engine.capacity;
		input >> data[i].vehicle_engine.cylinder;
		no_items++;
		i++;
	}
	input.close();									
	return no_items;
}

void displaySearchOutput(Vehicle data[], int no_vehicles, float min, float max)
{
	int vehiclesfound=0;
	cout << "-------------------------------------------------------------------------------"<<endl;
	cout<<left;
	cout <<setw(12)<<"MAKE"<<setw(12)<<"COLOR"<<setw(12)<<"COST(RM)"<<setw(12)<<"CAPACITY"<<setw(12)<<"CILINDERS"<<endl;
	cout << "-------------------------------------------------------------------------------"<<endl;
	
	for (int i = 0; i < no_vehicles; i++)
    {
        if ((data[i].cost<=max)&&(data[i].cost>=min))
        {
            cout << setw(12)<<data[i].make<<setw(12)<<data[i].color<<setw(12)<<data[i].cost<<setw(12)<<data[i].vehicle_engine.capacity<<setw(12)<<data[i].vehicle_engine.cylinder<<endl;
        	vehiclesfound++;
		}
        
        
    }
    	cout << "-------------------------------------------------------------------------------"<<endl;
    	cout <<vehiclesfound<<" Vehicles were found within cost range ( RM "<<min<<" , RM "<<max<<" )";
}
