Итак, у меня есть назначение в моем классе C++ на классах, и у меня проблемы. Вот описание задания:Проблема с назначением моей школы по классам
Задача программирования 7 на стр. 499 вашего текста запрашивает у вас дизайн и класс инвентаря, который может хранить информацию для предмета в инвентаре розничного магазина. Вам предоставляется код для создания класса вместе с кодом для реализации функций. Продемонстрируйте класс, написав простую программу, которая его использует. Эта программа должна продемонстрировать, что каждая функция работает правильно. Отправьте ваш .cpp-файл, используя предоставленную ссылку.
А вот содержимое файла, отправленного (это довольно длительный):
// Chapter 7---Files for Programming Challenge 13---Inventory Class
// This is the inventory.h file.
// It contains the Inventory class declaration.
#ifndef INVENTORY_H
#define INVENTORY_H
class Inventory
{
private:
int itemNumber;
int quantity;
double cost;
double totalCost;
public:
// Default constructor
Inventory()
{ itemNumber = quantity = cost = totalCost = 0; }
// Overloaded constructor
Inventory(int, int, double); // Defined in Inventory.cpp
// Mutators (i.e., "set" functions) defined in Inventory.cpp
void setItemNumber(int);
void setQuantity(int);
void setCost(double);
// setTotalCost calculates the total cost
// and stores the result in the totalCost member
void setTotalCost()
{ totalCost = cost * quantity; }
// Accessors (i.e., "get" functions)
int getItemNumber()
{ return itemNumber; }
int getQuantity()
{ return quantity; }
double getCost()
{ return cost; }
double getTotalCost()
{ return totalCost; }
// Input validation functions
bool validInt(int);
bool validFloat(double);
};
#endif
// This is the inventory.cpp file.
// It contains the Inventory class function definitions.
#include <iostream>
#include "Inventory.h"
using namespace std;
//************************************************************
// Overloaded constructor
// Accepts arguments to be stored in each member variable.
//************************************************************
Inventory::Inventory(int in, int q, double c)
{
setItemNumber(in);
setQuantity(q);
setCost(c);
setTotalCost();
}
//************************************************************
// setItemNumber accepts an argument to be stored in item number.
//************************************************************
void Inventory::setItemNumber(int in)
{
while (!validInt(in))
{
cout << "Item Number must be positive. Please re-enter: ";
cin >> in;
}
itemNumber = in;
}
//************************************************************
// setQuantity accepts an argument to be stored in quantity.
//************************************************************
void Inventory::setQuantity(int q)
{
while (!validInt(q))
{
cout << "Quantity must be positive. Please re-enter: ";
cin >> q;
}
quantity = q;
}
//************************************************************
// setCost accepts an argument to be stored in cost.
//************************************************************
void Inventory::setCost(double c)
{
while (!validInt(c))
{
cout << "Cost must be positive. Please re-enter: ";
cin >> c;
}
cost = c;
}
//************************************************************
// The validInt member tests its integer argument to see
// if it is negative. If the argument is negative, the function
// returns false. Otherwise, the function returns true.
//************************************************************
bool Inventory::validInt(int value)
{
if (value < 0) // the value is negative so it is NOT valid
return false;
else // the integer value is valid
return true;
}
//************************************************************
// The validFloat member tests its floating-point argument to see
// if it is negative. If the argument is negative, the function
// returns false. Otherwise, the function returns true.
//************************************************************
bool Inventory::validFloat(double value)
{
if (value < 0) // the value is negative so it is NOT valid
return false;
else // the floating-point value is valid
return true;
}
Я просто не знаю, как использовать эту информацию, чтобы сделать программу, которая демонстрирует класс, и это может быть так же просто, как я не сохраняю файл правильным способом
В чем ваш вопрос? –
Слишком много кода, и вы не задали конкретный вопрос, на который мы можем ответить. Если вы не можете понять, как начать работу по заданию, обратитесь за помощью к своему инструктору. Этот сайт предназначен для * конкретных вопросов * о * актуальных проблемах, с которыми вы сталкиваетесь *; неспособность начать домашнее задание не является конкретной проблемой. Ваш инструктор, по-видимому, еще не выполнил работу по проверке достаточной информации для вас, чтобы выполнить эту работу; попросите их получить дополнительную помощь. Это то, за что им платят. Кроме того, ваш заголовок бессмыслен, так как он не делает ничего, чтобы описать конкретную проблему или задать вопрос. –
:(@ действительная функция Float –