class Seller
{
private:
float salestotal; // run total of sales in dollars
int lapTopSold; // running total of lap top computers sold
int deskTopSold; // running total of desk top computers sold
int tabletSold; // running total of tablet computers sold
string name; // name of the seller
Seller::Seller(string newname)
{
name = newname;
salestotal = 0.0;
lapTopSold = 0;
deskTopSold = 0;
tabletSold = 0;
}
bool Seller::SellerHasName (string nameToSearch)
{
if(name == nameToSearch)
return true;
else
return false;
}
class SellerList
{
private:
int num; // current number of salespeople in the list
Seller salespeople[MAX_SELLERS];
public:
// default constructor to make an empty list
SellerList()
{
num = 0;
}
// member functions
// If a salesperson with thisname is in the SellerList, this
// function returns the associated index; otherwise, return NOT_FOUND.
// Params: in
int Find (string thisName);
void Add(string sellerName);
void Output(string sellerName);
};
int SellerList::Find(string thisName)
{
for(int i = 0; i < MAX_SELLERS; i++)
if(salespeople[i].SellerHasName(thisName))
return i;
return NOT_FOUND;
}
// Add a salesperson to the salespeople list IF the list is not full
// and if the list doesn't already contain the same name.
void SellerList::Add(string sellerName)
{
Seller(sellerName);
num++;
}
У меня есть некоторые проблемы с параметрами в моих функциях в классе SellerList. Я хочу добавить кого-то в массив продавцов, поэтому у меня есть запись обо всех моих продавцах ... Боб, Пэм, Тим и т. Д. Мой конструктор Продавец (продавецName) создает продавца с именем sellerName.Объявление моих параметров функции/аргументов функции
Как добавить этого продавца в массив Salespeople и иметь возможность извлечь данные из него и использовать его в большем количестве функций, таких как функция обновления или функция вывода?
MAX_SELLERS = 10 .... Я полагаю, что моя проблема не знает, следует ли использовать только параметры Добавить (строка) или Добавить (Продавец, строка). Любая помощь будет оценена по достоинству.
C++ не похож на Java. Нет причин вообще распределять динамически продавца, а также в этом случае, который не компилируется ('salespeople' - это массив' Продавца', а не указатели на продавцов). Я предлагаю вам изучить C++, прежде чем отвечать на вопросы об этом. – Manu343726
Кто сказал что-нибудь о java? Я знаю C++ .. Я просто так ответил, потому что я принимал управляемый код .. :( – CaldasGSM