jeudi 25 décembre 2014

How to remove the city info by enter the name then how to search the city


include


include


include


include


using namespace std; struct node{string Name;string address; string search;int zipcode;int population;node *next;}*start;


bool isempty(node *head); char menu(); void first(node *&head,node *&last,string Name,string address,int zipcode,int population); void search(node *find,node *last); void insert(node *&head,node *&last,string Name,string address,int zipcode,int population); void zipcode(node *&head,node *&last,string Name,string address,int zipcode); void population(node *&head,node *&last,string Name,string address,int zipcode,int population);


void removefirst(node *&head, node *&last); void remove(node *&head, node *&last,node *remove); void showlist(node *current); void reverse(node *reverse,node *head);


bool isempty(node *head) { if(head==NULL)



return true;

else
return false;


} char menu() { char choice ; cout<<"____________________Choose an Item here___________________"<



cout << "menu\n\n";
cout <<"1. Enter the city Information\n";
cout <<"2. Remove the city Name from the Top\n";
cout <<"3. Show the list \n";
cout <<"4. Search Address by City Name\n";
cout<<"5. Scanning record\n";
cout<<"6. Remove By name"<<endl;


// cout<<"7. Insert the Queue"< cout<



cin>>choice;
cout<<endl;
return choice;


} void first(node *&head,node *&last,string Name,string address,int zipcode,int population) { node *temp=new node; temp->Name=Name; temp->address=address; temp->zipcode=zipcode; temp->population=population; temp->next=NULL;



last=temp;
head=temp;


} void insert(node *&head,node *&last,string Name,string address,int zipcode,int population) { if(isempty(head))



first(head,last,Name,address,zipcode,population);

else {
node *temp=new node;
temp->Name=Name;
temp->address=address;
temp->zipcode=zipcode;
temp->population=population;

temp->next=NULL;

last->next=temp;
last=temp;
}


}


void reverse(node *reverse,node *head) {


node *rev( node *head ) {


node *next; node *current = head; node *prev = NULL;


while (current!= NULL) { next = current->next; current->next = prev;



prev = current;
current = next;
}


return prev; } }


void removefirst(node *&head,node *&last) { if(isempty(head))



cout<<"The list is already empty"<<endl;

else if(head==last)
{
delete head;
head=NULL;
last=NULL;

}
else{
node *temp=head;
head= head->next;

delete temp;
}


}


/* void remove(node *remove,node *head,node *last) { if(isempty(remove)) cout<<"List is already empty now ..."<



}
else
{
node *temp= last;
last=last->next;
delete temp;
}


} */ void search(node *find ,node *last) { if(isempty(find)) {



cout<<"The list is already Empty "<<endl;
}


else{

cout<<" --------------------------------------------"<<endl;
cout<<" | Search Successively found ! |"<<endl;
cout<<" --------------------------------------------"<<endl;



cout<<"The Address of "<<find->Name<<" is "<<find->address<<endl;
cout<<"There are "<<find->population<<" people living in "<<find->Name<<" and the Zipcode is "<<find->zipcode<<endl;
last= find->next;


}


}


void showlist(node *current) { if(isempty(current)) {



cout <<"The list is empty, Please Insert something"<<endl;

}


else
{
cout<<" -----------------------------------------"<<endl;
cout<<" The list contains "<<endl;
cout<<" ------------------------------------------"<<endl;

while(current!=NULL)
{
cout<<"City Name :"<<current->Name<<endl;
cout<<"City Address :"<<current->address<<endl;
cout<<"Populaton "<<current->population<<endl;
cout<<"The ZipCode is :"<<current->zipcode<<endl;
current=current->next;
}

}
system("CLS");


} int main() {system ("color a1");



cout<<" Welcome to Group5 Creation "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout<<" "<< endl;
cout <<" copyright 2014"<< endl;
cout <<" Click Enter to continuous.................."<< endl;
system("PAUSE");
system("CLS");
system("color b0");

cout <<static_cast<char>(1)<<static_cast<char>(2)<<static_cast<char>(1)<<" "<<static_cast<char>(3)<<" "<<static_cast<char>(2)<<static_cast<char>(1)<<static_cast<char>(2)<<endl;
cout << "This Project will show you how to manipulate data in C++ "<<static_cast<char>(2)<< endl;
cout <<"------------------------------------------------------------------------------"<< endl;



node *head=NULL;
node *last=NULL;
char choice;
string Name;
string address;
int population;
int zipcode;
do{
choice=menu();
switch(choice)
{
case '1':cout <<"Enter the Name of the City" << endl;
cin>>Name;


cout<<" Enter the Address of the city :"<<endl;
cin>>address;
cout<<"Now Enter the Population :"<<endl;
cin>>population;
cout<<"What About the Zipcode ?:"<<endl;
cin>>zipcode;
insert(head,last,Name,address,zipcode,population);
system("CLS");

break;


case '2':removefirst(head,last);

cout<<"The name has been removed "<<endl;
system("color c");
system("CLS");
break;



case '7':cout <<"Enter the Name of the City" << endl;
cin>>Name;


cout<<" Enter the Address of the city :"<<endl;
cin>>address;
cout<<"Now Enter the Population :"<<endl;
cin>>population;
cout<<"What About the Zipcode ?:"<<endl;
cin>>zipcode;
insert(head,last,Name,address,zipcode,population);
system("CLS");
break;



case '4':cout<<"Type the name Here !"<<endl;
cin>>Name;


search(head,last);
system("CLS");
break;
case '9':reverse(head,last);
break;

case '3':showlist(head);


system("color e");

break;



case'5':cout<<"Here you will Write Three times City Info! To be printed in File "<<static_cast<char>(2)<< endl;



{

ofstream outfile;
outfile.open("OurCity.txt",ios::out);
int num=1;
while(num<=3){

cout<<"Enter the City name "<<endl;
cin>>Name;
outfile<<"City name :"<<Name<<endl;
cout<<"Now Enter the Address of the City"<<endl;
cin>>address;
outfile<<"City Address :"<<address<<endl;
cout<<"Enter the Population "<<endl;

cin>>population;
outfile<<"Population is:"<<population<<endl;
cout<<"Zipcode :"<<endl;
cin>>zipcode;
outfile<<"Here is the Zipcode "<<zipcode<<endl;
num++;
}

outfile.close();


}
break;
system("CLS");
default:cout <<"Exit"<<endl;

}
}
while(choice!='0');
{

system("color f7");
cout<<"****** * * ******* ****** * * ******* "<<endl;
cout<<"* * * * * * * * * * "<<endl;
cout<<"* * * * * * * * * * "<<endl;
cout<<"* * *** ******* * * *** ******* "<<endl;
cout<<"* * * * * * * * "<<endl;
cout<<"* * * * * * * * "<<endl;
cout<<"****** * ******* ****** * ******* "<<endl;

system("PAUSE");
}

return 0;


}





Aucun commentaire:

Enregistrer un commentaire