#include <iostream>
#include <string>
usingnamespace std;
class VEHICLE{ // Class Vehicle defination
public:
VEHICLE();
// Declaration of Public funtions and members
void display(VEHICLE*);
void get_input(string,string,int,int);
friend istream& operator >>(istream &,VEHICLE &);
friend ostream& operator <<(ostream&,VEHICLE&);
~VEHICLE()
{
cout<<"Object Deleted"<<endl;
}
// Private Section of the class Vehicale
private:
string company;
string model;
int year;
int engin;
};
VEHICLE::VEHICLE() // default Class constructor's defination
{
company = "";
model = "";
year = 0;
engin = 0;
}
istream& operator >>(istream& in,VEHICLE& V)
{
cout<<"Please Enter The Name Of Vehicle Maker Company: ";
in>>V.company;
cout<<endl;
cout<<"Please Enter the Model Of The Vehicle: ";
in>>V.model;
cout<<endl;
cout<<"Please Enter The Year Of Registration: ";
in>>V.year;
cout<<endl;
cout<<"Please Enter The Engin Capacity: ";
in>>V.engin;
cout<<endl;
return in;
}
ostream& operator << (ostream& os,VEHICLE& V)
{
os<<"Company: "<<V.company<<'\n'<<endl;
os<<"Model: "<<V.model<<'\n'<<endl;
os<<"Year of Manufacture: "<<V.year<<'\n'<<endl;;
os<<"Engin Capacity in CC: "<<V.engin<<'\n'<<endl;
return os;
}
int main()
{
string comp;
string mod;
int y = 0;
int eng = 0;
int vnum = 0;
VEHICLE* vehiptr;
cout<<"Please Enter The Number Of Vehicle: ";
cin>>vnum;
cout<<endl;
vehiptr = new VEHICLE[vnum]; // Creating a pointer array according to the number of Vehicles
for(int i=0;i<vnum;i++)
{
cout<<"VEHICLE "<<i+1<<endl;
cout<<endl;
cin>>vehiptr[i];
}
for(int j=0;j<vnum;j++)
{
cout<<"VEHICLE ["<<j+1<<']'<<endl;
cout<<endl;
cout<<vehiptr[j];
}
cout<<endl;
delete [] vehiptr; // Calling the distructor to delete the objects
cout<<endl;
system("pause");
}
It's still bad. Your operator>>() overload outputs to the standard output some messages. Imagine you want to use the same operator when reading from a file. When you will do that a bunch of messages will show on screen (or whichever is the standard output).
In your output operator you have things like <<'\n'<<endl. Use <<endl<<endl as this will work accordingly (e.g.: for Unix endl means '\n' while for Windows it means "\r\n").
PS: when you code either indent by tabs only or by spaces only. Tabs don't always render the same in all editors (e.g.: 1 tab doesn't always mean 4 spaces). When copying and pasting code that has mixed indents (tabs + spaces) in some editors it will look "right" while in others it won't.