For Loop Method Call - c++

An error pops up saying the class type does not provide a subscript operator.
I'm new to c++ and can't seem to figure this one out. Would be really thankful if you provided me some tips and where I'm going wrong in my code outside of the problem.
class Transaction {
protected:
char * ime;
char smetka[16];
float iznos;
Date d;
public:
Transaction() {}
Transaction( char * ime , char * smetka ,float iznos ,Date d ) {
this->ime = new char[strlen(ime)+1];
strcpy(this->ime,ime);
strcpy(this->smetka,smetka);
this->iznos=iznos;
this->d=d;
}
Transaction(const Transaction & c) {
ime = new char[strlen(ime)+1];
strcpy(this->ime,c.ime);
strcpy(this->smetka,c.smetka);
this->iznos=c.iznos;
this->d=c.d;
}
friend ostream & operator<<(ostream & out, const Transaction & c) {
if(c.iznos>0) {
return out << "Inflow " << c.iznos << " " << c.ime << "(" << c.smetka << ")-" << c.d.getDay() << "." << c.d.getMonth() << "." << c.d.getYear() << endl;
} else {
return out << "Outflow " << c.iznos << " " << c.ime << "(" << c.smetka << ")-" << c.d.getDay() << "." << c.d.getMonth() << "." << c.d.getYear() << endl;
}
}
Transaction(char * ime, char * smetka) {
this->ime = new char[strlen(ime)+1];
strcpy(this->ime,ime);
strcpy(this->smetka,smetka);
}
};
class TransactionAccount {
private:
char * ime;
char smetka[16];
Transaction * t;
int n;
int kapacitet;
public:
TransactionAccount() {
this->t = new Transaction[3];
this->kapacitet=3;
}
TransactionAccount(char * ime,char * smetka) {
this->ime = new char[strlen(ime)+1];
strcpy(this->ime,ime);
strcpy(this->smetka,smetka);
}
void addTransaction(Transaction & a) {
if(n<kapacitet) {
this->t = &a;
} else {
kapacitet*=2;
this->t = &a;
}
}
Transaction getTransList() {
return *t;
}
int getTransCapacity() {
return this->kapacitet;
}
int getTransNumber() {
return this->n;
}
virtual ~TransactionAccount() {}
};
int main() {
char name[50],number[16];
float amount;
int d,m,y;
int n;
bool isInflow;
TransactionAccount ta;
int testcase;
cin>>testcase;
switch (testcase) {
case 1: {
cout<<"------Transaction test------"<<endl;
cin>>name;
cin>>number;
cin>>amount;
cin>>d>>m>>y;
Transaction t(name,number,amount,Date(d,m,y));
cout<<t;
}
break;
case 2: {
cout<<"------TransactionAccount test:constructor, desctuctor & get-
functions------"<<endl;
cin>>name;
cin>>number;
TransactionAccount ta(name,number);
cin>>n;
for (int j=0; j<n; j++) {
cin>>name>>number>>amount>>d>>m>>y;
Transaction t(name,number,amount,Date(d,m,y));
ta.addTransaction(t);
}
cout<<"Capacity: "<<ta.getTransCapacity()<<endl;
cout<<"Number of elements: "<<ta.getTransNumber()<<endl;
cout<<(ta.getTransList())[n]; // -- here is the
problem
cin>>n;
cout<<"The element on position "<<n<<" is "<<endl;
}
return 0;
}
My desired result is that it calls the previous object(of the class) and prints it.

The answer to this specific question is that getTransList returns a single Transaction (rather than, as the name would suggest, the 'list'). The error then happens because Transaction does not have an overloaded subscript operator (which is fine; it probably shouldn't).
Transaction getTransList() {
return *t;
}
should be replaced with
Transaction* getTransList() {
return t;
}
which properly returns the array.
However, there are many other problems with the code provided. Some will become apparent when you try to run/debug the code; for the rest, while you can of course ask (new) questions about specific problems on this site, you might be better served consulting your teacher.

Related

`Vector.erase()` does not work for vector of classes

I've made a class of gym pass that has expiration date (int expiration), price for the pass (float price) and name of its' holder (string data). It also has services (char services), where 0 is basic, 1 is with free showers and 2 is VIP room.
Here's the definition of class:
class GymPass
{
int expiration; //the amount of days
char services; //0 - basic, 1 - shower, 2 - VIP room
float price = ((int)services - 47) * expiration;
string data; //client's identifiable data
public:
GymPass()
{
cout << "this: " << this;
expiration = 0;
services = '0';
price = 0;
data = "Lorem ipsum";
}
Pass(int expiration, char services, string data)
{
this->expiration = expiration;
this->services = services;
this->data = data;
}
void Print()
{
cout << "Gym Pass: ";
switch (services)
{
case '0':
{
cout << "Basic gym access, ";
}
case '1':
{
cout << "gym + shower room, ";
}
case '2':
{
cout << "Luxurious gym pass with VIP room, ";
}
default:
{
cout << "Error."; //this should never happen
}
}
cout << "valid for: " << expiration << " days, price: " << price << " zl." << endl;
}
void NewPass()
{
cout << "Choose service type: \n0 - basic\n1 - showers included\n2 - vip room included";
{
char temp{};
do
{
cin >> temp;
if (!((int)temp > 47 & (int)temp < 51)) cout << endl << "Incorrect service type.";
} while (!((int)temp > 47 & (int)temp < 51));
this->services = temp;
}
cout << endl << "Input the expiration date of the Pass:";
cin >> this->expiration;
cout << endl << "Input your name: ";
cin >> this->data;
}
friend bool operator==(const GymPass& lhs, const GymPass& rhs)
{
if (lhs.price != rhs.price) return false;
if (!(lhs.data._Equal(rhs.data))) return false;
if (lhs.services != rhs.services) return false;
if (lhs.expiration != rhs.expiration) return false;
return true;
}
};
I also made a class that's basically a vector of my GymPass classes. I'm trying to make a void function to delete one gym pass, but the erase throws error:
no instance of overloaded function "std::vector<_Ty, _Alloc>::erase [with _Ty=GymPass, _Alloc=std::allocator<GymPass>]" matches the argument list
Like a good programmer, I've done hours of googling, but to no luck. Here's definition of gym class
class Gym
{
vector <GymPass> Clients;
public:
void add(GymPass pass)
{
Clients.push_back(pass);
}
void remove(GymPass pass)
{
for (int i = 0; i < Clients.size(); i++)
{
if (Clients[i] == pass) Clients.erase(i);
}
}
};
void remove is the delete function, where I get the error. How do I fix the error?
std::vector::erase takes an iterator not an index as the argument.
Stali_Klienci.erase(Stali_Klienci.begin() + i);
is a reasonable hack. Stali_Klienci.begin() is the iterator to the first element, the + i increments the iterator to the ith element.
If you want to remove every element from a std::vector then clear does that in one call.
You must read erase() doc first: erase() expects an iterator
Then something like this must do the job:
for (auto it = Stali_Klienci.begin(); it != Stali_Klienci.end(); )
{
if (*it == karnet) {
it = c.erase(it);
} else {
++it;
}
}

Access element of vector

I have a class Student:
class Student {
private:
unsigned int id;
string name;
vector<int> grades;
public:
Student(unsigned int id, string name, vector<int> grades);;
virtual ~Student() {}
unsigned int getId() { return this->id; }
string getName() { return this->name; }
int getGradesAmount() { return this->grades.size(); }
vector<int> getGrades() { return this->grades; }
int getGrade(int i) { return this->grades[i]; }
unsigned int getCoef()
{
unsigned int coef = 1;
for (int i = 0; i < this->grades.size(); i++) { coef *= this->grades[i]; }
return coef;
}
int getNameCoef() { return this->getName().size() % 2; }
ostringstream getInfo()
{
ostringstream info;
info << "ID: " << getId() << ".\n";
info << "Name: " << getName() << ".\n";
info << "Amount of grades: " << getGradesAmount() << ".\n";
info << "Grades:";
for (int i = 0; i < getGradesAmount(); i++)
info << " " << getGrade(i);
info << "\nProduct of grades: " << getCoef() << ".\n";
info << "Is surname has odd number of symbols (0 = no / 1 = yes): " << getNameCoef() << ".\n";
return info;
}
};
Student::Student(unsigned int id, string name, vector<int> grades)
{
this->id = id; this->name = name; this->grades = grades;
}
And a class Group:
class Group : public Student {
protected:
int size = 0;
vector<Student> group;
public:
Group() : Student(getId(), getName(), getGrades()) {}
void addStudent(Student student)
{
if (student.getNameCoef() == 1)
{
if (this->group.size() > 0)
{
for (int i = 0; i < this->group.size(); i++)
{
if (student.getCoef() > group[i].getCoef())
{
this->group.insert(this->group.begin() + i, student);
this->size = this->size + 1;
return;
}
}
}
cout << "\nAdded to start";
this->group.push_back(student);
this->size = this->size + 1;
}
}
};
In Group I'm trying to overload << to make a cout << group.
So, I have added this into a Group:
friend ostream& operator<<(ostream& out, const Group& group) { // overloaded operator of output
out << "\nThere are " << group.size << " students in the group.\n";
for (int i = 0; i < group.size; i++)
{
out << "Student # " << i + 1 << ":\n";
out << group[i].getInfo();
}
return out;
}
But I have this error:
error C2676: binary '[': 'const Group' does not define this operator or a conversion to a type acceptable to the predefined operator
So, I googled for any [] overloaded operators for vector but didn't find anything that work for me. I also tried copying constructor, but it didn't helped me.
How to use group[i].getInfo() ? Or maybe there are some oter ways to access this. So, group[i] must be Student object.
It seems like you are confusing the group which is of type Group with its member, which is confusingly also called group.
Either you provide an Group::operator[] or you change your operator<< to
friend ostream& operator<<(ostream& out, const Group& group) { // overloaded operator of output
auto& vect = group.group;
out << "\nThere are " << vect.size() << " students in the group.\n";
for (int i = 0; i < vect.size(); i++)
{
out << "Student # " << i + 1 << ":\n";
out << vect[i].getInfo();
}
return out;
}
There are several issues with your code (see comments), but the one you're asking about is because of this line:
out << group[i].getInfo();
As JohnFileau mentioned, group is a Group object, not a std::vector. If you want to access the std::vector group in the Group class, you will need group.group:
out << group.group[i].getInfo();
This will fix this issue, but it's only fair to warn you you will soon hit others. I recommend reading the comments on your question and figuring out how to fix them.
Something worth noting here is that part of the reason you're seeing this is you may not realize that operator<<() is not a member function of Group. That is, even if you define it inline like this:
class Group : public Student {
//...
friend ostream& operator<<(ostream& out, const Group& group) { // overloaded operator of output
out << "\nThere are " << group.size << " students in the group.\n";
for (int i = 0; i < group.size; i++)
{
out << "Student # " << i + 1 << ":\n";
out << group[i].getInfo();
}
return out;
}
};
It might look like it's a member of Group, but it's actually not. It is an external friend function. It is not actually a part of Group. That means you can't access the data members directly. For instance,
this->size
will fail because, again, it's not actually a member function.
If you want to access data members of Group, you need to access them via the instance you were passed (i.e., group:
group.size
Note that that means when you do something like group.size, you're actually getting data member Group::size, not the size() from std::vector.

delete array pointers heap corruption

I get an exception on this line in Visual Studio 2015. It builds with no errors.
_free_dbg(block, _UNKNOWN_BLOCK);
This is how I declare the new array of pointers:
CAirship * pAirShip[10];
This is how I delete the array of pAirShip pointers:
for (int i = 0; i < 10; i++) {
if (pAirShip[i]) {
cout << "pAirShip[" << i << "] is " << pAirShip[i] << endl;
delete pAirShip[i];// Delete appropriate object
}
} // end for loop
I get an error on attempting to delete pAirShip[0],
Here is a debug window that does print the pointer addresses:
Here is the full code:
struct AirShipFile {
int Type; // Airplane or Balloon
string name; // Name of the airship
int passCount; // passenger count
int weightCargo; // cargo weight
int EngOrGas; // engine or gas type
int distance; // range or altitude
};
enum EngineType { Jet, Propeller }; // for airplanes only
std::ostream& operator<<(std::ostream& out, const EngineType value) {
static std::map<EngineType, std::string> strings;
if (strings.size() == 0) {
#define INSERT_ELEMENT(p) strings[p] = #p
INSERT_ELEMENT(Jet);
INSERT_ELEMENT(Propeller);
#undef INSERT_ELEMENT
}
return out << strings[value];
}
enum GasType {Helium, Hydrogen }; // for proprellers only
std::ostream& operator<<(std::ostream& out, const GasType value) {
static std::map<GasType, std::string> strings;
if (strings.size() == 0) {
#define INSERT_ELEMENT(p) strings[p] = #p
INSERT_ELEMENT(Helium);
INSERT_ELEMENT(Hydrogen);
#undef INSERT_ELEMENT
}
return out << strings[value];
}
enum AirShipType { AIRPLANE, BALLOON };
class CAirship {
public:
CAirship() { }
virtual void SetData(AirShipFile &data) = 0;
virtual void GetData() = 0;
AirShipType GetAirShipType() { return m_AirShipType; }
protected:
AirShipType m_AirShipType;
};
class CAIRPLANE : public virtual CAirship {
public:
CAIRPLANE() : CAirship() {}
void SetData(AirShipFile &data);
void GetData();
private:
EngineType m_EngineType;
int m_MaxPassengerCount;
string m_Name;
int m_MaxCargoWeight;
int m_MaxAltitude;
};
// Function: SetData
void CAIRPLANE::SetData(AirShipFile &data)
{
// cast integer to enum
m_EngineType = EngineType(data.EngOrGas);
// airplane name
m_Name = data.name;
// passenger count
m_MaxPassengerCount = data.passCount;
//max cargo weight
m_MaxCargoWeight = data.weightCargo;
// cast integer to enum
m_AirShipType = AirShipType(data.Type);
// maximum altitude
m_MaxAltitude = data.distance;
}
void CAIRPLANE::GetData()
{
cout << setw(20) << m_Name << "\t" << setw(20) << m_EngineType << setw(20);
cout << left << setw(20) << m_MaxAltitude << "\n";
}
class CBALLOON : public virtual CAirship {
public:
CBALLOON() : CAirship() {}
void SetData(AirShipFile &data);
void GetData();
private:
GasType m_GasType;
EngineType m_EngineType;
int m_MaxPassengerCount;
string m_Name ;
int m_MaxCargoWeight;
int m_MaxAltitude;
};
void CBALLOON::SetData(AirShipFile &data)
{
// cast integer to enum
m_GasType = GasType(data.EngOrGas);
// airplane name
m_Name = data.name;
// passenger count
m_MaxPassengerCount = data.passCount;
//max cargo weight
m_MaxCargoWeight = data.weightCargo;
// cast integer to enum
m_AirShipType = AirShipType(data.Type);
// maximum altitude
m_MaxAltitude = data.distance;
}
void CBALLOON::GetData()
{
cout << setw(20) << m_Name << "\t" << setw(20)<< m_GasType << setw(20);
cout << left << setw(20) << m_MaxAltitude << "\n";
}
// AIRPLANE = 0
// BALLOON = 1
int main(int argc, char *argv[])
{
if (argc != 2) {
cout << "Usage: PR <filename>\n";
return 1;
}
ifstream Infile(argv[1]);
if (!Infile) {
cout << "Cannot open file\n";
return 1;
}
char LineBuf[100];
char d[] = ",";
CAirship * pAirShip[10];
int i = 0;
while (Infile.getline(LineBuf, 100)) {
struct AirShipFile data;
// read the first field Airship type
// airplane or balloon
data.Type = atoi(strtok(LineBuf, d));
switch (data.Type) {
case AIRPLANE:
// Create AIRPLANE Object
pAirShip[i] = new CAIRPLANE();
data.name = strtok(NULL, d);
data.passCount = atoi(strtok(NULL, d));
data.weightCargo = atoi(strtok(NULL, d));
data.EngOrGas = atoi(strtok(NULL, d));
data.distance = atoi(strtok(NULL, d));
break;
case BALLOON:
// Create BALLOON Object
pAirShip[i] = new CBALLOON();
data.name = strtok(NULL, d);
data.passCount = atoi(strtok(NULL, d));
data.weightCargo = atoi(strtok(NULL, d));
data.EngOrGas = atoi(strtok(NULL, d));
data.distance = atoi(strtok(NULL, d));
break;
default:
break;
} // end switch
// call appropriate function
pAirShip[i++]->SetData(data);
memset(LineBuf, '\0', 100);
}
Infile.close();
cout << "Listing of all Airplanes \n";
cout << left << setw(20) << "\nName" << left<< setw(20)<<"\tEngine Type";
cout << left<<setw(20)<<"\Maximum Range" << "\n\n";
for (int i = 0; i < 10; i++) {
if (pAirShip[i]->GetAirShipType() == AIRPLANE)
pAirShip[i]->GetData();
}
cout << "\n\nListing of all Balloons \n";
cout <<left << setw(20) << "\nName" << left << setw(20) << "\tGas Type" ;
cout << left << setw(20) << "\Maximum Altitude" << "\n\n";
for (int i = 0; i < 10; i++) {
if (pAirShip[i]->GetAirShipType() == BALLOON)
pAirShip[i]->GetData();
}
for (int i = 0; i < 10; i++) {
if (pAirShip[i]) {
delete pAirShip[i];// Delete appropriate object
}
} // end for loop
return 0;
}
The problem is that when allocating an array of any kind, C++ does not initialize the elements, but leaves them with "random" values. So, when you create an array of pointers, the pointers are not created with NULL, nullptr or 0 value, so this is not a good indicator if they are really unused on its own. Trying to free the space that isn't allocated is what generates the error. You should first initialize them (by yourself in a for loop) with nullptr right after you create the array, then you can use your code for deleting the array of pointers.

Constructor with a array type of another class

This is the photo of the model I have to resolve:
I have this class:
#include<iostream>
#include<fstream>
using namespace std;
class Word
{
protected:
char *value;
char type[20];
int noChars;
static int noWords;
public:
Word(char *value, char *type)
{
this->noChars = 0;
this->value = new char[strlen(value) + 1];
strcpy(this->value, value);
strcpy(this->type, type);
Word::noWords++;
}
Word()
{
this->noChars = NULL;
this->value = NULL;
strcpy(this->type,"Nedeterminat");
}
void operator=(Word &x)
{
this->noChars = x.noChars;
strcpy(this->type, x.type);
this->value = new char[strlen(x.value) + 1];
strcpy(this->value, x.value);
}
Word(const Word& x){
this->noChars = x.noChars;
strcpy(this->type, x.type);
this->value = new char[strlen(x.value) + 1];
strcpy(this->value, x.value);
}
char* getValue()
{
return this->value;
}
void setType(char* x)
{
if (x == NULL)
{
throw new exception("Tip gresit!");
}
else
{
strcpy(this->type, x);
}
}
char &operator[](int i)
{
if (i >= 0 && i <= (strlen(this->value) - 1))
{
return this->value[i];
}
else
cout << endl << "Eroare indice: " << i;
}
static int getNoWords()
{
return Word::noWords;
}
operator int()
{
return this->noChars;
}
friend ostream& operator<<(ostream&, Word&);
friend istream& operator>>(istream&, Word&);
};
ostream& operator<<(ostream& consola, Word& x)
{
consola << "Value: " << x.getValue() << endl;
consola << "Type: " << x.type << endl;
consola << "NoChars: " << x.noChars << endl;
return consola;
}
istream& operator>>(istream& consola, Word& x){
cout << "Value: "; consola >> x.value;
cout << "Type: "; consola >> x.type;
cout << "NoChars: "; consola >> x.noChars;
return consola;
}
int Word::noWords = 0;
class Dictionary{
private:
char *language;
int noWords;
bool isOnline;
Word v[100];
public:
Dictionary(char *language, Word w, int noWords, bool isOnline)
{
this->language = new char[strlen(language) + 1];
strcpy(this->language, language);
for (int i = 0; i < 100; i++)
{
this->v[i] = w;
}
this->noWords = noWords;
this->isOnline = isOnline;
}
};
int main()
{
//1
Word w1("exam", "noun");
/*Word w2;*/
Word w3 = w1;
cout << w3;
//2
cout << endl << "Word value: " << w3.getValue();
Word w2("to take", "noun");
w2.setType("verb");
//3
w3 = w2;
cout << endl << w3;
Word *pw = new Word("pointer", "noun");
delete pw;
//4
cin >> w3; cout << w3;
char character = w3[2];
cout << endl << character;
//5
double noChars = (int)w1;
cout << endl << noChars;
cout << endl << Word::getNoWords() << endl;
//6
Dictionary dictionary1("English", NULL, 0, false);
}
I have this main:
Dictionary dictionary1("English", NULL, 0, false);
How should I change the constructor to work? I receive a error :
Arrgument types are:(const char[8],int,int,bool);
And how should I write the default constructor?
NULL cannot be assigned to Word. Try Word() instead which will call the default constructor to Word. Consider changing that function parameter to const Word& - anonymous temporaries are allowed to bind to const references.
I'd prefer to see a std::string as the type for the member variable language; using a const std::string& as the function parameter. Then you will not have to worry about a subsequent delete call, and defining your own assignment operators and copy constructors. Currently, your class leaks memory.
You can not Assign null to the type Word. If you want to default it you should pass something like word()
Dictionary dictionary1("English", word(), 0, false);
EDIT:
The better approach,IMO, that will work for the same main() you have is like this:
class Dictionary{
private:
std::string language;
int noWords;
bool isOnline;
std::array<Word,100> v;
public:
Dictionary(std::string const& language, Word* w, int noWords, bool isOnline): language (language),isOnline(isOnline ),noWords(noWords)
{
for (int i = 0; i < 100; i++){
this->v[i] = (w==NULL)?word():*w;
}
}
};

logical error using copy constructor in c++

In the following program my intended output is to display the list of item a customer object is interested of but it is showing null values. no values are printed when i am calling showitem(). please help me out to correct the logical fault in my code.
class item
{
int itemno;
string name;
public:
item()
{
itemno=0;
}
item(int r,string n)
{
itemno = r;
name = n;
}
void showitem()
{
cout<<"Item no is:"<<itemno<<"\n";
cout<<"Name is :"<<name<<"\n";
}
};
class customer
{
public:
int customerno;
string customername;
string address;
int totalitem;
item *iteminterested;
customer()
{
iteminterested=0;
totalitem=0;
}
customer(customer &custref)
{
customerno=custref.customerno;
customername=custref.customername;
address=custref.address;
iteminterested=new item[custref.totalitem];
for(int i=0;i<custref.totalitem;++i)
{
iteminterested[i]=custref.iteminterested[i];
}
totalitem=custref.totalitem;
}
customer(int no,string cusname,string add,item *temp,int total)
{
customerno=no;
customername=cusname;
address=add;
iteminterested=new item[total];
for(int i=0;i<totalitem;++i)
{
iteminterested[i]=temp[i];
}
totalitem=total;
}
void showcustomer()
{
cout<<"customer name is"<<customername<<"\n";
cout<<"customer number is"<<customerno<<"\n";
cout<<"customer address is"<<address<<"\n";
cout<<"customer " <<customername <<"intersted in \n";
for(int k=0;k<totalitem;k++)
{
iteminterested[k].showitem();
}
}
};
int main()
{
customer steve;
item itemarray[]={item(3,"sandwiches"),item(4,"paperbags"),item(5,"biscuits"),item(6,"coke"),item(10,"biscuits"),item(9,"pen"),item(1,"pencil"),item(2,"eraser")};
steve=customer(2,"steve","aus",itemarray,5);
steve.showcustomer();
customer mark(steve);
mark.showcustomer();
mark.showcustomer();
steve.showcustomer();
return 0;
}
In the customer constructor you must set totalitem before assigning the items. It is not initialized for the loop. Or use total for the loop.
#include <iostream>
#include <string>
using namespace std;
class Item {
int itemno;
string name;
public:
Item()
: itemno(0) { }
Item(int r, string n)
: itemno(r),
name(n) { }
void showitem() const {
cout << "Item no is: " << itemno << "\n";
cout << "Name is: " << name << "\n"; } };
class Customer {
public:
int customerno;
string customername;
string address;
int totalitem;
Item* iteminterested;
Customer()
: totalitem(0),
iteminterested(0) { }
Customer(const Customer& custref)
: customerno(custref.customerno),
customername(custref.customername),
address(custref.address),
totalitem(custref.totalitem) {
iteminterested = new Item[totalitem];
for (int i = 0; i < totalitem; ++i) {
iteminterested[i] = custref.iteminterested[i]; } }
Customer(int no, string cusname, string add, Item* temp, int total)
: customerno(no),
customername(cusname),
address(add),
totalitem(total) {
iteminterested = new Item[total];
for (int i = 0; i < totalitem; ++i) {
iteminterested[i] = temp[i]; } }
void showcustomer() const {
cout << "customer name is: " << customername << "\n";
cout << "customer number is: " << customerno << "\n";
cout << "customer address is: " << address << "\n";
cout << "customer " << customername << " intersted in \n";
for (int k = 0; k < totalitem; ++k) {
iteminterested[k].showitem(); } } };
int main() {
Customer steve;
Item itemarray[] = {
Item(3, "sandwiches"),
Item(4, "paperbags"),
Item(5, "biscuits"),
Item(6, "coke"),
Item(10, "biscuits"),
Item(9, "pen"),
Item(1, "pencil"),
Item(2, "eraser") };
steve = Customer(2, "steve", "aus", itemarray, 5);
steve.showcustomer();
Customer mark(steve);
mark.showcustomer();
mark.showcustomer();
steve.showcustomer();
return 0; }