-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mini_HW_3_MoshchanetskayaMaria #240
Open
Luckymilkk
wants to merge
3
commits into
itmogamedev:master
Choose a base branch
from
Luckymilkk:mini_HW3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Shop Ostin | ||
Items 5 | ||
T-short 700 50 cotton | ||
sweater 1200 150 wool | ||
jacket 1500 100 denim | ||
skirt 500 70 leather | ||
shirt 600 cotton | ||
Shop Gorzdrav | ||
Items 5 | ||
coldrex 800 40 internal | ||
bandage 120 30 external | ||
thermometer 150 20 internal | ||
noshpa 750 60 external | ||
ingavirin 830 80 external | ||
Shop Leonardo | ||
Items 6 | ||
pencil 50 15 green | ||
pen 60 20 blue | ||
notebook 350 200 pink | ||
artbook 1300 600 orange | ||
sketchbook 450 320 gray | ||
erase 50 10 white | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
/*#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <fstream> | ||
#include <sstream> | ||
|
||
class Item | ||
{ | ||
public: | ||
std::string name; | ||
int cost; | ||
int weight; | ||
|
||
Item(std::string name, int cost, int weight): name(name), cost(cost),weight(weight){} | ||
}; | ||
|
||
class Shop | ||
{ | ||
public: | ||
std::vector<Item*> items; | ||
std::string shop_name; | ||
//float average_cost; | ||
//float average_weight; | ||
|
||
void AddItem(Item* item) | ||
{ | ||
items.push_back(item); | ||
} | ||
|
||
float averagePrice() { | ||
float total = 0; | ||
for (auto& item : items) { | ||
total += item->cost; | ||
} | ||
return items.empty() ? 0 : total / items.size(); | ||
} | ||
|
||
float averageWeight() { | ||
float total = 0; | ||
for (auto& item : items) { | ||
total += item->weight; | ||
} | ||
return items.empty() ? 0 : total / items.size(); | ||
} | ||
}; | ||
|
||
class ClothesItem : public Item | ||
{ | ||
public: | ||
std::string material; | ||
ClothesItem(std::string name, int cost, int weight,std::string material):Item(name, cost, weight), material(material) {} | ||
}; | ||
|
||
class MedicineItem : public Item | ||
{ | ||
public: | ||
std::string application; | ||
MedicineItem(std::string name, int cost, int weight, std::string application):Item(name, cost, weight), application(application) {} | ||
}; | ||
|
||
class ArtItem : public Item | ||
{ | ||
public: | ||
std::string colour; | ||
ArtItem(std::string name, int cost, int weight, std::string colour) :Item(name, cost, weight), colour(colour) {} | ||
}; | ||
|
||
void Show_list_of_shops() | ||
{ | ||
|
||
} | ||
|
||
int main() | ||
{ | ||
std::ifstream file("List of shops.txt", std::ios::app); // эта часть выводит записи из файла, ее надо применять только при соответствующей команде | ||
std::string line; | ||
std::vector<Shop> shops; | ||
while (std::getline(file, line)) | ||
{ | ||
if (line.find("Shop") != std::string::npos) | ||
{ | ||
std::string shop_name = line.substr(5); | ||
shops.emplace_back(shop_name); | ||
} | ||
else if (line.find("Items") != std::string::npos) | ||
{ | ||
int numb_of_products; | ||
std::istringstream(line.substr(6)) >> numb_of_products; | ||
for (int i = 0; i < numb_of_products; ++i) | ||
{ | ||
std::stringstream iss(line); | ||
std::string item_name; | ||
int cost, weight; | ||
if (shops.back().shop_name == "Ostin") | ||
{ | ||
std::string material; | ||
iss >> material; | ||
ClothesItem* clothesItem = new ClothesItem(item_name, cost, weight, material); | ||
shops.back().AddItem(clothesItem); | ||
} | ||
else if (shops.back().shop_name == "Gorzdrav") | ||
{ | ||
std::string application; | ||
iss >> application; | ||
MedicineItem* medItem = new MedicineItem(item_name, cost, weight, application); | ||
shops.back().AddItem(medItem); | ||
} | ||
else if (shops.back().shop_name == "Leonardo") | ||
{ | ||
std::string colour; | ||
iss >> colour; | ||
ArtItem* artItem = new ArtItem(item_name, cost, weight, colour); | ||
shops.back().AddItem(artItem); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
for (auto& shop : shops) | ||
{ | ||
std::cout << "Shop: " << shop.shop_name << std::endl; | ||
std::cout << "Average Price: " << shop.averagePrice() << std::endl; | ||
std::cout << "Average Weight: " << shop.averageWeight() << std::endl; | ||
std::cout << std::endl; | ||
} | ||
|
||
file.close(); | ||
}*/ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <memory> // Для использования умных указателей | ||
|
||
class Item | ||
{ | ||
public: | ||
std::string name; | ||
int cost; | ||
int weight; | ||
|
||
Item(std::string name, int cost, int weight) : name(name), cost(cost), weight(weight) {} | ||
}; | ||
|
||
class Shop | ||
{ | ||
public: | ||
std::vector<std::shared_ptr<Item>> items; // Используем shared_ptr для управления памятью | ||
std::string shop_name; | ||
|
||
Shop(std::string name) : shop_name(name) {} // Конструктор для инициализации имени магазина | ||
|
||
void AddItem(std::shared_ptr<Item> item) | ||
{ | ||
items.push_back(item); | ||
} | ||
|
||
float averagePrice() { | ||
float total = 0; | ||
for (const auto& item : items) { | ||
total += item->cost; | ||
} | ||
return items.empty() ? 0 : total / items.size(); | ||
} | ||
|
||
float averageWeight() { | ||
float total = 0; | ||
for (const auto& item : items) { | ||
total += item->weight; | ||
} | ||
return items.empty() ? 0 : total / items.size(); | ||
} | ||
}; | ||
|
||
class ClothesItem : public Item | ||
{ | ||
public: | ||
std::string material; | ||
ClothesItem(std::string name, int cost, int weight, std::string material) : Item(name, cost, weight), material(material) {} | ||
}; | ||
|
||
class MedicineItem : public Item | ||
{ | ||
public: | ||
std::string application; | ||
MedicineItem(std::string name, int cost, int weight, std::string application) : Item(name, cost, weight), application(application) {} | ||
}; | ||
|
||
class ArtItem : public Item | ||
{ | ||
public: | ||
std::string colour; | ||
ArtItem(std::string name, int cost, int weight, std::string colour) : Item(name, cost, weight), colour(colour) {} | ||
}; | ||
|
||
int main() | ||
{ | ||
std::ifstream file("List of shops.txt"); | ||
std::string line; | ||
std::vector<Shop> shops; | ||
|
||
while (std::getline(file, line)) | ||
{ | ||
if (line.find("Shop") != std::string::npos) | ||
{ | ||
std::string shop_name = line.substr(5); | ||
shops.emplace_back(shop_name); | ||
} | ||
else if (line.find("Items") != std::string::npos) | ||
{ | ||
int numb_of_products; | ||
std::istringstream(line.substr(6)) >> numb_of_products; | ||
for (int i = 0; i < numb_of_products; ++i) | ||
{ | ||
std::string item_name; | ||
int cost, weight; | ||
std::string additional_info; | ||
|
||
// Чтение следующей строки для получения информации о товаре | ||
std::getline(file, line); | ||
std::istringstream iss(line); | ||
iss >> item_name >> cost >> weight >> additional_info; | ||
|
||
if (shops.back().shop_name == "Ostin") | ||
{ | ||
auto clothesItem = std::make_shared<ClothesItem>(item_name, cost, weight, additional_info); | ||
shops.back().AddItem(clothesItem); | ||
} | ||
else if (shops.back().shop_name == "Gorzdrav") | ||
{ | ||
auto medItem = std::make_shared<MedicineItem>(item_name, cost, weight, additional_info); | ||
shops.back().AddItem(medItem); | ||
} | ||
else if (shops.back().shop_name == "Leonardo") | ||
{ | ||
auto artItem = std::make_shared<ArtItem>(item_name, cost, weight, additional_info); | ||
shops.back().AddItem(artItem); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const auto& shop : shops) | ||
{ | ||
std::cout << "Shop:" << shop.shop_name << std::endl; | ||
std::cout << "Average Price: " << shop.averagePrice() << std::endl; | ||
std::cout << "Average Weight: " << shop.averageWeight() << std::endl; | ||
std::cout << std::endl; | ||
} | ||
|
||
file.close(); | ||
return 0; // Возвращаем 0, чтобы указать, что программа завершилась успешно | ||
} | ||
|
||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем тут закоментированный код?