#include "stdafx.h"
#include "pch.h"
#include "functions.h"
int skolkovsegosvedeni(string fileee)
{
	ifstream read(fileee);
	int k = 0;
	if (read) {
		read >> k;
	}
	else
		printf("  ! \n");
	read.close();
	return k;
}
void readfileandotkr(string fileee, machine *q)
{
	ifstream read(fileee);
	int k = 0;
	if (read) {
		read >> k;
		for (int i = 0; i < k; i++)
		{
			read >> q[i].marka;
			read >> q[i].god;
			read >> q[i].speed;
			read >> q[i].color;
			read >> q[i].xarakt.dwijok;
			read >> q[i].xarakt.transmis;
			read >> q[i].xarakt.podveska;
		}
	}
	else
		printf("  ! \n");
	read.close();
}
void pokaz(machine *q, int jj)
{
	for (int i = 0; i < jj; i++)
	{
		cout << "    " << i + 1 << endl;
		cout << " : " << q[i].marka << endl;
		cout << " : " << q[i].god << endl;
		cout << " : " << q[i].speed << endl;
		cout << " : " << q[i].color << endl;
		cout << " : " << q[i].xarakt.dwijok << endl;
		cout << " : " << q[i].xarakt.transmis << endl;
		cout << " : " << q[i].xarakt.podveska << endl;
		cout << "__________________________________\n";
	}
}
void RecordInFile(string fileee, machine * q, int jj)
{
	ofstream zapis(fileee);
	if (zapis) {
		for (int i = 0; i < jj; i++)
		{
			zapis << "    " << i + 1 << endl;
			zapis << " : " << q[i].marka << endl;
			zapis << " : " << q[i].god << endl;
			zapis << " : " << q[i].speed << endl;
			zapis << " : " << q[i].color << endl;
			zapis << " : " << q[i].xarakt.dwijok << endl;
			zapis << " : " << q[i].xarakt.transmis << endl;
			zapis << " : " << q[i].xarakt.podveska << endl;
			zapis << "__________________________________\n";
		}
	}
	else
		printf("  ! \n");
	zapis.close();
}
bool poiskponame(machine * q, int jj, string kk)
{
	bool seek = false;
	for (int i = 0; i < jj; i++) {
		if (q[i].marka == kk)
		{
			cout << "    " << i + 1 << endl;
			cout << " : " << q[i].marka << endl;
			cout << " : " << q[i].god << endl;
			cout << " : " << q[i].speed << endl;
			cout << " : " << q[i].color << endl;
			cout << " : " << q[i].xarakt.dwijok << endl;
			cout << " : " << q[i].xarakt.transmis << endl;
			cout << " : " << q[i].xarakt.podveska << endl;
			cout << "__________________________________\n";
			seek = true;
		}
	}
	return seek;
}
bool poiskpogody(machine * q, int jj, int year)
{
	bool seek = false;
	for (int i = 0; i < jj; i++) {
		if (q[i].god == year)
		{
			cout << "    " << i + 1 << endl;
			cout << " : " << q[i].marka << endl;
			cout << " : " << q[i].god << endl;
			cout << " : " << q[i].speed << endl;
			cout << " : " << q[i].color << endl;
			cout << " : " << q[i].xarakt.dwijok << endl;
			cout << " : " << q[i].xarakt.transmis << endl;
			cout << " : " << q[i].xarakt.podveska << endl;
			cout << "__________________________________\n";
			seek = true;
		}
	}
	return seek;
}
void sortirovkaponame(machine * q, int jj)

	machine qq;
	for (int i = 0; i < jj - 1; i++) {
		for (int j = 0; j < jj - i - 1; j++) {
			if (q[j].marka > q[j + 1].marka) {
				qq = q[j];
				q[j] = q[j + 1];
				q[j + 1] = qq;
			}
		}
	}
}

void sortirovkapogody(machine * q, int jj)
{
	machine qq;
	for (int i = 0; i < jj - 1; i++) {
		for (int j = 0; j < jj - i - 1; j++) {
			if (q[j].god > q[j + 1].god) {
				qq = q[j];
				q[j] = q[j + 1];
				q[j + 1] = qq;
			}
		}
	}
}
bool Filtration(machine * q, int jj, int a, int b)
{
	bool seek = false;
	for (int i = 0; i < jj; i++) {
		if (q[i].god >= a && q[i].god <= b)
		{
			cout << "    " << i + 1 << endl;
			cout << " : " << q[i].marka << endl;
			cout << " : " << q[i].god << endl;
			cout << " : " << q[i].speed << endl;
			cout << " : " << q[i].color << endl;
			cout << " : " << q[i].xarakt.dwijok << endl;
			cout << " : " << q[i].xarakt.transmis << endl;
			cout << " : " << q[i].xarakt.podveska << endl;
			cout << "__________________________________\n";
			seek = true;
		}
	}
	return seek;
}
void Copy(machine * p, machine * h, int n)
{
	for (int i = 0; i < n; i++) {
		h[i].marka = p[i].marka;
		h[i].speed = p[i].speed;
		h[i].color = p[i].color;
		h[i].god = p[i].god;
		h[i].xarakt.dwijok = p[i].xarakt.dwijok;
		h[i].xarakt.transmis = p[i].xarakt.transmis;
		h[i].xarakt.podveska = p[i].xarakt.podveska;
	}
}