Answer the question
In order to leave comments, you need to log in
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:
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
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;
}
You need to create a program that will serve as a cash register emulator.
начать работу
нажать кнопку один
нажать кнопку два
повернуть ручку такую-то
повернуть ручку другую-то
показать на экране текущее состояние
кончить работу
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 questionAsk a Question
731 491 924 answers to any question