Задание: В контейнере типа vector хранятся елки(поля: высота, цена).Необходимо разработать программу для : 1. Поиск минимального значения(по высоте, цене) 2. Поиск максимального значения 3. Сортировка данных по убыванию 4. Сортировка данных по возрастанию 5. Увеличение значений в контейнере на заданную константу 6. Уменьшение значений в контейнере на заданную константу 7. Удаление элементов из контейнера равных искомому значению
class tree
{
private:
float height;
float price;
public:
tree(float height, float price) : height(height), price(price){}
float getHeight()
{
return height;
}
float getPrice()
{
return price;
}
};
int main()
{
vector<tree> _tree;
vector<tree>::iterator it;
it = _tree.begin();
float height;
float price;
while (true)
{
system("cls");
cout << "MENU" << endl << endl;
cout << "1 - add tree" << endl;
cout << "2 - find the minimum value" << endl;
cout << "3 - find the maximum value" << endl;
cout << "4 - sort data in descending order" << endl;
cout << "5 - sort data in ascending order" << endl;
cout << "6 - increase the values in the container by a given constant" << endl;
cout << "7 - decrease values in the container by a given constant" << endl;
cout << "8 - removing items from the container equal to the desired value" << endl;
cout << "9 - exit" << endl << endl;
cout << "Enter: ";
int menu;
cin >> menu;
switch (menu)
{
case 1:
{
system("cls");
cout << "Enter height: ";
cin >> height;
cout << "Enter price: ";
cin >> price;
tree t(height,price);
_tree.push_back(t);
Sleep(500 * 1);
break;
}
case 2:
{
system("cls");
Sleep(1000 * 1);
break;
}
}
}
system("cls");
return 0;
}
Как мне через vector достучаться к полям класса, что бы с ними работать ?
tree. Типаtree_[i].getPrice(). В чем проблема? А все сортировки - просто пишете свой компаратор.. – Harry Jan 10 '20 at 09:57