Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * File: main.cpp
- * Author: BT
- *
- * Created on January 12, 2016, 7:57 PM
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <vector>
- using namespace std;
- class Product{
- protected:
- int prodId;
- string prodModel;
- string prodManuf;
- string prodDesc;
- int prodPrice;
- string prodType;
- public:
- Product(int id, string type, string model, string manuf, string desc, int price){
- this->prodId = id;
- this->prodModel = model;
- this->prodManuf = manuf;
- this->prodDesc = desc;
- this->prodPrice = price;
- this->prodType = type;
- }
- Product(){
- };
- int getProdId(){
- return prodId;
- }
- void setProdId(int newId){
- this->prodId = newId;
- }
- string getProdModel(){
- return prodModel;
- }
- void setProdModel(string newModel){
- this->prodModel = newModel;
- }
- string getProdManuf(){
- return prodManuf;
- }
- void setProdManuf(string newManuf){
- this->prodManuf = newManuf;
- }
- void setProdDesc(string newDesc){
- this->prodDesc = newDesc;
- }
- string getProdDesc(){
- return prodDesc;
- }
- int getProdPrice(){
- return prodPrice;
- }
- void setProdPrice(int prodPrice){
- this->prodPrice = prodPrice;
- }
- void setProdType(string prodType){
- this->prodType = prodType;
- }
- string getProdType(){
- return prodType;
- }
- };
- class Pc : public Product{
- private:
- int cpuSpeed;
- int ramCap;
- string discType;
- string graphCard;
- public:
- Pc(int prodId, string prodType, string prodModel, string prodManuf, string prodDesc, int prodPrice, int cpu, int ram, string disc, string graph) : Product (prodId, prodType, prodModel, prodManuf, prodDesc, prodPrice){
- this->cpuSpeed = cpu;
- this->ramCap = ram;
- this->discType= disc;
- this->graphCard = graph;
- }
- Pc(string totalDesc){
- Product();
- istringstream desc(totalDesc);
- vector<string> token;
- string word;
- while(getline(desc, word, ':')) {
- token.push_back(word);
- }
- stringstream(token[0]) >> this->prodId;
- this->prodType = token[1];
- this->prodModel = token[2];
- this->prodManuf = token[3];
- this->prodDesc = token[4];
- stringstream(token[5]) >> this->prodPrice;
- stringstream(token[6]) >> this->cpuSpeed;
- stringstream(token[7]) >> this->ramCap;
- this->discType = token[8];
- this->graphCard = token[9];
- }
- int getCpuSpeed(){
- return cpuSpeed;
- }
- void setCpuSpeed(int newSpeed){
- this->cpuSpeed = newSpeed;
- }
- int getRamCap(){
- return ramCap;
- }
- void setRamCap(int newCap){
- this->ramCap = newCap;
- }
- string getDiscType(){
- return discType;
- }
- void setDiscType(string newDisc){
- this->discType = newDisc;
- }
- string getGraphCard(){
- return graphCard;
- }
- void setGraphCard(string newCard){
- this->graphCard = newCard;
- }
- string toString() {
- stringstream sstm;
- sstm << prodId << ":" << prodType << ":" << prodModel << ":" << prodManuf << ":" << prodDesc << ":" << prodPrice << ":" << ramCap << ":" << cpuSpeed << ":" << discType << ":" << graphCard;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("products.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- };
- //void updatePcs(){
- // ifstream infile;
- // infile.open("products.dat");
- // string tok;
- // while(getline(infile, tok)){
- // pcs.emplace_back(tok);
- // }
- //}
- ////
- class SmartPhone : public Product{
- private:
- int screenInch;
- int batCap;
- int _4d;
- public:
- SmartPhone(int prodId, string prodType, string prodModel, string prodManuf, string prodDesc, int prodPrice, int cpu, int screenInch, int batCap, int _4d) : Product (prodId, prodType, prodModel, prodManuf, prodDesc, prodPrice){
- this->screenInch = screenInch;
- this->batCap = batCap;
- this->_4d= _4d;
- }
- SmartPhone(string totalDesc){
- Product();
- istringstream desc(totalDesc);
- vector<string> token;
- string word;
- while(getline(desc, word, ':')) {
- token.push_back(word);
- }
- stringstream(token[0]) >> this->prodId;
- this->prodType = token[1];
- this->prodModel = token[2];
- this->prodManuf = token[3];
- this->prodDesc = token[4];
- stringstream(token[5]) >> this->prodPrice;
- stringstream(token[6]) >> this->screenInch;
- stringstream(token[7]) >> this->batCap;
- stringstream(token[8]) >> this->_4d;
- }
- int getScreenInch(){
- return screenInch;
- }
- void setScreenInch(int screenInch){
- this->screenInch = screenInch;
- }
- int getBatCap(){
- return batCap;
- }
- void setBatCap(int batCap){
- this->batCap = batCap;
- }
- int get_4d(){
- return _4d;
- }
- set_4d(int _4d){
- this->_4d = _4d;
- }
- string toString() {
- stringstream sstm;
- sstm << prodId << ":" << prodType << ":" << prodModel << ":" << prodManuf << ":" << prodDesc << ":" << prodPrice << ":" << screenInch << ":" << batCap << ":" << _4d ;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("products.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- };
- class Tv : public Product{
- private:
- int screenInch;
- int _3d;
- public:
- Tv(int prodId, string prodType, string prodModel, string prodManuf, string prodDesc, int prodPrice, int screenInch, int _3d) : Product (prodId, prodType, prodModel, prodManuf, prodDesc, prodPrice){
- this->screenInch = screenInch;
- this->_3d= _3d;
- }
- Tv(string totalDesc){
- Product();
- istringstream desc(totalDesc);
- vector<string> token;
- string word;
- while(getline(desc, word, ':')) {
- token.push_back(word);
- }
- stringstream(token[0]) >> this->prodId;
- this->prodType = token[1];
- this->prodModel = token[2];
- this->prodManuf = token[3];
- this->prodDesc = token[4];
- stringstream(token[5]) >> this->prodPrice;
- stringstream(token[6]) >> this->screenInch;
- stringstream(token[7]) >> this->_3d;
- }
- int getScreenInch(){
- return screenInch;
- }
- void setScreenInch(int screenInch){
- this->screenInch = screenInch;
- }
- int get_3d(){
- return _3d;
- }
- void set_3d(int _3d){
- this->_3d = _3d;
- }
- string toString() {
- stringstream sstm;
- sstm << prodId << ":" << prodType << ":" << prodModel << ":" << prodManuf << ":" << prodDesc << ":" << prodPrice << ":" << screenInch << ":" << _3d ;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("products.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- };
- class User{
- protected:
- string username;
- string password;
- string accType;
- public:
- User(){
- }
- User(string username, string password, string acc){
- this->username = username;
- this->password = password;
- this->accType = acc;
- }
- User(string desc){
- Product();
- vector<string> token;
- string word;
- istringstream descr(desc);
- while(getline(descr, word, ':')) {
- token.push_back(word);
- }
- this->username = token[0];
- this->password = token[1];
- this->accType = "ADMIN";
- }
- void setPassword(string password){
- this->password = password;
- }
- void setUsername(string username){
- this->username = username;
- }
- void setAccType(string accType){
- this->accType = accType;
- }
- string getPassword(){
- return password;
- }
- string getUsername(){
- return username;
- }
- string getAccType(){
- return accType;
- }
- void appendToFile() {
- ofstream infile;
- infile.open("users.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- string toString() {
- stringstream sstm;
- sstm << username << ":" << password << ":" << accType;
- return sstm.str();
- }
- };
- class Customer: public User{
- protected:
- int afm;
- int phone;
- string adress;
- public:
- Customer(string username, string password, string type, int afm, int phone, string adress) : User(username, password, type){
- this->afm = afm;
- this->phone = phone;
- this->adress = adress;
- }
- Customer(){
- }
- void setAfm(int afm){
- this->afm = afm;
- }
- void setPhone(int phone){
- this->phone = phone;
- }
- void setAdress(string adress){
- this->adress = adress;
- }
- int getAfm(){
- return afm;
- }
- int getPhone(){
- return phone;
- }
- string getAdress(){
- return adress;
- }
- };
- class Person : public Customer{
- protected:
- string name;
- string surname;
- int idNum;
- public:
- Person(string username, string password, string type, int afm, int phone, string adress, string name, string surname, int idNum) : Customer(username, password, type, afm, phone, adress){
- this->accType = "CUSTOMER";
- this->name = name;
- this->surname = surname;
- this->idNum = idNum;
- }
- Person(string totalDesc){
- Customer();
- istringstream desc(totalDesc);
- vector<string> token;
- string word;
- while(getline(desc, word, ':')) {
- token.push_back(word);
- }
- this->username = token[0];
- this->password = token[1];
- this->accType = token[2];
- stringstream(token[3]) >> this->afm;
- stringstream(token[4]) >> this->phone;
- stringstream(token[5]) >> this->adress;
- this->name = token[6];
- this->surname = token[7];
- stringstream(token[8]) >> this->idNum;
- }
- void setName(string name){
- this->name = name;
- }
- void setSurname(string surname){
- this->surname = surname;
- }
- void setIdNum(int idNum){
- this->idNum = idNum;
- }
- string getName(){
- return name;
- }
- string getSurname(){
- return surname;
- }
- int getIdNum(){
- return idNum;
- }
- string toString() {
- stringstream sstm;
- sstm << username << ":" << password << ":" << accType << ":" << afm << ":" << phone << ":" << adress << ":" << name << ":" << surname << ":" << idNum;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("users.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- };
- class Company : public Customer{
- private:
- string name;
- string supName;
- string supSurname;
- int disc;
- int fax;
- public:
- Company(string username, string password, string type, int afm, int phone, string adress, string name, string supName, string supSuername, int disc, int fax) : Customer(username, password, type, afm, phone, adress){
- this->accType = "CUSTOMER";
- this->name = name;
- this->supName = supName;
- this->supSurname = supSurname;
- this->disc = disc;
- this->fax = fax;
- }
- Company(string totalDesc){
- Customer();
- istringstream desc(totalDesc);
- vector<string> token;
- string word;
- while(getline(desc, word, ':')) {
- token.push_back(word);
- }
- this->username = token[0];
- this->password = token[1];
- this->accType = token[2];
- stringstream(token[3]) >> this->afm;
- stringstream(token[4]) >> this->phone;
- stringstream(token[5]) >> this->adress;
- this->name = token[6];
- this->supName = token[7];
- this->supSurname = token[8];
- stringstream(token[9]) >> this->disc;
- stringstream(token[10]) >> this->fax;
- }
- void setName(string name){
- this->name = name;
- }
- void setSupName(string supName){
- this->supName; supName;
- }
- void setSupSurname(string supSurname){
- this->supSurname = supSurname;
- }
- void setDisc(int disc){
- this->disc = disc;
- }
- void setFax(int fax){
- this->fax = fax;
- }
- string getName(){
- return name;
- }
- string getSupName(){
- return supName;
- }
- string getSupSurname(){
- return supSurname;
- }
- int getFax(){
- return fax;
- }
- int getDisc(){
- return disc;
- }
- string toString() {
- stringstream sstm;
- sstm << username << ":" << password << ":" << accType << ":" << afm << ":" << phone << ":" << adress << ":" << name << ":" << supName << ":" << supSurname << ":" << disc << ":" <<fax;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("users.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl;
- infile.close();
- }
- };
- class CartItem{
- private:
- string ownerUsername;
- string cartProduct;
- string productAmount;
- public:
- CartItem(string name, string cartProduct, string productAmount){
- this->ownerUsername = name;
- this->cartProduct = cartProduct;
- this->productAmount = productAmount;
- }
- CartItem(string desc){
- vector<string> token;
- string word;
- istringstream descr(desc), sstm;
- while(getline(descr, word, '-')) {
- token.push_back(word);
- }
- this->ownerUsername = token[0];
- this->cartProduct = token[1];
- this->productAmount = token[2];
- }
- void setOwnerUsername(string username){
- this->ownerUsername = username;
- }
- void setCartProduct(string product){
- this->cartProduct = product;
- }
- void setProductAmount(string amount){
- this->productAmount = amount;
- }
- string getCartProduct(){
- return cartProduct;
- }
- string getProductAmount(){
- return productAmount;
- }
- string getOwnerUsername(){
- return ownerUsername;
- }
- string toString(){
- stringstream sstm;
- sstm << ownerUsername << "-" << cartProduct << "-" << productAmount;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("carts.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl ;
- infile.close();
- }
- };
- class Order{
- private:
- string ownerUsername;
- string cartProduct;
- string productAmount;
- string orderComplete;
- public:
- Order(string name, string cartProduct, string productAmount, string complete){
- this->ownerUsername = name;
- this->cartProduct = cartProduct;
- this->productAmount = productAmount;
- this->orderComplete = complete;
- }
- Order(CartItem item){
- this->ownerUsername = item.getOwnerUsername();
- this->productAmount = item.getProductAmount();
- this->cartProduct = item.getCartProduct();
- this->orderComplete = "PENDING";
- }
- Order(string desc){
- vector<string> token;
- string word;
- istringstream descr(desc), sstm;
- while(getline(descr, word, '-')) {
- token.push_back(word);
- }
- this->ownerUsername = token[0];
- this->cartProduct = token[1];
- this->productAmount = token[2];
- this->orderComplete = token[3];
- }
- void setOwnerUsername(string username){
- this->ownerUsername = username;
- }
- void setCartProduct(string product){
- this->cartProduct = product;
- }
- void setProductAmount(string amount){
- this->productAmount = amount;
- }
- void setOrderComplete(string complete){
- this->orderComplete = complete;
- }
- string getCartProduct(){
- return cartProduct;
- }
- string getProductAmount(){
- return productAmount;
- }
- string getOwnerUsername(){
- return ownerUsername;
- }
- string getOrderComplete(){
- return orderComplete;
- }
- string toString(){
- stringstream sstm;
- sstm << ownerUsername << "-" << cartProduct << "-" << productAmount << "-" << orderComplete;
- return sstm.str();
- }
- void appendToFile() {
- ofstream infile;
- infile.open("orders.dat", std::ios_base::app | std::ios_base::out);
- infile << this->toString() << endl ;
- infile.close();
- }
- };
- vector<Pc> pcs;
- vector<SmartPhone> smartPhones;
- vector<Tv> tvs;
- vector<Person> persons;
- vector<Company> companies;
- vector<User> admins;
- vector<CartItem> cartItems;
- vector<Order> orders;
- string getType(string desc,int choice){
- string word;
- vector<string> resVec;
- istringstream descr(desc);
- while (getline(descr, word, ':')) {
- resVec.push_back(word);
- }
- word = resVec[choice];
- return word;
- }
- vector<string> splitLine(string desc, char ch){
- stringstream locos(desc);
- string word;
- vector<string> words;
- while(getline(locos,word, ch)){
- words.push_back(word);
- }
- return words;
- }
- void storeData(){
- remove("carts.dat");
- for(CartItem c : cartItems){
- c.appendToFile();
- }
- remove("products.dat");
- for(Pc p : pcs){
- p.appendToFile();
- }
- for(SmartPhone t : smartPhones){
- t.appendToFile();
- }
- for(Tv t : tvs){
- t.appendToFile();
- }
- remove("users.dat");
- for(Company c : companies){
- c.appendToFile();
- }
- for(Person p : persons){
- p.appendToFile();
- }
- for(User a : admins){
- a.appendToFile();
- }
- remove("orders.dat");
- for(Order o : orders){
- o.appendToFile();
- }
- }
- void updateData(){
- ifstream file; //
- file.open("products.dat");
- string line;
- string type;
- while(getline(file, line)){
- type = getType(line,1);
- if(type == "PC"){
- pcs.push_back(Pc(line));
- }
- if(type == "SMARTPHONE"){
- smartPhones.push_back(SmartPhone(line));
- }
- if(type == "TV"){
- tvs.push_back(Tv(line));
- }
- }
- file.close();
- ifstream file2;
- file2.open("users.dat");
- while(getline(file2, line)){
- type=getType(line,2);
- if(type=="PERSON"){
- persons.push_back(Person(line));
- }
- if(type=="COMPANY"){
- companies.push_back(Company(line));
- }
- if(type=="ADMIN"){
- admins.push_back(User(line));
- }
- }
- file2.close();
- ifstream file3;
- file3.open("carts.dat");
- while(getline(file3, line)){
- vector<string> items;
- items = splitLine(line,'-');
- cartItems.push_back(CartItem(items[0],items[1],items[2]));
- }
- file3.close();
- ifstream file4;
- file4.open("orders.dat");
- while(getline(file4, line)){
- vector<string> items;
- items = splitLine(line,'-');
- orders.push_back(Order(items[0],items[1],items[2],items[3]));
- }
- file4.close();
- cout << endl << "Data updated." << endl<< "Total objects loaded into vectors:" << endl << "Pcs: " << pcs.size() << endl << "Tvs: " << tvs.size() << endl << "SmartPhones: " << smartPhones.size() << endl << "Persons: " << persons.size() << endl << "Companies: " << companies.size() << endl << "Admins: " << admins.size() << endl << "Cart items: " << cartItems.size() << endl << "Orders: " << orders.size() << endl;
- }
- string userLogin(){
- string username,password;
- while(1){
- cout << endl << "Enter Username" << endl;
- cin >> username;
- cout << "Enter password" << endl;
- cin >> password;
- for(Person p : persons){
- if(p.getUsername() == username && p.getPassword() == password){
- cout << "Log in sucessful PERSON." << endl;
- return p.toString();
- }
- for(Company c : companies){
- if(c.getUsername() == username && c.getPassword() == password){
- cout << "Log in sucessful COMPANY." << endl;
- return c.toString();
- }
- }
- for(User a : admins){
- if(a.getUsername() == username && a.getPassword() == password){
- cout << "Log in sucessful ADMIN." << endl;
- return a.toString();
- }
- }
- }
- cout << endl << "Username and/or password does not correspond to any existing user." << endl << "If you have trouble connecting please contact the administrator." << endl;
- }
- }
- void printProducts(int sort){
- if(sort == 1){
- cout << "----------Catergory Printing----------" << endl;
- cout << "---Available PCs---" << endl << endl;
- for(Pc p : pcs){
- cout << "Product Id: " << p.getProdId() << endl << "Price: " << p.getProdPrice() << endl << "Product Model: " << p.getProdModel() << endl << "Product Manufacturer" << p.getProdManuf() << endl << "Product description: " << p.getProdDesc() << endl << "Cpu speed " << p.getCpuSpeed() << "Ghz" << endl << "Ram capacity: " << p.getRamCap() << endl << "Disc Type: " << p.getDiscType()<< endl << "Graphic Card: " << p.getGraphCard() << endl << endl ;
- }
- cout << "---Available SmartPhones---" << endl << endl;
- for(SmartPhone p : smartPhones){
- cout << "Product Id: " << p.getProdId() << endl << "Price: " << p.getProdPrice() << endl << "Product Model: " << p.getProdModel() << endl << "Product Manufacturer" << p.getProdManuf() << endl << "Product description: " << p.getProdDesc() << endl << "Screen Inches: " << p.getScreenInch() << endl << "Battery Mha" << p.getBatCap() << endl << "4d capable" << p.get_4d() << endl << endl;
- }
- cout << "---Available Tvs---" << endl << endl;
- for(Tv p : tvs){
- cout << "Product Id: " << p.getProdId() << endl << "Price: " << p.getProdPrice() << endl << "Product Model: " << p.getProdModel() << endl << "Product Manufacturer" << p.getProdManuf() << endl << "Product description: " << p.getProdDesc() << endl << "Screen Inches: " << p.getScreenInch() << endl << "3d capable" << p.get_3d() << endl << endl;
- }
- }
- }
- string prodString(string sid){
- int id;
- stringstream str(sid);
- str >> id;
- for(Pc p : pcs){
- if(p.getProdId() == id){
- return p.toString();
- }
- }
- for(SmartPhone p : smartPhones){
- if(p.getProdId() == id){
- return p.toString();
- }
- }
- for(Tv p : tvs){
- if(p.getProdId() == id){
- return p.toString();
- }
- }
- return "E";
- }
- void customerUi(Customer currUser){
- while(1){
- string id, amount, prodS, cho;
- cout << endl << "---Menu Options---" << endl << "Product browse (B)" << endl << "View cart (C)"<< endl << "Delete Cart product from cart(D)"<< endl << "Make order(O)" << endl << "View products ordered (V)" << endl << "Logout (L)" << endl << endl;
- cin >> cho;
- if(cho == "B" | cho == "b"){ // Sorting options - VIEW PRODS
- while(1){
- printProducts(1);
- cout << "If you would like to add a product to your cart, specify ID." << endl << "In order to go back menu, insert a dot" << endl;
- cin >> id;
- if(id!="."){
- prodS = prodString(id);
- if(prodS != "E"){
- cout << "Product selected: " << prodS << endl << "Please specify amount" << endl;
- cin >> amount;
- CartItem tor(currUser.getUsername(), prodS, amount);
- tor.appendToFile();
- updateData();
- cout << endl << "Product successfully added to cart, make a menu choice." << endl;
- break;
- }else{
- cout << endl << "Id provided does not correspond to existing product, make a menu choice.";
- break;
- }
- }else{
- cout << endl << "Exiting to main menu, make a menu choice" << endl;
- break;
- }
- }
- }else if(cho == "C" | cho == "c"){ //CART CHOICE
- vector<int> prodMatch;
- int i = 0;
- for(CartItem c : cartItems){
- if(c.getOwnerUsername() == currUser.getUsername()){
- cout << "-- Uniquea cart ID: " << i <<endl << " Info: " << c.getCartProduct() << endl << " Amount: " << c.getProductAmount()<< endl;
- prodMatch.push_back(i);
- }
- i++;
- }
- }else if(cho == "D" | cho == "d"){ // DELETE
- while(1){
- cout << endl << "Your cart cosists of the following products" << endl;
- cout << endl << "If you would like to delete a cart Item, please specify its unique cart ID" << endl << "Else hit . to go to main menu" << endl;
- int i = 0;
- vector<int> prodMatch;
- for(CartItem c : cartItems){
- if(c.getOwnerUsername() == currUser.getUsername()){
- cout << "-- Uniquea cart ID: " << i <<endl << " Info: " << c.getCartProduct() << endl << " Amount: " << c.getProductAmount()<< endl;
- prodMatch.push_back(i);
- }
- i++;
- }
- string cChoice;
- cin >> cChoice;
- if(cChoice != "."){
- stringstream tor(cChoice);
- int unId;
- tor >> unId;
- cartItems.erase(cartItems.begin() + unId);
- storeData();
- break;
- }
- }
- }else if(cho == "O" | cho == "o"){
- int i = 0;
- string cChoice;
- for(CartItem o : cartItems){
- if(o.getOwnerUsername() == currUser.getUsername()){
- cout << "--Unique order Id: " << i << endl << "Product info: " << o.getCartProduct() << endl << "Amount of order: " << o.getProductAmount() << endl;
- }
- i++;
- }
- cout << endl << "If you would like to order a cart product please specify its unique order Id" << endl;
- int orId;
- cin >> cChoice;
- stringstream tor(cChoice);
- tor >> orId;
- orders.push_back(cartItems[orId]);
- cartItems.erase(cartItems.begin() + orId);
- storeData();
- cout << "Order complete" << endl;
- }else if(cho == "v" || cho == "V"){
- for(Order o : orders){
- if(currUser.getUsername() == o.getOwnerUsername()){
- cout << "Product info: " << o.getCartProduct() << endl << "Product amount: " << o.getProductAmount() << endl << "Status: " << o.getOrderComplete() << endl;
- }
- }
- }else if (cho == "L" | cho == "l"){
- break;
- }
- }
- }
- void adminUi(){
- while(1){
- cout << endl << "---Menu options---" << endl << "Create new user (U)" << endl << "Print products (P)" << endl << "Add products to store (A)" << endl << "Delete products from store (D)" << endl << "Modify product (MP)" << endl << "Update order status (UO)" << endl << "Print clients (PC)" << endl << "Print all orders (PO)" << endl << "Calculate total income (CI)" << endl << "Log out (L)" << endl;
- string cho;
- cin >> cho;
- if(cho == "U" | cho == "u"){
- while(1){
- string choi, username, password, fax, phone, afm, adress, supName, supSurname, idNum, name, discAmount, surName, compName, type = "ADMIN";
- cout << endl << "Create new administrator (A)" << endl << "Create new Person (P)" << endl << "Create a new company (C)" << endl;
- cin >> choi;
- cout << "Enter username: " << endl;
- cin >> username;
- cout << "Enter password: " << endl;
- cin >> password;
- if(choi == "A" | choi == "a"){
- admins.push_back(User(username, password, type));
- storeData();
- break;
- }
- cout << "Enter phone number: " << endl;
- cin >> phone;
- cout << "Enter adress: " << endl;
- cin >> adress;
- cout << "Enter TAX ID: " << endl;
- cin >> afm;
- if(choi == "P" | choi == "p"){
- cout << "Enter person's name: " << endl;
- cin >> name;
- cout << "Enter surname: " << endl;
- cin >> surName;
- cout << "Enter id number: " << endl;
- cin >> idNum;
- type = "PERSON";
- stringstream make;
- make << username << ":" << password << ":PERSON:" << afm << ":" << phone << ":" << adress << ":" << name << ":" << surName << ":" << idNum;
- string tor = make.str();
- cout << tor << endl << endl;
- persons.push_back(Person(tor));
- storeData();
- break;
- }
- if(choi == "C" | choi == "c"){
- cout << "Enter company name: " << endl;
- cin >> compName;
- cout << "Enters company's supervisor name: " << endl;
- cin >> supName;
- cout << "Enter company's supervisor surname: " << endl;
- cin >> supSurname;
- cout << "Enter Fax number" << endl;
- cin >> fax;
- cout << "Enter amount of discount (%)" << endl;
- cin >> discAmount;
- stringstream make;
- make << username << ":" << password << ":COMPANY:" << afm << ":" << phone << ":" << adress << ":" << compName << ":" << supName << ":" << supSurname << ":" << discAmount << ":" << fax;
- string tor = make.str();
- companies.push_back(Company(tor));
- storeData();
- break;
- }
- }
- }else if(cho == "P" | cho == "p"){
- printProducts(1);
- }else if (cho == "A" | cho == "a"){
- while(1){
- string choi, id, price, manuf, desc, disc, card, model, screen, cpu, ram, bat, _4d, _3d;
- cout << "Add PC: (P)" << endl << "Add Smartphone (S)" << endl << "Add Tv (T)" << endl;
- cin >> choi;
- cout << "Enter product Id: " << endl;
- cin >> id;
- cout << "Enter product model: " << endl;
- cin >> model;
- cout << "Enter product manufacturer: " << endl;
- cin >> manuf;
- cout << "Enter product description: " << endl;
- cin >> desc;
- cout << "Enter product price: " << endl;
- cin >> price;
- if(choi == "s" | choi == "S"){
- cout << "Enter screen inches: " << endl;
- cin >> screen;
- cout << "Enter battery capability: " << endl;
- cin >> bat;
- cout << "Enter 4d capability: (0-1 only) : " << endl;
- cin >> _4d;
- stringstream make;
- make << id << ":SMARTPHONE:" << model << ":" << manuf << ":" << desc << ":" << price << ":" << screen << ":" << bat << ":" << _4d;
- string tor = make.str();
- smartPhones.push_back(SmartPhone(tor));
- storeData();
- cout << endl << "Smartphone added" << endl;
- break;
- }
- if(choi == "p" | choi == "P"){
- cout << "Enter cpu gHz: " << endl;
- cin >> cpu;
- cout << "Enter ram capability: " << endl;
- cin >> ram;
- cout << "Enter graphics card name: " << endl;
- cin >> card;
- cout << "Enter disc type: " << endl;
- cin >> disc;
- stringstream make;
- make << id << ":PC:" << model << ":" << manuf << ":" << desc << ":" << price << ":" << cpu << ":" << ram << ":" << disc << ":" << card;
- string tor = make.str();
- pcs.push_back(Pc(tor));
- storeData();
- cout << endl << "Pc added" << endl;
- break;
- }
- if(choi == "t" | choi == "T"){
- cout << "Enter screen inches: " << endl;
- cin >> screen;
- cout << "Enter 3d capability: " << endl;
- cin >> _3d;
- stringstream make;
- make << id << ":TV:" << model << ":" << manuf << ":" << desc << ":" << price << ":" << screen << ":" << _3d;
- string tor = make.str();
- tvs.push_back(Tv(tor));
- storeData();
- cout << endl << "Tv added" << endl;
- break;
- }
- }
- }
- if(cho == "D" | cho == "d"){
- while(1){
- printProducts(1);
- cout << "In order to delete an item specify its Id, else hit . to go back." << endl;
- string cChoi;
- cin >> cChoi;
- int unId;
- stringstream tor(cChoi);
- tor >> unId;
- int i = 0;
- for(Pc p : pcs){
- if(p.getProdId() == unId){
- pcs.erase(pcs.begin() + i);
- storeData();
- cout << "Item deleted sucessfully" << endl;
- break;
- }
- i++;
- }
- i = 0;
- for(Tv p : tvs){
- if(p.getProdId() == unId){
- tvs.erase(tvs.begin() + i);
- storeData();
- cout << "Item deleted sucessfully" << endl;
- break;
- }
- i++;
- }
- i = 0;
- for(SmartPhone p : smartPhones){
- if(p.getProdId() == unId){
- smartPhones.erase(smartPhones.begin() + i);
- storeData();
- cout << "Item deleted sucessfully" << endl;
- break;
- }
- i++;
- }
- if(cChoi == "."){
- cout << "Returning to main menu" << endl;
- break;
- }
- cout << "Id does not correspond to existing item, please re-try." << endl;
- }
- }
- else if(cho == "MP" | cho == "mp"){
- printProducts(1);
- cout << "Enter the Id of the product you would wish to modify: " << endl;
- string choi;
- cin >> choi;
- int id;
- stringstream tor(choi);
- tor >> id;
- for(Pc p : pcs){
- if(p.getProdId() == id){
- cout << "Modify id (I)" << endl << "Modify Model (M)" << endl << "Modify description (D)" << endl << "Modify price" << endl << "Modify manufacturer (MM)" << endl << "Modify Cpu ghz (C)" << endl << "Modify ram capability (R)" << endl << "Modify disc type (DI)" << endl << "Modify graphic hard (G)" << endl; ;
- string choi2,mv;
- cin >> choi2;
- }
- }
- }else if(cho == "uo" | cho == "UO"){
- int i = 0;
- for(Order o : orders){
- cout << "Order no: " << i << endl << "Owner :" << o.getOwnerUsername() << endl << "Product information :" << o.getCartProduct() << endl << "Product amount: " << o.getProductAmount() << endl << "Order status: " << o.getOrderComplete() << endl << "-- " << endl;
- i++;
- }
- cout << "Enter order no id to modify status (COMPLETE/PENDING/SENT)" << endl;
- string choi,sta;
- cin >> choi;
- stringstream tor(choi);
- tor >> i;
- if(i < orders.size() && i >= 0){
- cout << endl << "Status: " << endl;
- cin >> sta;
- orders[i].setOrderComplete(sta);
- storeData();
- }else{
- cout << "No such existing order number, back to main menu." << endl;
- }
- }else if(cho == "pc" | cho == "PC"){
- cout << "---Priting persons---" << endl;
- for(Person p : persons){
- cout << endl << "Username: " << p.getUsername() << endl << "Password: " << p.getPassword() << endl << "Name: " << p.getName() << endl << "Surname: " << p.getSurname() << endl;
- }
- cout << "---Priting companies---" << endl;
- for(Company p : companies){
- cout << endl << "Username: " << p.getUsername() << endl << "Password: " << p.getPassword() << endl << "Company name: " << p.getName() << endl << "Supervisor name: " << p.getSupName() << endl << "Discount amount" << p.getDisc() << endl;
- }
- }else if(cho == "po" | cho == "PO"){
- for(Order o : orders){
- cout << endl << "Order owner: " << o.getOwnerUsername() << endl << "Order product: " << o.getCartProduct() << endl << "Order status: " << o.getOrderComplete() << endl;
- }
- }else if(cho == "ci" | cho == "CI"){
- float income = 0;
- for(Order o : orders){
- vector<string> amounts, items, items2, prices;
- items = splitLine(o.toString(), '-');
- amounts.push_back(items[2]);
- cout << items[2] << endl;
- items2 = splitLine(o.toString(), ':');
- prices.push_back(items2[4]);
- cout << items2[5] << endl;
- stringstream am(items[2]), pr(items2[5]);
- float pri,ams;
- am >> ams;
- pr >> pri;
- income += pri*ams;
- }
- cout << endl << "Total income: " << income << endl;
- }else if(cho == "L" | cho == "l"){
- cout << "Loging out" << endl;
- break;
- }
- }
- }
- int main() {
- while(1){
- updateData();
- string userIn = userLogin();
- cout << "Loged in as: " << userIn << endl;
- if(getType(userIn,2) == "PERSON"){
- Person currUser(userIn);
- customerUi(currUser);
- }else if(getType(userIn,2) == "COMPANY"){
- Company currUser(userIn);
- }else{
- User currUser(userIn);
- adminUi();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement