0

table.h

#pragma once
#include <iostream>
#include <string>
using namespace std;
class table
{
protected:
    double price;
    bool presense = true;
public:
    double getPrice();
virtual double add_dish() = 0;
virtual ~table() = default;
void setPresense(bool v);

};

table.cpp

#include "table.h"

double table::getPrice() { return price; }

void table::setPresense(bool v) { presense = v; }

dish.h

#pragma once
#include "table.h"
using namespace std;
class dish:public table
{
protected:
    table* ptr = nullptr;
public:
    double add_dish()override;
dish(table* _ptr);
~dish();

};

dish.cpp

#include "dish.h"

double dish::add_dish() { return price; }

dish::dish(table* _ptr) { ptr = _ptr;

}

dish::~dish() { delete[] ptr; }

order.h

#pragma once
#include "table.h"
using namespace std;
class order:public table
{
public:
     double add_dish()override;

};

order.cpp

#include "order.h"

double order::add_dish() { return 0; }

coffee.h

#pragma once
#include "dish.h"
using namespace std;
class coffee:public dish
{
    bool presense = true;
    double price = 1.5;
public:
     double add_dish()override;
    coffee(table* v);
};

coffee.cpp

#include "coffee.h"

double coffee::add_dish() { if (presense == false) { cout << "Stop list" << endl; return ptr->add_dish() + 0; } cout << "Coffe "<<price << endl; return ptr->add_dish()+price; }

double coffee::dell_dish() { return ptr->dell_dish() ; }

coffee::coffee(table* v):dish(v) { }

latte.h

#pragma once
#include "dish.h"
using namespace std;
class latte:public dish
{
    bool presense = true;
double price = 1.2;

public: double add_dish()override; latte(table* v); };

latte.cpp

#include "latte.h"

double latte::add_dish() { if (presense == false) { cout << "Stop list" << endl; return ptr->add_dish() + 0; } cout << "Latte "<<price << endl; return ptr->add_dish() + price; } latte::latte(table* v):dish(v) { }

discount.h

#pragma once
#include "dish.h"
class discount :public dish
{
    const bool presense = true;
double price =0.9;

public: double add_dish()override; discount(table* v); };

discount.cpp

#include "discount.h"

double discount::add_dish() { if (presense == false) { cout << "Stop list" << endl; return ptr->add_dish() + 0; }

return ptr-&gt;add_dish() *price;

}

discount::discount(table* v) :dish(v) {}

user.h

#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include "table.h"
#include "latte.h" //классы из паттерна "Декоратор"
#include "coffee.h"
#include "dish.h"
#include "order.h"
#include "discount.h"
#include <iostream>
#include <string>
#include<windows.h>
#include <ctime>
#include <fstream>
#include <vector>

using namespace std;

class user { protected: int right=0; //право, которое отвечает за определенные возможности персонала double salary;//заработанная сумма за смену
int id; string name; string surname; string patronymic; tm working; public:

user();
void print_u();
void new_table(vector &lt;table*&gt; &amp;t);
void setRight(int v);
void setSalary(double v);
void setId(int v);
int getId()const;
int getRight()const;
double getSalary()const;
void setName(string v);
void setSurname(string v);
void setPatroymic(string v);
string getName()const;
string getSurname()const;
string getPatronymic()const;
void open_shift();
void close_shift();
virtual ~user() = default;
virtual void add_order() = 0;

};

user.cpp

#include "user.h"

user::user() { name = "nothing"; right = 0; salary = 0; }

void user::print_u() { cout << "Name: " << name << endl; cout << "Surname: " << surname << endl; cout << "Patronymic: " << patronymic << endl; cout << "ID: " << id << endl; } void user::new_table(vector<table*> &t) {

t.push_back(new order());
int code=-1;
int i = 0;
while (code != 0)
{
    cout &lt;&lt; &quot;Enter the code of dish -&gt; &quot;;
    cin &gt;&gt; code;
    if (code == 1)
    {
        t.push_back(new latte(t[i]));

        i++;
    }
    if (code == 2)
    {
        t.push_back(new coffee(t[i]));
        i++;


    }
    if (code ==3)
    {
        t.push_back(new discount(t[i]));
        i++;
    }
}

} void user::setRight(int v) { right = v; }

