C + + realizes scenic information management system

Source: Internet
Author: User

                                   Scenic Information Management System


The simple information management system of scenic spot has realized:

1.1 Setting the main application menu option

The main application menu option contains all the functions implemented, and the option is selected with a digital ID, and other error inputs can be distinguished, prompting for errors.

1.2 The output of the map of the creation level of tour guide route map

The adjacency linked list is used to store the information of the map of the scenic spots, and the neighboring list of the graphs (with weights and no direction). Output scenic Spots distribution map (adjacency matrix). The weights of the edges in the figure ∞ are represented by 32767.

1.3 Output Guide route map

Tourism information Management system in the scenic spot guide Route strategy, first by traversing the attractions, give an entrance attraction, set up a guide route map, guide Route map with a map.

1.4 outputs whether there is a circuit in the Guide route map

In the tourist information management system of scenic spot, after creating a good guide road map, judge whether there is a loop in the graph.

1.5 Find and Sort

L Search function: can be based on the user input keywords to find attractions, keywords can be in the name of the attractions can also be in the introduction of attractions. Find success then return to the relevant introduction of the attraction, if the search is not successful please give the correct prompt.

L sorting function: According to the popularity of attractions, the branch of the attraction to sort and print out the sort order.

1.6 outputs the shortest path and shortest distance between two attractions

Find the shortest path and shortest distance between the two attractions, and output road construction plan. The algorithm uses the Dijkstra algorithm.

1.7 output road building planning diagram

Road construction first of all to ensure that all the attractions, but also to spend the least cost.

1.8 Export and exit information for vehicles

1.8.1 Specific requirements:

The parking lot is a car that can park n cars, and there is only one door for cars to enter and exit. The car in the parking lot according to the order of arrival time of the vehicle, in order, if the yard is already full of n vehicles, later the car can only wait on the sidewalk outside the door, once there is a car, the first car on the sidewalk can be opened; When a car in the parking lot leaves, the vehicle after it must exit the yard to make way for it. When the vehicle leaves the gate, other vehicles enter the depot in the original order, and each car parked in the depot must pay the fee for the length of time it has to leave the car park. Output the parking space after each vehicle arrives (parking lot or sidewalk), and the cost of the car leaving the car park and the time it stays in the parking lot.

1.8.2 the management process for the parking lot is as follows:

A. When the vehicle is entering the parking lot, check that the car park is full and if it is not full, the vehicle enters the parking lot and if the parking lot is full, the vehicle will be waiting on the sidewalk.

B. When the vehicle requests a stack, let the vehicle that enters the car park after it exits the parking lot to make way for it, and then let the car out of the parking lot, and then enter the parking lot in the same order as it originally entered the parking lot. After that, check to see if there is a car waiting on the sidewalk, and a car to let the first waiting car into the parking lot.

1.8.3 Vehicle Access Checklist:

Each set of input data includes three data items: vehicle "arrival" or "leave" information, car license number, and time of arrival or departure. The output information for each set of input data is as follows: If the vehicle arrives, it will output the parking position of the car in the parking lot or on the sidewalk, and if the vehicle leaves, the time of the car's stay in the parking lot and the fee payable (the time of stay on the sidewalk is not charged).

1.9

Exit the entire program.





#include <iostream> #include <fstream> #include <time.h> #include <stdio.h> #include < cstring> #include <iomanip> #include <stack> #include <queue> #define MAX 20#define MAX2 2#define INFINITY 32767int arr1[max][max];using namespace std;double arr[max][max];class arcnode {public:int Adjvex; Arcnode *nextarc;double weight;}; Class Vnode {public:string data1;string data2;int wel;bool wc;bool rest; Arcnode *firstarc;}; Class Algraph {Public:vnode *vertices;int vexnum, Arcnum; Arcnode *arcnode;}; Class Zanlind{public:int number;int hour;int minute;}; int Locatevex (algraph G, string v) {int i; for (i = 0; v! = g.vertices[i].data1 && i < g.vexnum; i++); if (i >= G.vexnum) Return-1;return i;} int Locatew (algraph G, int wel) {int i;for (i = 0; Wel! = G.vertices[i].wel && i < g.vexnum; i++); if (I >= g.v Exnum) Return-1;return i;} void Createudn (Algraph &g) {g.arcnode=new Arcnode[max]; G.vertices=new vnode[max];fstream file ("Info.txt");File.fail ()) {cout << "error open!" << Endl;} Int J; Arcnode *s, *t;cout<< "Please enter the number of vertices and the number of edges:"; Cin>>g.vexnum>>g.arcnum;int i=0;cout<<endl;while (! File.eof ()) {file >>g.vertices[i].data1>>g.vertices[i].data2 >> g.vertices[i].wel>> g.vertices[i].rest>>g.vertices[i].wc; G.vertices[i].firstarc = null;i++;} Cout<<endl;fstream file1 ("Edge.txt"), if (File.fail ()) {cout << "error open!" << Endl;} while (!file1.eof ()) {int weight;string v1, v2;file1>>v1>>v2>>weight;int i = Locatevex (G, v1); int J = Lo Catevex (G, v2); s = new Arcnode (); t = new Arcnode (); S->adjvex = J;s->nextarc = G.vertices[i].firstarc;s->weight=w Eight G.vertices[i].firstarc =s;t->adjvex = I;t->nextarc = g.vertices[j].firstarc;t->weight=weight; G.vertices[j].firstarc =t;} File1.close (); File.close (); }void printadjlist (algraph &g) {cout<< "The following is the graph's adjacency list output:" <<endl; Arcnode *p;cout<< "numbering" << "vertices" << "adjacent edge numbers""<<endl;for (int i = 0; i < G.vexnum; i++) {cout<< "" <<i<< "" <<g.vertices[i].data1;for (p = g.vertices[i].firstarc; P p = p->nextarc) cout<< "--------->" &LT;&LT;P-&GT;ADJVEX;COUT&LT;&LT;ENDL;} void Outputgraph (algraph G) {cout<< "Below is the adjacency matrix output of the graph:" <<endl;int m1=g.vexnum;int m2=g.vexnum;for (int i=0; i <m1; i++) {for (int j=0; j<m2; J + +) {arr[i][j]=32767;}} for (int k=0; k<m1; k++) {arcnode *p=g.vertices[k].firstarc;for (int i2=0; i2<m2; i2++) {if (k==i2) {arr[k][i2]=0;} if (p) {Arr[k][p->adjvex]=p->weight;p=p->nextarc;}}} cout<< ""; for (int n1=0; n1<m1; n1++) {cout<<setiosflags (ios::left) &LT;&LT;SETW (one) <<g.vertices[n1].data1;} cout<<endl;for (int n2=0; n2<m1; n2++) {cout<<setiosflags (ios::left) &LT;&LT;SETW (<<) g.vertices[n2].data1;for (int n3=0; n3<m1; n3++) {cout<<setiosflags (ios::left) &LT;&LT;SETW (Ten) <<arr[ N2][N3];} Cout<<endl;}} BOOL Visited[max];stack<int> *s=new stack<int> (); bool Isover (Algraph g,bool A[max]) {for (int i=0; i<g.vexnum; i++) {if (a[i]!=1) {RET Urn false;}} return true;} void Dfstraverse (Algraph G) {bool Sta[20];int v;for (v = 0; v<g.vexnum; v++) {sta[v] =true;} stack<int>status; int n=0; int num =-1; int PK; Arcnode *e; cout << g.vertices[0].data1 << "--"; Sta[0] =false; Status.push (0); int AA, BB; AA = 0; while (n < g.vexnum-1) {e = NULL; num = Status.top (), E = G.vertices[num].firstarc; while (e) {if (Sta[e->adjvex] = = False) {e = e->nextarc;} else{status.push (E->adjvex); cout << g.vertices[e->adjvex].data1<< "- > "; AA = e->adjvex; Sta[e->adjvex] = false; n++; Break }} if (E = = NULL) {pk = status.top (); bb = pk; if (aa! = bb) {cout << g.vertices[pk].data1<< "; } status.pop (); } if (status.top () = = 0) {cout << g.vertices[0].data1 << ";}} cout << Endl;} BOOL Isedge (Algraph G) {string S1, s2;cin>&Gt;s1>>s2;int Ia=locatevex (G,S1); int Ja=locatevex (G,S2); Arcnode *p=g.vertices[ia].firstarc;while (P) {if (P->adjvex==ja) {return 1;} else {P=p->nextarc;}} return 0;} int adjlist[max];void findindegree (algraph &g) {int i; Arcnode *p;for (i=0; i<g.vexnum; i++) adjlist[i]=0;for (i=0; i<g.vexnum; i++) {p=g.vertices[i].firstarc;while (p) { adjlist[p->adjvex]++;p =p->nextarc;}}} void Judgecir (Algraph g) {Findindegree (g); int count=0;int q[max];int front,rear,v;front=rear=-1;for (int i=0; i< G.vexnum; i++) {if (adjlist[i]==0) | | | (adjlist[i]==1)) {q[++rear]=i;count++;}} while (front!=rear) {v=q[++front];if (adjlist[v]==1) {adjlist[v]=-1;for (int j=0; j<g.vexnum; J + +) {if (arr[v][j]> 0 && arr[v][j]<32767) {adjlist[j]--;if (adjlist[j]==1) {q[++rear]=j;count++;}}}} else {adjlist[v]=-1;}} if (count<g.vexnum) {cout<< "There are loops in the graph" &LT;&LT;ENDL;} elsecout<< "No loops in the graph" &LT;&LT;ENDL;} int in[max];void LocateVex2 (algraph G, String v) {for (int i = 0;i < MAX; i++) {in[i]=10000;} for (int i = 0;i < G.vexnum; i++) {if (G.vertices[i].data1.find (v) <g.vertices[i].data1.length () | | G.vertices[i].data2.find (v) <g.vertices[i].data2.length ()) {in[i]=i;}} }void Search (algraph g,string s) {findindegree (G); LocateVex2 (G, s); for (int i=0;i<g.vexnum;i++) {if (in[i]!=10000) {cout<< "You are inquiring about the attractions described as:" <<endl<< endl<< "The name of the attraction is:" <<G.vertices[in[i]].data1<< "<<endl<<" The description of the attraction is: "<<g.vertices[ in[i]].data2<<endl<< "The attraction is:" <<G.vertices[in[i]].wel<<endl<< "there is no seating area for:" << g.vertices[in[i]].rest<<endl<< "There is no toilet for:" <<g.vertices[in[i]].wc<<endl<<endl;}}} void Sortwel (Algraph G) {int ary[g.vexnum];for (int i=0; i<g.vexnum; i++) {Ary[i]=g.vertices[i].wel;} int I, J, Tmp;for (i=0; i<g.vexnum; i++) {tmp = Ary[i];for (j=g.vexnum-1; j>i; j--) {if (TMP < ARY[J]) {Ary[i] = ary [J];ary[j] = Tmp;tmp = Ary[i];}}} for (int j=0; j<g.vexnum; J + +) {int m=locatew (g,ary[j]);cout<<j+1<<"," <<g.vertices[m].data1<<endl;}} BOOL Isinn (algraph g,int a[max],int N) {for (int i=0;i<g.vexnum;i++) {if (a[i]==n) {return true;}} return false;} void Sortn (Algraph G) {int ary[g.vexnum];int a[g.vexnum];for (int j=0; j<g.vexnum; J + +) {a[j]=10000;} Findindegree (G); for (int i=0; i<g.vexnum; i++) {ary[i]=adjlist[i];} int I, J, Tmp;for (i=0; i<g.vexnum; i++) {tmp = Ary[i];for (j=g.vexnum-1; j>i; j--) {if (tmp <= ary[j]) {a[i]=j;ary[ I] = ary[j];a[i]=j;ary[j] = Tmp;tmp = Ary[i];}}} for (int j=0;j<g.vexnum;j++) {for (int i=0;i<g.vexnum;i++) {if (Ary[j]==adjlist[i]) {if (!isinn (g,a,i)) {a[j]=i;} else{continue;}}}} for (int i=0;i<g.vexnum;i++) {cout<<i+1<< "," <<g.vertices[a[i]].data1<<endl;}} void Shortestpath_dij (Algraph g,int v0, int p[][max], int d[]) {int V, W, I, J, Min;bool Final[10];for (v=0; v<g.vexnum;) v++) {final[v]=false;d[v]=arr[v0][v];for (w=0; w<g.vexnum; w++) p[v][w]=-1;if (d[v]<infinity) {p[v][0]=v0;p[v][ 1]=v;}} D[v0]=0;final[v0]=true;for (I=1; i<g.vexnum; i++) {min=infinity;for (w=0; w<g.vexnum; w++) if (!final[w] && d[w]<min) {v=w;min=d[w];} Final[v]=true;for (w=0; w<g.vexnum; w++) {if (!final[w] && min<infinity && arr[v][w]<infinity & amp;& (Min+arr[v][w]<d[w])) {d[w]=min+arr[v][w];for (j=0; j<g.vexnum; J + +) {p[w][j]=p[v][j];if (p[w][j]==-1 {P[w][j]=w;break;}}}}} BOOL Isinve (algraph g,string va) {for (int i=0;i<g.vexnum;i++) {if (G.vertices[i].data1==va) {return true;}} return false;} void Printshortestpath (Algraph G) {int ia,ja;string s1,s2;int p[max][max];int d[max];cout<< "Please enter the name of the two attractions to be queried:"; Cin>>s1>>s2;if (Isinve (G,S1) && isinve (g,s2)) {Ia=locatevex (G,S1); Ja=locatevex (G,S2); Shortestpath_dij (G,ia, p, D);cout<< "The shortest path and length to each vertex are:" <<endl;if (ja!=0 && d[ja]!=infinity) {cout << "Shortest path:"; for (int j=0; j<g.vexnum; J + +) {if (p[ja][j]>-1) cout<<g.vertices[p[ja][j]].data1< < "";} cout<<endl;cout<< "The shortest distance is:" <<d[ja];} else if (d[ja]==infinity) cout<<g.vertices[ia].data1<< "-" <<G.vertices[jA].data1<< ":" < < "unreachable" &LT;&LT;ENDL;} else{cout<< "The name of the attraction you entered does not exist, please enter the correct spot name:" <<endl;printshortestpath (G);}} void Prim (Algraph g,int v,double Arr[max][max]) {int lowcost[max];int min;int closest[max],i,j,k;for (i=0; i<G.vexnum ; i++) {lowcost[i]=arr[v][i];closest[i]=v;} for (I=1; i<g.vexnum; i++) {min=infinity;for (j=0; j<g.vexnum; J + +) {if (lowcost[j]!=0&&lowcost[j]<min ) {min=lowcost[j];k=j;}} cout<< "from" <<G.vertices[closest[k]].data1<< "to" <<G.vertices[k].data1<< "fix a Road" < <endl;lowcost[k]=0;for (j=0; j<g.vexnum; J + +) {if (arr[k][j]!=0 && arr[k][j]<lowcost[j]) {lowcost[j]= arr[k][j];closest[j]=k;}}}} Stack<zanlind> parking; Stack<zanlind> cars; Queue<zanlind> waits;int z[max2];bool Isinzan (int zan[],int number) {for (int i=0;i<max2;i++) {if (zan[i]== Number) {return true;}} return false;} int indexz (int z[],iNT N) {for (int i=0;i<max2;i++) {if (z[i]==n) {return i;}} return-1;} void Goin () {int k1=0;zanlind zan;cout<< "license plate number:"; cin>>zan.number;cout<<endl;/*time_t t = time (0); Char tmp[64]; Strftime (tmp,sizeof (TMP), "%x", LocalTime (&t)) zan.time=tmp;*/struct TM *newtime;time_t Long_time;time (& Long_time); Get time as Long integernewtime = LocalTime (&long_time); int h = newtime->tm_hour;//Gets the current time of the hour int m = newtime->tm_min;//Gets the current time of the minute zan.hour=h;zan.minute=m;cout<< " The entry time is: "; if (zan.minute>=1 && zan.minute<10) {cout<<zan.hour<<": 0 "<<zan.minute< <endl;} else{cout<<zan.hour<< ":" <<zan.minute<<endl;} if (Parking.size () <max2) {for (int m=0;m<max2;m++) {if (z[m]==0) {z[m]=zan.number;break;}} Parking.push (Zan);cout<< "The car has entered the parking lot at:" <<k1++<< "Lane";} else{cout<< "The parking lot is full, please wait for other vehicles to leave:"; Waits.push (Zan);} void Goout () {if (Parking.size () <=0) {cout<< "Parking is empty, no car to leave! ";} else {cout<< "Please enter your license plate number:";NT Number;cin>>number;if (Isinzan (Z,number)) {while (Parking.top (). Number!=number) {Cars.push (Parking.top ()); Parking.pop ();} int Num=indexz (Z,parking.top (). number), z[num]=0;/*time_t t = time (0); Char tmp[64]; Strftime (tmp,sizeof (TMP), "%x", LocalTime (&t)); */struct TM *newtime;time_t long_time;time (&long_time); Get time as Long integernewtime = LocalTime (&long_time); int h = newtime->tm_hour;//Gets the current time of the hour int m = newtime->tm_min;//Gets the current time of the minute cout<< "the license plate number is:" <<parking.top ( .number<< "car to leave" <<endl << "Parking Time:" << (h*60+m)-(Parking.top (). Hour*60+parking.top (). minute) << "minutes" <<endl << "parking fee is:" << ((h*60+m)-(Parking.top (). Hour*60+parking.top (). minute)) *5<< "Yuan" <<endl; Parking.pop (); while (!cars.empty ()) {Parking.push (Cars.top ()); Cars.pop ();} while (Parking.size () <max2) {if (Waits.size ()!=0) {for (int m=0;m<max2;m++) {if (z[m]==0) {z[num]=waits. Front (). number;}} Parking.push (wAits.front ()); Waits.pop ();} Else{break;}} }else{cout<< "There is no such car! Please enter the correct license plate number: "<<endl;}}} void Parkinglot () {r2:cout<<endl<< "* * Car park Management Program * *" <<endl<< "--------------------- -----------------------------"<<endl<<" * * << "* *---car parking D---Car exit E---withdrawal procedure * *" <<endl < < "--------------------------------------------------" <<endl<< "Please select: <a, D, e>:"; char choose; Cin>>choose;if (choose== ' a ' | | choose== ' d ' | | choose== ' E ') {switch (choose) {case ' a ': goin (); goto R2;case ' d ': goout (); goto r2;case ' E ': Break;}} else{cout<< "Your input is incorrect, please enter one of the <a D e>. "; goto R2;}} int main () {int i, j;int IAA; Algraph *g=new algraph (); int Choose=0;cout<<endl;while (TRUE) {r:cout<< "------------------------------- -----------"<<endl <<" Welcome to use the scenic Information management system "&LT;&LT;ENDL << * * * * * * * * * * * * * * * * "<<endl <<"------------------------------------------"&LT;&LT;endl << "1, create scenic spots distribution map" <<endl << "2, output scenic spots distribution map" <<endl << "3, Output Guide route map" <<endl << "4, Output guide circuit map of the loop" <<endl & lt;< "5, Find and sort" <<endl << "6, ask for the shortest route and shortest distance between two attractions" <<endl << " 7, Output road construction plan "<<endl <<" 8, car parking vehicle access record information "<<endl <<" 0, exit system "<<endl <<" Please enter the menu item you want to select: "; Cin>>choose;if (choose<=8 && choose>=0) {if (choose>1 && g->vexnum==0 && choose!=8) {cout<<endl<< "************ your diagram is empty, first create your diagram **********:" <<endl<<endl;goto r;} else { Switch (choose) {case 1:CREATEUDN (*g); Break;case 2:printadjlist (*g); Cout<<endl;outputgraph (*g); Break;case 3: cout<< "guide route:";//creattoursortgraph (*g);//dfstraverse (*g); Break;case 4:judgecir (*g); break;case 5:while (true) {int ch;cout<< "you need" << "find (0)," << "Sort by popularity (1)," << "sort by the points of Attraction (2)," << "Exit this directory ( 3): "; cin>>ch;string sa;switch (CH) {Case 0:;cout<<" Please enter the keywords you want to find about the sights: ";cin>>sa; Search (*G,SA); Break;case 1:sortwel (*g); Break;case 2:sortn (*g); Break;case 3:goto r;default:cout<< "Your input is wrong, Please re-enter: "<<endl;}} Case 6:printshortestpath (*g); Break;case 7:prim (*g,0,arr); break;case 8:parkinglot (); Break;case 0:exit (0);}} Cout<<endl;} else {cout<< "Your input is wrong, please re-enter the number between 0-8" &LT;&LT;ENDL;}} return 0;}

  

C + + realizes scenic information management system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.