I
I
igoodmood2016-10-08 16:37:34
Programming
igoodmood, 2016-10-08 16:37:34

How to properly organize the structure in the class?

Hello! You need to create a program that will serve as a cash register emulator. As I understand it, you need to use the structure. But since I'm learning OOP, this needs to be done in class. I tried to implement it in different ways, creating pointers and the like, but there was no success. There is also very little information on the Internet on this topic. Therefore, I am writing here in order to understand the implementation.
Here is the error itself:
6022b3d3995145889af54b0c578cb122.PNG
Here is the code at the moment : (this is the check.h file)

#pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class check
{
public:
  void create(double *&numbers, string name_goods, double prises, int numbers_of_once)
  {
    numbers = new double[n];
    int p = 0;
    for (int i = 1; i <= n; i++)
    {
      while (p != n)
      {
        int g = 0;
        cout << "1 - Milk, 2 - Potatoes, 3 - Chocolate, 4 - Sugar, 5 - Bread, 6 - Water, 7 -  Magazine" << endl;
        cout << "Enter" << i << "product of list:";
        cin >> g;
        switch (g)
        {
        case 1:
          numbers[i].name_goods;
          break;
    
        default:
          cout << "Enter the number from 1 to 7!" << endl;
          break;
        }
      }
    }
  }
private:
  int n = 5;
  struct Check
  {
    string name_goods;
    double prises;
    int numbers_of_once;
  };
};
Так же есть файл .срр, но там только подключенные директивы и пространство имен, не считая названия класса и его объекта. Очень надеюсь на Вашу помощь)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mercury13, 2016-10-08
@igoodmood

Apart from what I have written…
1. How to arrange the data?

struct CheckLine {
public:
   int itemCode;    // код товара
   int qty;         // количество
   int price;       // цена, по которой всё это продано в копейках
   const CheckLine* next() const { return _next; }
private:
   friend class Check;   // я тут ошибся с const-корректностью и заconst’ив всё, что можно, не дал Check’у писать
   CheckLine* _next;
}

class Check {
public:
    Check() : _firstLine(NULL), _lastLine(NULL) {}
    void addLine(int itemCode, int qty, int price);   // пиши реализацию сам.
    const CheckLine* firstLine() const { return _firstLine; }
    ~Check();  // не забудь про деструктор…
    Check(const Check&)  // …конструктор копирования…
    Check& operator = (const Check&);  // и операцию «присвоить».
private:
    CheckLine *_firstLine, *_lastLine;
}

In general, for simplicity (we still don’t know what a vector is), I set up storing data in a linked list.
2. In the inner kitchen of the class, you access the console. What for? This is usually done as close to main as possible.
I'll be back and I'll keep writing.

A
abcd0x00, 2016-10-09
@abcd0x00

You need to create a program that will serve as a cash register emulator.

You must first describe the external component of this apparatus.
Type
начать работу
нажать кнопку один
нажать кнопку два
повернуть ручку такую-то
повернуть ручку другую-то
показать на экране текущее состояние
кончить работу

This is the external description of the device.
This is what your class should implement - to be such a box with methods. But inside you already store some data entered into the device or received by it inside when calling methods from outside.
The entered products are added to the list of products, which is hidden from the outside observer, but which is visible inside the device. All control of the device occurs through its external methods (via the interface).

C
chichackles, 2017-11-26
@chichackles

On the main question: Why? A structure within a class is an additional level of nesting. What is the meaning of it. From the point of view of the data, the class itself is actually a structure. Write structure fields as class fields and that's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question