void user::setSalary(double v) { salary = v; }

void user::setId(int v) { id = v; }

int user::getId() const { return id; }

int user::getRight() const { return right; }

double user::getSalary() const { return salary; }

void user::setName(string v) { name = v; }

void user::setSurname(string v) { surname = v; }

void user::setPatroymic(string v) { patronymic = v; }

string user::getName() const { return name; }

string user::getSurname() const { return surname; }

string user::getPatronymic() const { return patronymic; }

void user::open_shift() { time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime);

working.tm_sec = timeinfo-&gt;tm_sec;
working.tm_min = timeinfo-&gt;tm_min;
working.tm_hour = timeinfo-&gt;tm_hour;

}

void user::close_shift() { time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); string buf; buf = surname + " " + name + " " + patronymic + ".txt"; fstream fs; string h; double s = 0; fs.open(buf, ios::in); while (!fs.eof()) { getline(fs, h);

    s = atof(h.c_str());
    cout &lt;&lt; s &lt;&lt; endl;
    cout &lt;&lt; h &lt;&lt; endl;
}
fs.close();
fs.open(buf, ios::out);
working.tm_sec = timeinfo-&gt;tm_sec - working.tm_sec;
working.tm_min = timeinfo-&gt;tm_min - working.tm_min;
working.tm_hour = timeinfo-&gt;tm_hour - working.tm_hour;
if (working.tm_sec &lt; 0)
{
    working.tm_min--;
    working.tm_sec = 60 + working.tm_sec;


}
if (working.tm_min &lt; 0)
{
    working.tm_hour--;
    working.tm_min = 60 + working.tm_min;
}
if (working.tm_hour &gt; 14)
{
    working.tm_sec = 0;
    working.tm_min = 0;
    working.tm_hour = 0;
}

s= s +salary * (working.tm_sec + working.tm_min * 60 + working.tm_hour * 3600);
cout &lt;&lt; s;
fs &lt;&lt; s;
fs.close();

}

waiter.h

#pragma once
#include "user.h"
class waiter:public user
{
  public:
     waiter();
 void add_order() override;

};

waiter.cpp

#include "waiter.h"

waiter::waiter(): user() { right = 2; }

void waiter::add_order() { cout << " "; }

Source

#include "user.h"
#include "waiter.h"

using namespace std; int main() { waiter a; vector <table*> tables; a.new_table(tables); cout << tables[tables.size() - 1]->add_dish(); }

Скажите, пожалуйста, что мне нужно исправить, чтоб убрать ошибку: error LNK2019: unresolved external symbol "public: void __thiscall user::new_table(class std::vector<class table *,class std::allocator<class table *> > &)" (?new_table@user@@QAEXAAV?$vector@PAVtable@@V?$allocator@PAVtable@@@std@@@std@@@Z) referenced in function _main; Буду очень сильно благодарен, если поможете) И не закрывайте, пожалуйста, мой вопрос!

  • 1
    Посмотрите, что именно вы не сделали, в вопросе по ссылке. Наверное, user.cpp в проект не включили?\ – Harry Sep 30 '20 at 17:08
  • Когда подключаю .cpp выдает ошибку, что у функции уже есть тело. Я 3 дня смотрю, что не так. И все равно не могу понять, почему выдает ошибку. – Niki_012003 Sep 30 '20 at 17:14
  • Соберите минимальный пример - ваш же код компилировать не получится, куча всяких инклудов - а как, не компилируя, проверить, где вы ерунду написали... – Harry Sep 30 '20 at 17:31
  • Добавил все классы – Niki_012003 Sep 30 '20 at 18:10
  • 1
    "Все классы" != "минимальный". – HolyBlackCat Sep 30 '20 at 18:51

0 Answers0