error in my c++ program

Status
Not open for further replies.

its me

Right off the assembly line
Hello

I need a help in c++ program, There is an error and I couldn't solve it.

this is the program

#include<iostream>
#include<string>
using namespace std;
void showMenu();
/////////////////////The Struct Car/////////////////////
struct Car
{
int model;
long plate;
string brand;
long mileage;
double price;
};
/////////////////////The Class linkedListType/////////////////////
template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};
//////////////////////////////////////////////////////////////////
template <class Type>
class linkedListType
{
private:
void copyList(const linkedListType<Type>& otherList);

protected:
int count;
nodeType<Type> *first;
nodeType<Type> *last;

public:
const linkedListType<Type> & operator=(const linkedListType<Type>&);
void initialzeList();
bool isEmptyList();
int length();
void destroyList();
Type front();
Type back();
void PrintAll();
bool Search(const Type &tItem);
void insertBeg(const Type &tItem);
void insertEnd(const Type &tItem);
void deleteNode(const Type &tItem);
linkedListType();
linkedListType(const linkedListType<Type> &otherList);
~linkedListType();

void FindAndDelete( );
void SplitList(const linkedListType<Type> &L1,const linkedListType<Type> &L2);
void PrintOnlyOneCar(const Type &Item);
void Find_MostExpensiveCar();
bool CheckSamebrand(const Type &Item,const Type &Value);


};
template <class Type>
void Split(const linkedListType<Type>&list1, const linkedListType<Type>&, const linkedListType<Type>&)
{
if(list1.isEmpty())
cerr<<"The list is Empty.\n";
else
{

linkedListType<Type>L3(list1);
Type value=L3.front();
while(!L3.isEmpty())
{

if(value.model<= 2000)
L1.insertEnd(value);
else if(value.model> 2000)
L2.insertEnd(value);

L3.deleteNode(value.plate);
}
}

}
///////////////////////////////The Main()//////////////////////////////////////
int main()
{
linkedListType<Car>list1;
linkedListType<Car>L1;
linkedListType<Car>L2;
Car c,c1;


bool p,k;
int Code;
cout<<"******************** The Cars Exhibition ********************\n";
showMenu();
cout<<"\nPlease,Enter your selection:";
cin>>Code;
cout<<"\n";


while(Code!=0)
{
switch(Code)
{
case 1:
cout<<"Eenter the model(year of make):";
cin>>c.model;
cout<<"Enter the plate number:";
cin>>c.plate;
cout<<"Enter the brand:";
cin>>c.brand;
cout<<"Enter the mileage(how many Kilometers):";
cin>>c.mileage;
cout<<"Enter the price:";
cin>>c.price;
list1.insertEnd(c);
cout<<"\n****************************************\n";
break;
case 2:
cout<<"Enter the plate number for car you went delete it:";
cin>>c.plate;
list1.deleteNode(c);
cout<<"\n****************************************\n";
break;
case 3:
list1.PrintAll();
cout<<"\n****************************************\n";
break;
case 4:
if(list1.isEmptyList())
cout<<"The list is Empty.\n";
else
{
cout<<"Enter the plate number for the car you wont print data for it:";
cin>>c.plate;
list1.PrintOnlyOneCar(c);
}
cout<<"\n****************************************\n";
break;
case 5:
if(list1.isEmptyList())
cout<<"The list is Empty.\n";
else
{
cout<<"Enter the plate number for the car you wont search data for it:";
cin>>c.plate;
p=list1.Search(c);
if(p)
{
cout<<"\nThe car is found ,and the position is:"<<p<<endl;
list1.PrintOnlyOneCar(c);
}
else
cout<<"\nThe plate number not found.\n";
}
cout<<"\n****************************************\n";
break;
case 6:
list1.Find_MostExpensiveCar();
cout<<"\n****************************************\n";
break;
case 7:
cout<<"Enter two brand for the car you wont check if it similar to another car's brand :";
cin>>c.brand;
cin>>c1.brand;

k=list1.CheckSamebrand(c,c1);
if(k)
cout<<"\nBoth cars have same brand.\n";
else
cout<<"\nThe cars have not same brand.\n";
cout<<"\n****************************************\n";
break;
case 8:
list1.FindAndDelete( );
cout<<"\n****************************************\n";
break;
case 9:
list1.SplitList(L1,L2);
cout<<"\n****************************************\n";
break;
default:
cout<<"Invalid selection\n";
cout<<"\n****************************************\n";
}
cout<<"\n";
showMenu();
cout<<"\nPlease,Enter your selection:";
cin>>Code;
cout<<"\n";
}

cout<<"****************************************\n";
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
template<class Type>
linkedListType<Type>::linkedListType()
{
first=NULL;
last=NULL;
count=0;
}
//////////////////////////////////////////
template<class Type>
bool linkedListType<Type>::isEmptyList()
{

return(first==NULL);
}
//////////////////////////////////////////
template<class Type>
void linkedListType<Type>::destroyList()
{
nodeType<Type> *temp;

while(first!=NULL)
{
temp=first;
first=first->link;
delete temp;
}
last=NULL;
count=0;
}
//////////////////////////////////////////
template<class Type>
void linkedListType<Type>::initialzeList()
{

destroyList();
}
//////////////////////////////////////////
template<class Type>
int linkedListType<Type>::length()
{

return count;
}
//////////////////////////////////////////
template<class Type>
Type linkedListType<Type>::front()
{
assert(last!=NULL);
return first->info;

}
//////////////////////////////////////////
template<class Type>
Type linkedListType<Type>::back()
{
assert(last!=NULL);
return last->info;

}
//////////////////////////////////////////
template <class Type>
void linkedListType<Type>::printAll()
{

if(isEmptyList())
cout<<"The list is Empty.\n";

else
{
nodeType<Type> *current=first;
while(current!=NULL)
{

cout<<"The information for the car is as following:\n";
cout<<"The model of car is:"<<current->info.model<<".\n";
cout<<"The plate number for car is:"<<current->info.plate<<".\n";
cout<<"The brand is:"<<current->info.brand<<".\n";
cout<<"The mileage is:"<<current->info.mileage<<".\n";
cout<<"The price is:"<<current->info.price<<".\n\n";
current=current->link;
}
}

}
//////////////////////////////////////////
template<class Type>
bool linkedListType<Type>::Search(const Type &Item)
{
if(isEmptyList())
{
cout<<"The list is Empty.\n";
return false;
}
else
{
nodeType<Type> *current=first;

while(current!=NULL)
{ if(current->info.plate == Item.plate)
return true;
else
current=current->link;
}

return false;
}
}
//////////////////////////////////////////
template<class Type>
void linkedListType<Type>::insertBeg(const Type &Item)
{
nodeType<Type> *temp;
temp= new nodeType<Type>;

assert(temp!=NULL);
temp->info=Item;
temp->link=NULL;

count++;
if(isEmptyList())
{
first=temp;
last=temp;
}
else
{
temp->link=Item;
first=temp;
}

}
///////////////////////////////////////////
template<class Type>
void linkedListType<Type>::insertEnd(const Type &Item)
{
nodeType<Type> *temp;
temp= new nodeType<Type>;

temp->info=Item;
temp->link=NULL;

count++;
if(isEmptyList())
{
first=temp;
last=temp;
}
else
{
last->link=temp;
last=temp;
}

}
///////////////////////////////////////////////
template<class Type>
void linkedListType<Type>::deleteNode(const Type &Item)
{
nodeType<Type> *current;
nodeType<Type> *trailcurrent;
bool found;

if(isEmptyList())
{
cout<<"\nCannot delelte from an Empty list.\n";
return;
}
else
{
if(first->info.plate == Item.plate)
{ current=first;
first=first->link;
count--;

if(first==NULL)
last=NULL;
delete current;

cout<<"\nNow,the item remove form the list.\n";
}
else
{
found=false;
trailcurrent=first;
current=first->link;

while(current!=NULL && !found)
{
if(current->info.plate !=Item.plate)
{
trailcurrent=current;
current=current->link;
}
else
found=true;
}
if(found)
{
trailcurrent->link=current->link;
count--;

if(last=trailcurrent)
last=trailcurrent;
delete current;

cout<<"\nNow,the item remove form the list.\n";
}
else
cout<<"\nItem to be deleted is not in the list.\n";
}

}
}
///////////////////////////////////////////////
template<class Type>
void linkedListType<Type>::copyList(const linkedListType<Type> &otherList)
{
nodetype<Type> *current;
nodetype<Type> *newNode;

if(first!=NULL)
destroyList();

if(otherList.first==NULL)
{
first=NULL;
last=NULL:
count=0;
}
else
{
current=otherList.first;
count=otherList.count;

first=new nodetype<Type>;
assert(first!=NULL);
first->info=current->info;
first->link=NULL;

last=first;
current=current->link;
while(current!=NULL)
{
newNode=new nodeType<Type>;
assert(newNode!=NULL);

newnode->info=current->info;
newNode->link=NULL;

last->link=newNode;
last=newNode;
current=current->link;
}
}
}
///////////////////////////////////////////////////////
template<class Type>
linkedListType<Type>::~linkedListType()
{

destroyList();
}
///////////////////////////////////////////////////////
template<class Type>
linkedListType<Type>::linkedListType(const linkedListType<Type> &otherList)
{

first=NULL;
copyList(otherList);

}
///////////////////////////////////////////////////////
template<class Type>
const linkedListType<Type> & linkedListType<Type>::eek:perator=(const linkedListType<Type> &otherList)
{

if(this!=&otherList)
copyList(otherList);

return *this;
}
///////////////////////////////////////////////////////
template <class Type>
void linkedListType<Type>::printOnlyOneCar(const Type &Item)
{
bool K;
K=Search(Item);


if(!K)
cout<<"\nCannot found the car.\n";
else
{ nodeType<Type> *current=first;

while(current!=NULL)
{ if(current->info.plate == Item.plate)
break;
else
current=current->link;
}

cout<<"The information for the car is as following:\n";
cout<<"The model of car is:"<<current->info.model<<".\n";
cout<<"The plate number for car is:"<<current->info.plate<<".\n";
cout<<"The brand is:"<<current->info.brand<<".\n";
cout<<"The mileage is:"<<current->info.mileage<<".\n";
cout<<"The price is:"<<current->info.price<<".\n\n";

}
}
/////////////////////////////////////////////
template <class Type>
void linkedListType<Type>::Find_MostExpensiveCar()
{
Type Exp;

if(isEmptyList())
cout<<"The list is Empty.\n";
else
{
nodeType<Type> *current=first;
bool found=false;

while(current!=NULL && !found)
{
if(current->info.price>0)
{
Exp=current->info;
cout<<"The information for the most expensive car is as following:\n";
cout<<"The model of car is:"<<current->info.model<<".\n";
cout<<"The plate number for car is:"<<current->info.plate<<".\n";
cout<<"The brand is:"<<current->info.brand<<".\n";
cout<<"The mileage is:"<<current->info.mileage<<".\n";
cout<<"The price is:"<<current->info.price<<".\n\n";
found=true;
}
else
current=current->link;
}


}

}
/////////////////////////////////////////////
template <class Type>
bool linkedListType<Type>::CheckSamebrand(const Type &Item,const Type &Value)
{

return(Item.brand == Value.brand);

}
/////////////////////////////////////////////
template <class Type>
void linkedListType<Type>::FindAndDelete( )
{
if(isEmptyList())
cerr<<"The list is Empty.\n";
else
{
nodeType<Type> *current=first->link, *min=first;
while(current!=NULL)
{
if(current->info.mileage<min->info.mileage)
min=current;

current=current->link;

deleteNode(min->info);
}
}

}
/////////////////////////////////////////////
template <class Type>
void linkedListType<Type>::SplitList(const linkedListType<Type> &L1,const linkedListType<Type> &L2)
{
if(isEmptyList())
cerr<<"The list is Empty.\n";
else
{
nodeType<Type> *current=first;

while(current!=NULL)
{
if(current->info.model<= 2000)
{
L1.insertEnd(current->info);
}
else if(current->info.model> 2000)
{
L2.insertEnd(current->info);
}

current=current->link;

}
}

}
/////////////////////////////////////////////
void showMenu()
{
cout << "To make a selection enter the number and press enter."<<endl;
cout << "0: Exit the program."<<endl;
cout << "1: Insert new car,s information."<<endl;
cout << "2: Delete a car(according to plate number)."<<endl;
cout << "3: Print all cars."<<endl;
cout << "4: Print one car information(according to plate number)."<<endl;
cout << "5: Search for a car(according to plate number)."<<endl;
cout << "6: Find The most Expensive Car ."<<endl;
cout << "7: Check same brand."<<endl;
}
/////////////////////The End/////////////////////



the error is :-
1-'insertEnd' : cannot convert 'this' pointer from 'const class linkedListType<struct Car>' to 'class linkedListType<struct Car> &'




 

nightcrawler

Broken In
you are passing a pointer to a function which accepts only reference thats all.


Look into the declaration of insertEnd and change it to pointer. You will also have to make changes to the definition accordingly.

void insertEnd(const Type &tItem); to void insertEnd(Type *ptr);
 
Status
Not open for further replies.
Top Bottom