#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class Vehical
{
protected:
	int reg_no;
	int id;
public:
	Vehical()
	{
		reg_no = 0;
		id = 0;
	}
	virtual void inputData() = 0;
	virtual void printData() = 0;
	virtual void writingDet() = 0;
	virtual int search(string) = 0;
};
class Bike :public Vehical
{
private:
	string Bike_clr;
	string bike_typ;
	int model;
public:
	Bike() :Vehical()
	{
		Bike_clr = "";
		bike_typ = "";
		model = 0;
	}
	void inputData()
	{
		cout << "Enter registration no of Bike : " << ' ';
		cin >> reg_no;
		cout << "Enter ID of Bike : " << ' ';
		cin >> id;
		cin.ignore();
		cout << "Enter Bike Color : " << ' ';
		getline(cin, Bike_clr);
		cout << "Enter Bike Type : " << ' ';
		getline(cin, bike_typ);
		cout << "Enter Model (year) : " << ' ';
		cin >> model;
	}
	void printData()
	{
		cout << "Reg No.  " << reg_no << endl;
		cout << "ID no.  " << id << endl;
		cout << "Bike Color  " << Bike_clr << endl;
		cout << "Bike Type  " << bike_typ << endl;
		cout << "Model Year  " << model << endl;
	}
	void writingDet()
	{
		ofstream file;
		if (bike_typ == "Heavy Bike")
		{
			file.open("Heavy Bike.txt", ios::app);
			if (file.is_open())
			{
				file << reg_no << endl;
				file << id << endl;
				file << Bike_clr << endl;
				file << bike_typ << endl;
				file << model << endl;
				file << endl;
			}
			else
			{
				cerr << "Your File cannot be open" << endl;
			}
		}file.close();
	}
	int search(string clr)
	{
		string line;
		ifstream fm;
		fm.open("Heavy Bike.txt");
		for (line; getline(fm, line);)
		{

			if (line.find(clr) != string::npos)
			{
				cout << "\n\nFound" << endl;
				fm >> reg_no;
				cout << reg_no << endl;
				fm >> id;
				cout << id << endl;
				getline(fm, Bike_clr);
				cout << Bike_clr << endl;
				getline(fm, bike_typ);
				cout << bike_typ << endl;
				fm >> model;
				cout << model << endl;
			}
		}
		return 1;
	}
};
class Car :public Vehical
{
private:
	string car_clr;
	string car_typ;
	int crmodel;
public:
	Car()
	{
		car_clr = "";
		car_typ = "";
		crmodel = 0;
	}
	void inputData()
	{
		cout << endl;
		cout << "Enter registration no of Car : " << ' ';
		cin >> reg_no;
		cout << "Enter ID of Car : " << ' ';
		cin >> id;
		cin.ignore();
		cout << "Enter Car Color : " << ' ';
		getline(cin, car_clr);
		cout << "Enter Car Type : " << ' ';
		getline(cin, car_typ);
		cout << "Enter Model (year) : " << ' ';
		cin >> crmodel;
		cin.ignore();
		cout << endl;
		cout << endl;
	}
	void printData()
	{
		cout << "Reg No.  " << reg_no << endl;
		cout << "ID no.  " << id << endl;
		cout << "Car Color  " << car_clr << endl;
		cout << "Car Type  " << car_typ << endl;
		cout << "Model Year  " << crmodel << endl;
	}
};
int main()
{
	Vehical* vc[5];
	Bike bk;
	string clr;
	bool found;
	for (int i = 0; i < 2; i++)
	{
		vc[i] = new Bike;
		vc[i] = &bk;
		vc[i]->inputData();
		vc[i]->writingDet();
	}
	cin.ignore();
	cout << "\nEnter Color of Bike you want : " << ' ';
	getline(cin, clr);
	for (int k = 0; k < 2; k++)
	{
		found = vc[k]->search(clr);
		if (found)
		{
			break;
		}
		else
		{
			continue;
		}
	}
	cout << endl;
	system("PAUSE");
	return 0;
}