Хочу сделать поиск в файле по количеству комнат и диапазону цен, всё по запросу пользователя. Есть пока лишь это
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <vector>
using namespace std;
class RealtorOffice
{
public:
string Location;
string LocOfDeclarant;
int NumberOfRooms;
int Price;
};
void print(RealtorOffice &obj)
{
cout << "Location: "<<obj.Location<<"\nLocation of declarant: "<<obj.LocOfDeclarant<<"\nNumber of rooms: "<<obj.NumberOfRooms<<"\nPrice: "<<obj.Price<<"\n\n"<<endl;
}
void input();
void output();
//void search_by_num();
//void search_by_price()
int menu()
{
cout << " ::: YOOO ::: " <<endl<< endl;
cout << "****************************************************" << endl << endl;
cout << ":::Menu:::\n\n";
int choice;
cout<<"0. Exit"<<endl
<<"1. All"<<endl
<<"2. Search by number of rooms"<<endl
<<"3. Search by price"<<endl
<<"Ваш вибір ->";
cin>>choice;
return choice;
}
void input()
{
ofstream file_obj;
file_obj.open("Input.txt", ios::app);
RealtorOffice obj;
obj.Location = "New_York";
obj.LocOfDeclarant = "LA";
obj.NumberOfRooms = 1;
obj.Price = 150;
file_obj << obj.Location << " ";
file_obj << obj.LocOfDeclarant << " ";
file_obj << obj.NumberOfRooms << " ";
file_obj << obj.Price << endl;
obj.Location = "Chicago";
obj.LocOfDeclarant = "Chicago";
obj.NumberOfRooms = 2;
obj.Price = 250;
file_obj << obj.Location << " ";
file_obj << obj.LocOfDeclarant << " ";
file_obj << obj.NumberOfRooms << " ";
file_obj << obj.Price << endl;
}
void output(vector<RealtorOffice> &v)
{
ifstream file_obj;
file_obj.open("Input.txt");
RealtorOffice obj;
for(string s; getline(file_obj,s);)
{
stringstream stream(s);
stream >> obj.Location;
stream >> obj.LocOfDeclarant;
stream >> obj.NumberOfRooms;
stream >> obj.Price;
v.push_back(obj);
print(obj);
}
}
int main()
{
input();
vector<RealtorOffice> v;
vector<RealtorOffice> res;
int choice;
do
{
choice = menu();
switch(choice)
{
case 0: cout<<"Bye"<<endl;
break;
case 1:output(v);
break;
/* case 2:search_by_num();
break;*/
/*case 3:search_by_price();
break;*/
}
}
while(choice!=0);
return 0;
}
пробовала что-то накидать сама, но оно криво работает
void search(vector<RealtorOffice> &v,vector<RealtorOffice> &result, int num_of_room)
{
for(RealtorOffice &x : v)
{
if(x.NumberOfRooms == num_of_room)
{
result.push_back(x);
}
}
}
Помогите кто чем может) на крайняк видео, ресурсы, большое спасибо (про оплошности кода знаю, только новичок)