Created
February 28, 2017 16:32
-
-
Save bilinin/b2b0e85bb1562701451d089ce306b2e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Product{ | |
public: | |
// Конструктор | |
Product(string Name, string Manufacturer, int Price, int ExpirationDate, int Amount){ | |
set_name(Name); | |
set_manufacturer(Manufacturer); | |
set_price(Price); | |
set_expirationDate(ExpirationDate); | |
set_amount(Amount); | |
} | |
// Сеттеры | |
void set_name(string name){ | |
Name = name; | |
} | |
void set_manufacturer(string manufacturer){ | |
Manufacturer = manufacturer; | |
} | |
void set_price(int price){ | |
Price = price; | |
} | |
void set_expirationDate(int expiration_date){ | |
ExpirationDate = expiration_date; | |
} | |
void set_amount(int amount){ | |
Amount = amount; | |
} | |
// Геттеры | |
string get_name(){ | |
return Name; | |
} | |
string set_manufacturer(){ | |
return Manufacturer; | |
} | |
int get_price(){ | |
return Price; | |
} | |
int get_expirationDate(){ | |
return ExpirationDate; | |
} | |
int get_amount(){ | |
return Amount; | |
} | |
// other | |
void print_all_data(){ | |
cout << Name << " " << Manufacturer << " " << Price << " " | |
<< " " << ExpirationDate << " " << Amount << endl; | |
} | |
private: | |
string Name, | |
Manufacturer; | |
int Price, | |
ExpirationDate, | |
Amount; | |
}; | |
void show_by_name(vector <Product> Products, string name){ | |
cout << "\n\n Products " << name << endl; | |
int size = Products.size(); | |
for (int i = 0;i<size; i++){ | |
if(Products[i].get_name() == name){ | |
Products[i].print_all_data(); | |
} | |
} | |
} | |
void show_by_name_price(vector <Product> Products, string name, int price){ | |
cout << "\n\n Products " << name << " and price less " << price << endl; | |
int size = Products.size(); | |
for (int i = 0;i<size; i++){ | |
if((Products[i].get_name() == name) && (Products[i].get_price() < price)){ | |
Products[i].print_all_data(); | |
} | |
} | |
} | |
void show_expirationDate(vector <Product> Products, int expirationDate){ | |
cout << "\n\n Products expirationDate more then " << expirationDate<< endl; | |
int size = Products.size(); | |
for (int i = 0;i<size; i++){ | |
if(Products[i].get_expirationDate() > expirationDate){ | |
Products[i].print_all_data(); | |
} | |
} | |
} | |
int main() { | |
vector <Product> Products; | |
Products.push_back(Product("Apple","AgroRussia",50,30,100)); | |
Products.push_back(Product("Apple","AgroChina",40,50,100)); | |
Products.push_back(Product("Apple","AgroKrasnodar",80,20,100)); | |
show_by_name(Products, "Apple"); | |
show_by_name_price(Products, "Apple", 60 ); | |
show_expirationDate(Products, 21); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment