Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- //#include "cml6895_Auto_Part.h"
- #include "cml6895_Inventory.h"
- #include <iostream>
- #include <vector>
- int main()
- {
- std::vector<Auto_Part> parts;
- Inventory inventory;
- int num_parts;
- std::cout << "How many parts do you wish to create?" << std::endl;
- std::cin >> num_parts;
- for(int i = 0; i < num_parts; i++)
- {
- std::string type;
- std::string name;
- int part_number, amount;
- double price;
- std::cout << "Enter type of part: ";
- std::cin >> type;
- std::cout << "Enter name of part: ";
- std::cin >> name;
- std::cout <<"Enter part number: ";
- std::cin >> part_number;
- std::cout <<"Enter price: ";
- std::cin >> price;
- std::cout << "Enter how many are there in the inventory: ";
- std::cin >> amount;
- parts.push_back(Auto_Part(type, name, part_number, price));
- inventory.add_part(Auto_Part(type, name, part_number, price));
- }
- for(auto x : parts)
- {
- std::cout << x;
- }
- double sum = 0;
- for(Auto_Part part : parts)
- {
- sum += part.get_price();
- }
- std::cout << "Average: " << sum/parts.size() << std::endl;
- //std::cout << inventory.first << inventory.second << std::endl;
- /*
- std::map<Auto_Part::part, int>::iterator it = mymap.begin();
- for(it = inventory.begin(); it!= inventory.end(); ++it)
- {
- std::cout << it->first << it->second << std::endl;
- }
- */
- return 0;
- }
- ///auto_part.cpp
- #include "cml6895_Auto_Part.h"
- //#include "cml6895_Inventory.h"
- Auto_Part::Auto_Part()
- {
- type = "null";
- name = "null";
- part_number = 0;
- price = 0.0;
- }
- std::string Auto_Part::get_type() const
- {
- return type;
- }
- std::string Auto_Part::get_name() const
- {
- return name;
- }
- int Auto_Part::get_part_number() const
- {
- return part_number;
- }
- double Auto_Part::get_price() const
- {
- return price;
- }
- void Auto_Part::set_type(std::string t)
- {
- type = t;
- }
- void Auto_Part::set_name(std::string n)
- {
- name = n;
- }
- void Auto_Part::set_part_number(int pn)
- {
- part_number = pn;
- }
- void Auto_Part::set_price(double p)
- {
- price = p;
- }
- std::ostream& operator<<(std::ostream& ost, const Auto_Part& part)
- {
- ost << "Type: " << part.type << ", Name: " << part.name << ", Part Numer: " << part.part_number << ", Price: " << std::put_money(part.price) << std::endl;
- return ost;
- }
- bool Auto_Part::operator<(const Auto_Part& part_one)
- {
- if()
- {
- }
- return true;
- }
- //auto_part.h
- #include <string>
- #include <iomanip>
- #include <iostream>
- class Auto_Part
- {
- public:
- Auto_Part();
- Auto_Part(std::string t, std::string n, int pn, double p): type(t), name(n), part_number(pn), price(p) {};
- std::string get_type() const;
- std::string get_name() const;
- int get_part_number() const;
- double get_price() const;
- void set_type(std::string);
- void set_name(std::string);
- void set_part_number(int);
- void set_price(double);
- friend std::ostream& operator<<(std::ostream&, const Auto_Part&);
- bool operator<(const Auto_Part& rhs);
- private:
- std::string type;
- std::string name;
- int part_number;
- double price;
- };
- //inventory.cpp
- #include "cml6895_Inventory.h"
- //#include "cml6895_Auto_Part.h"
- #include <string>
- Inventory::Inventory() {}
- Inventory::Inventory(std::map<Auto_Part, int> inv)
- {
- inventory = inv;
- }
- bool Inventory::add_part(Auto_Part p)
- {
- int i;
- std::pair<Auto_Part, int> temp1(p, 1);
- if(inventory.count(p) > 1)
- {
- inventory.second ++;
- return inventory.insert(std::pair<Auto_Part, int>(p, i++)).second;
- }
- else
- {
- return inventory.insert(std::pair<Auto_Part, int>(p, 1)).second;
- }
- }
- void Inventory::add_parts(Auto_Part, int number)
- {
- }
- int Inventory::get_num_parts(Auto_Part)
- {
- }
- void Inventory::remove_part(Auto_Part)
- {
- }
- void Inventory::remove_parts(Auto_Part, int number)
- {
- }
- std::ostream& operator << (std::ostream& ost, const Auto_Part& part)
- {
- ost << "Type: " << part.type << ", Name: " << part.name << ", Part Numer: " << part.part_number << ", Price: " << std::put_money(part.price) << std::endl;
- return ost;
- }
- //inventory.h
- #include "cml6895_Auto_Part.h"
- #include <iomanip>
- #include <map>
- //#include <typeindex>
- class Inventory
- {
- public:
- Inventory();
- Inventory(std::map<Auto_Part, int>);
- bool add_part(Auto_Part);
- void add_parts(Auto_Part, int);
- int get_num_parts(Auto_Part);
- void remove_part(Auto_Part);
- void remove_parts(Auto_Part, int);
- friend std::ostream& operator<<(std::ostream&, const Auto_Part&);
- private:
- std::map<Auto_Part, int> inventory;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement