#include <iostream>
#include <fstream>
#include <string>
#include <vector>
//using namespace std;
struct ownerCar {
std::string name;
std::string model;
std::string number;
};
bool IsExist(std::vector<std::string> v,std::string s);
const int SIZE = 9;
void Save(ownerCar own[SIZE]);
void Load(ownerCar own[SIZE]);
int main(int argc, char* argv[])
{
ownerCar owner;
ownerCar owners[SIZE] = {
{"porox","ZAZ","35-65-85"},{"yatsenuk","ZAZ","22-22-22"},
{"porox","LAZ","33-65-55"},{"yanuk","LUAZ","30-00-05"},
{"porox","BELAZ","33-65-55"},{"yanuk","GAZ-66","30-00-05"},
{"klichko","LAZ","33-65-51"},{"klichko","LUAZ","32-00-25"},
{"porox","ROVER","33-65-55"}};
std::vector<std::string> cars_names;
for(int i = 0; i < SIZE; i++)
{
if((owners[i].number.at(0) == '3')&&(owners[i].number.at(owners[i].number.size()-1) == '5'))
{
std::cout << owners[i].number << std::endl;
if(!IsExist(cars_names,owners[i].model))
cars_names.push_back(owners[i].model);
}
}
int count = 0;
for(int i = 0;i< (int)cars_names.size();i++)
{
for(int j = 0; j < SIZE; j++)
{
if(cars_names.at(i) == owners[j].model)
count++;
}
std::cout << "Model " << cars_names.at(i) << " " << count << std::endl;
count = 0;
}
Save(owners);
Load(owners);
std::cout << owners[7].name << "\n";
std::getchar();
return 0;
}
bool IsExist(std::vector<std::string> v,std::string s)
{
for(int i = 0;i< (int)v.size();i++)
{
if(v.at(i) == s)
return true;
}
return false;
}
void Save(ownerCar own[SIZE])
{
std::ofstream outfile;
outfile.open("owners.dat",std::ios::out | std::ios::binary);
if(!outfile.is_open()) {
std::cout<<"File not open"<< std::endl;
return;
}
for(int i = 0; i < SIZE;i++)
{
outfile.write((char *) &own[i], sizeof ownerCar);
}
outfile.close();
}
void Load(ownerCar own[SIZE])
{
std::ifstream infile;
infile.open("owners.dat",std::ios::in | std::ios::binary);
if(!infile.is_open()) {
std::cout<<"File not open"<< std::endl;
return;
}
for(int i = 0; i < SIZE;i++)
{
infile.read((char *) &own[i], sizeof ownerCar);
}
infile.close();
}