Curriculum design of Campus guide system data structure

Source: Internet
Author: User
Tags printf stdin

Curriculum design of Campus guide system data Structure

Campus Guide System of old campus of Zhengzhou Normal University

awkward shortest-Path algorithm

Floyd and Dijkstra

awkward data Structure ...


record the code:

There are many references .....

#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #define MaxSize #define VISITED 1 #define notvisited 0 #define Infinite 1073741823 #define MAXVIEWNUM 50 * * Number of attractions most          Big 50*/#define MAXROAD 1000/* Define the path to infinity */#define N 16/* Current number of attractions */typedef struct {char name[30];        /* Attraction name */char number[10];    /* Attraction code */char introduce[200];                  /* Introduction to Attractions * *}ELEMTYPE;              /* Attractions Information */typedef struct {int num;        /* Attraction number */elemtype date;                    /* Attractions Information */}view;         /* Define Attractions */typedef struct {View view[maxviewnum];  /* A one-dimensional array of vertices, and the array unit 0th does not use the */int length[maxviewnum][maxviewnum];
/* Store path length */int m,n;

}mgraph;              Mgraph MGr;     /* global variable, define MGR as Mgraph type */int shortest[maxviewnum][maxviewnum];         /* Define global variable Storage minimum path */int path[maxviewnum][maxviewnum];
    /* Define Storage Path */void init () {int i,j;
    Mgr.view[1].num=1; strcpy (Mgr.view[1]. Date.name, "school Front door");
    strcpy (Mgr.view[1].date.number, "001"); strcpy (Mgr.view[1].date.introduce, "located in the Avenue of excellence, opposite for the country-based life Park, bustling city, convenient transportation."
	
    ");
    mgr.view[2].num=2;
    strcpy (Mgr.view[2].date.name, "Administrative building");
    strcpy (Mgr.view[2].date.number, "002"); strcpy (Mgr.view[2].date.introduce, "school leader, office building.
	
    ");
    mgr.view[3].num=3;
    strcpy (Mgr.view[3].date.name, "teaching area");
    strcpy (Mgr.view[3].date.number, "003"); strcpy (Mgr.view[3].date.introduce, "No. 1-5 School building, contains the school of information and chemistry, physics, etc.
	
    ");
    mgr.view[4].num=4;
    strcpy (Mgr.view[4].date.name, "Swan L.");
    strcpy (Mgr.view[4].date.number, "004"); strcpy (mgr.view[4].date.introduce, "Zhengzhou Normal University, a major attraction of the old campus, black and White swan, water blend."
	
    ");
    mgr.view[5].num=5;
    strcpy (Mgr.view[5].date.name, "library");
    strcpy (Mgr.view[5].date.number, "005"); strcpy (Mgr.view[5].date.introduce), "A long history, cultural accumulation." For students to quiet learning environment.
	
    ");
    mgr.view[6].num=6;
    strcpy (Mgr.view[6].date.name, "The Land of Art");
    strcpy (Mgr.view[6].date.number, "006"); strcpy (Mgr.view[6].date.introduce), "Academy of Fine Arts and music and dance, leads to the palace of art."
	
  ");  mgr.view[7].num=7;
    strcpy (Mgr.view[7].date.name, "sports field");
    strcpy (Mgr.view[7].date.number, "007"); strcpy (Mgr.view[7].date.introduce, "green Land, Activity Center.") Basketball court, football field, tennis court in turn, enrich the extracurricular life.
	
    ");
    mgr.view[8].num=8;
    strcpy (Mgr.view[8].date.name, "Restaurant");
    strcpy (Mgr.view[8].date.number, "008"); strcpy (Mgr.view[8].date.introduce, "restaurant, there are ethnic restaurants free boiling room, old campus where the students eat."
	
    The food is delicious ... ");
    mgr.view[9].num=9;
    strcpy (Mgr.view[9].date.name, "School Hospital");
    strcpy (Mgr.view[9].date.number, "009"); strcpy (Mgr.view[9].date.introduce, "School hospital, the students take medicine to the place, to provide convenience."
	
    ");
    mgr.view[10].num=10;
    strcpy (Mgr.view[10].date.name, "Old Campus Simon");
    strcpy (Mgr.view[10].date.number, "010"); strcpy (Mgr.view[10].date.introduce, "Simon went out to the cultural road, opposite the Henan Animal Husbandry Economics College."
	
    ");
    mgr.view[11].num=11;
    strcpy (Mgr.view[11].date.name, "Special Education Institute");
    strcpy (Mgr.view[11].date.number, "011"); strcpy (Mgr.view[11].date.introduce, "Special Education Institute, which is mostly deaf and dumb, provides a suitable and equal teaching place for every student."
	
    ");
    mgr.view[12].num=12;
    strcpy (mgr.view[12].date.name, "student Apartment"); strcpy (MGR.view[12].date.number, "012"); strcpy (mgr.view[12].date.introduce, "student dormitory area, where building 8th is a female dormitory, building 9th is a boys ' dormitory."
	
    ");
    mgr.view[13].num=13;
    strcpy (Mgr.view[13].date.name, "Zhengzhou Museum of Nature");
    strcpy (Mgr.view[13].date.number, "013"); strcpy (Mgr.view[13].date.introduce, "Zhengzhou Nature Museum, located in Zhengzhou Normal University, the old campus northwest corner, a long history."
	
    ");
    mgr.view[14].num=14;
    strcpy (Mgr.view[14].date.name, "Primary teaching building");
    strcpy (Mgr.view[14].date.number, "014"); strcpy (Mgr.view[14].date.introduce, "The primary School of elementary education, the place where students attend daily classes.
	
    ");
    mgr.view[15].num=15;
    strcpy (Mgr.view[15].date.name, "Zhongzhou North Gate");
    strcpy (Mgr.view[15].date.number, "015"); strcpy (Mgr.view[15].date.introduce, "adjacent to the University of Zhongzhou North Gate, go out for Kaiyuan Road, right to go straight to the new campus of Zhengzhou Teachers College."
	
    ");
    mgr.view[16].num=16;
    strcpy (Mgr.view[16].date.name, "Zhongzhou University teaching Area");
    strcpy (Mgr.view[16].date.number, "016"); strcpy (Mgr.view[16].date.introduce), "This area is the teaching area of Zhongzhou University.
	
    ");
        for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {mgr.length[i][j]=maxroad;
}} for (i=1;i<=n;i++) {shortest[i][j]=0;    } mgr.length[1][2]=mgr.length[2][1]=50;
    mgr.length[2][3]=mgr.length[3][2]=50;
    mgr.length[3][4]=mgr.length[4][3]=60;
    mgr.length[3][5]=mgr.length[5][3]=100;
    mgr.length[5][6]=mgr.length[6][5]=100;
	mgr.length[6][7]=mgr.length[7][6]=220;
    mgr.length[6][9]=mgr.length[9][6]=80;
    mgr.length[7][8]=mgr.length[8][7]=250;
	mgr.length[8][9]=mgr.length[9][8]=100;
    mgr.length[8][10]=mgr.length[10][8]=150;
    mgr.length[9][11]=mgr.length[11][9]=50;
    mgr.length[10][11]=mgr.length[11][10]=60;
    mgr.length[11][12]=mgr.length[12][11]=40;
	mgr.length[12][13]=mgr.length[13][12]=50;
    mgr.length[13][14]=mgr.length[14][13]=20;
	mgr.length[11][14]=mgr.length[14][11]=80;
	mgr.length[16][14]=mgr.length[14][16]=500;
	mgr.length[13][15]=mgr.length[15][13]=450;
    mgr.length[2][16]=mgr.length[16][2]=150;
    mgr.length[1][1]=mgr.length[2][2]=mgr.length[3][3]=mgr.length[4][4]=0;
    mgr.length[5][5]=mgr.length[6][6]=mgr.length[7][7]=mgr.length[8][8]=0; mgr.length[9][9]=mgr.length[10][10]=mgr.length[11][11]=mgr.length[12][12]=0;
mgr.length[13][13]=mgr.length[14][14]=mgr.length[15][15]=mgr.length[16][16]=0;
    } void introduce () {int m;
    printf ("Please enter enquiry number: \ n"); scanf ("%d", &m);
    Fflush (stdin);
		Switch (m) {case 1:printf ("Attraction No.:%s\t", mgr.view[1].date.number);
		printf ("Attraction name:%s\n", mgr.view[1].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[1].date.introduce);
	Break
		Case 2:printf ("Attraction No.:%s\t", mgr.view[2].date.number);
		printf ("Attraction name:%s\n", mgr.view[2].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[2].date.introduce);
	Break
		Case 3:printf ("Attraction No.:%s\t", mgr.view[3].date.number);
		printf ("Attraction name:%s\n", mgr.view[3].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[3].date.introduce);
	Break
		Case 4:printf ("Attraction No.:%s\t", mgr.view[4].date.number);
		printf ("Attraction name:%s\n", mgr.view[4].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[4].date.introduce);
	Break
		Case 5:printf ("Attraction No.:%s\t", mgr.view[5].date.number); printf ("Attractions Name:%s\n", Mgr.view[5].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[5].date.introduce);
	Break
		Case 6:printf ("Attraction No.:%s\t", mgr.view[6].date.number);
		printf ("Attraction name:%s\n", mgr.view[6].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[6].date.introduce);
	Break
		Case 7:printf ("Attraction No.:%s\t", mgr.view[7].date.number);
		printf ("Attraction name:%s\n", mgr.view[7].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[7].date.introduce);
	Break
		Case 8:printf ("Attraction No.:%s\t", mgr.view[8].date.number);
		printf ("Attraction name:%s\n", mgr.view[8].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[8].date.introduce);
	Break
		Case 9:printf ("Attraction No.:%s\t", mgr.view[9].date.number);
		printf ("Attraction name:%s\n", mgr.view[9].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[9].date.introduce);
	Break
		Case 10:printf ("Attraction No.:%s\t", mgr.view[10].date.number);
		printf ("Attraction name:%s\n", mgr.view[10].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[10].date.introduce);
	Break
		Case 11:printf ("Attraction No.:%s\t", mgr.view[11].date.number);
		printf ("Attraction name:%s\n", mgr.view[11].date.name); printf ("Introduction to Attractions:%s\n", Mgr.view[11].date.introduce];
	Break
		Case 12:printf ("Attraction No.:%s\t", mgr.view[12].date.number);
		printf ("Attraction name:%s\n", mgr.view[12].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[12].date.introduce);
	Break
		Case 13:printf ("Attraction No.:%s\t", mgr.view[13].date.number);
		printf ("Attraction name:%s\n", mgr.view[13].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[13].date.introduce);
	Break
		Case 14:printf ("Attraction No.:%s\t", mgr.view[14].date.number);
		printf ("Attraction name:%s\n", mgr.view[14].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[14].date.introduce);
	Break
		Case 15:printf ("Attraction No.:%s\t", mgr.view[15].date.number);
		printf ("Attraction name:%s\n", mgr.view[15].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[15].date.introduce);
	Break
		Case 16:printf ("Attraction No.:%s\t", mgr.view[16].date.number);
		printf ("Attraction name:%s\n", mgr.view[16].date.name);
		printf ("Introduction to Attractions:%s\n", mgr.view[16].date.introduce);
	Break default:printf ("Input ordinal error.
		\ n ");
    Break
} printf ("\ n");
    } void Floyd ()/* Freud algorithm */{int i,j,k; for (i=1;i<=n;i++{for (j=1;j<=n;j++) {shortest[i][j]=mgr.length[i][j];
		path[i][j]=0; }}/* Initialize array */for (k=1;k<=n;k++) {for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {if (shortest I
					[j]> (Shortest[i][k]+shortest[k][j])) {shortest[i][j]=shortest[i][k]+shortest[k][j];
					Path[i][j]=k;   Path[j][i]=k; /* Record path through */}//end_if}}//end_for}} void display (int i,int j) {/* Print the path and shortest path of two attractions */int A, A, b
    ;
    A=i;
    B=j;
    printf ("The shortest route between the two attractions you're inquiring about is: \ n");
	Fflush (stdin);
		if (i<j) {printf ("%d", b);
			while (path[i][j]!=0) {printf ("<--%d", Path[i][j]);
			if (i<j) j=path[i][j];
		else I=path[j][i];
		} printf ("<-%d\n\n", a); The shortest path to printf ("%d->%d" is:%d meters.
	\ n ", A,b,shortest[a][b]);
		} else {printf ("%d", a);
			while (path[i][j]!=0) {/* All the passes on the path I to J are printed out sequentially */printf ("-->%d", Path[i][j]);
			if (i<j) j=path[i][j];
		else I=path[j][i]; } printf ("->%d\n\n", b); The shortest path to printf ("%d->%d" is:%d meters.
	\ n ", A,b,shortest[a][b]);
    }}/*display*/int Shortdistance () {/* The shortest path of the two attractions to find */int i,j; printf ("Please enter the number of the two attractions to be queried (1->16) in the middle of the space between the spaces."
    \ n ");
    scanf ("%d%d", &i,&j); if (i>n| | i<0| | j>n| | j<0) {printf ("Input information error.
		\ n "); printf ("Please enter the number of the two attractions to be queried (1->16) in the middle of the space between the spaces."
		\ n ");
    scanf ("%d%d", &i,&j);
		} else {Floyd ();
    Display (I,J);
    } return 1;
Fflush (stdin);   }/*shortestdistance*/int a[maxsize+1][maxsize+1];
/* Dijkstra algorithm */int d[maxsize+1];
int s[maxsize+1],p[maxsize+1];
int source,sink;
int step = 1;                    
int top =-1;   
         
int stack[maxsize+1];
	void input () {int i;
	printf ("\ n Please enter the starting node:");
	scanf ("%d", &source);
	printf ("\ n Please enter the end node:");
	
	scanf ("%d", &sink);                     
		for (i = 1; I <= N; i++) {s[i] = notvisited;      
		D[i] = Mgr.length[source][i];      
	P[i] = source;          
	} S[source] = visited; D[source] =0;
		} void Push (int value) {if (top >= MaxSize) {printf ("No path exists!\n\n");
	Exit (1);
} else Stack[++top] = value;
		} int Pop () {if (Top < 0) {printf ("No path exists!\n\n");
	Exit (1);
} return stack[top--];
	} int Mind () {int i,t=0;
	long int minimum = Infinite;
			for (i=1;i<=n;i++) if ((s[i] = = notvisited) && D[i] < minimum) {minimum = D[i];
		t = i;
} return t;
	
	} void Output_path () {int node = sink; if ((sink = = Source) | |
	(D[sink] = = Infinite)) {There is no path between printf ("\ n node%d and node%d).
		\ n ", Source,sink);
	Return
	
	} printf ("\ n");
		while (node! = Source) {Push (node);
	node = P[node];
	} printf ("v%d to v%d Shortest path: \ n", Source,sink);
	printf ("v%d", source);
		while (node! = sink) {node = Pop ();
		printf ("--%ld-->", mgr.length[P[node]][node]);
	printf ("v%d", node);
	} printf ("\ n");
	printf ("\ n%d->%d the shortest path is:%ld\n", Source,sink,d[sink]);
printf ("\ n");
	} void Distance () {int t,i;
	Input (); For (step =2;step <=N; Step++) {T = Mind ();
		
		S[t] = visited; for (I=1; I <= N; i++) if ((s[i] = = notvisited) && (D[t]+mgr.length[t][i] <= d[i])) {D[i] = D[t] + mgr.length[t][i]
				;
			P[i] = t;
}} output_path ();
	} void Map () {printf ("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
	printf ("┃┏━━━━━━━━┓┏━━━━━┓┏━━━━━━━┓┃\n");
	printf ("┃┃13 Nature Museum" ┃┃14. ┃━━━┫15. Zhongzhou North Gate ┣━┃\n ");
	printf ("┃┗━━━━━━━━┛┗━━━━━┛┗━━━━━━━┛┃\n");
	printf ("┃┃\n");
	printf ("┃┏━━━━━┓┃\n");      printf ("┃┃12.
	┃┏━━━━┓┃\n ");
	printf ("┃┃ student apartment ┃┃8. Restaurant ┃┃\n");
	printf ("┃┗━━━━━┛┗━━━━┛┃\n");                     printf ("┃┏━━━━━━━━━━━━━━┓┏━━━━┓       ┃\n "); printf ("┃┃11.
	Special Education Institute ┃┃9 School Hospital ┃┏━━━━━━┓┃\n ");       printf ("┃┗━━━━━━━━━━━━━━┛┗━━━━┛┃16.
	┃┃\n ");
	printf ("┃┏━━━━┓┃ Zhongzhou ┃┃\n");
	printf ("┃┃10. Simon ┃┃ Teaching Area ┃┃\n");
	printf ("┃┗━━━━┛┃┃┃\n");
	printf ("┃┏━━━━━━━━━┓┏━━━━━━┓┗━━━━━━┛┃\n");
	printf ("┃┃┃┃6 Academy of Fine Arts ┃┃\n");
	printf ("┃┃┃┃ and Conservatory of Music ┃┃\n"); printf ("┃┃7.
	Transport ┃┗━━━━━━┛┃\n ");
	printf ("┃┃┃┃\n");
	printf ("┃┃ dynamic ┃┏━━━━┓┃\n");     printf ("┃┃┃┃4.
	┃┃\n ");         printf ("┃┃ field ┃  ┃ Swan L. ┃┃\n ");
	printf ("┃┃┃┗━━━━┛┏━━━━━━┓┃\n");
	printf ("┃┃┃┃ figure ┃┃\n");  printf ("┃┃┃┏━━━━━┓┃5.
	Book ┃┃\n ");
	printf ("┃┃┃┃ 45th Building, ┃┃ Hall ┃┃\n");
	printf ("┃┗━━━━━━━━━┛┃━━━━━┃┗━━━━━━┛┃\n");
	printf ("┃┃, building 23rd, ┃┃\n");
	printf ("┃┃━━━━━┃┃\n");
	printf ("┃┃3. Building ┃┃\n");
	printf ("┃┗━━━━━┛┃\n");
	printf ("┃┃\n");
	printf ("┃┃\n"); printf ("┃┏━━━━━━━━━┓┏━━━━━┓┃\n "); printf ("┃┃2.
	Administrative building ┃━━━━━━━┫1. School front door ┣━━━━━━┃\n ");
	printf ("┃┗━━━━━━━━━┛┗━━━━━┛┃\n");
	printf ("┃┃\n");
    printf ("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
    printf ("\ n");
Fflush (stdin);
    }/*map*/int main () {char k;
	Init ();
	printf ("**********************************************************************\n");
	printf ("* *\n");
	printf ("* *\n");                     printf ("* Welcome to the old campus of Zhengzhou Normal University guide system!
	*\n ");
	printf ("* *\n");
	printf ("* *\n"); printf ("**********************************************************************\n");
    printf ("\ n");
		while (1) {printf ("1. Click on the" 1 "key for tourist attraction information); \ n");
		printf ("2. Site Shortest Path query (Freud algorithm) Please press" 2 "key; \ n");
		printf ("3. Site Shortest Path query (Dijkstra algorithm) Please press" 3 "key; \ n");	    
		printf ("4." Please press "4" key to check the map of the campus attractions. \ n ");
		printf ("5." Exit the system, press the "5" key; \ n ");
		printf ("Please select: \ n");
		
		scanf ("%c", &k); Switch (k) {case ' 1 ':p rintf (Please enter 1-16 for a description of the attraction).
			\ n ");
		Introduce (); break; Case ' 2 ':p rintf ("Attraction Shortest Path query (Freud algorithm).
			");
		Shortdistance (); break; Case ' 3 ':p rintf ("Attraction Shortest Path (Dijkstra algorithm) query.
			");
		Distance (); break; Case ' 4 ':p rintf ("attraction map.
			\ n ");
		Map (); break;
		Case ' 5 ':p rintf ("Thank you for using!\n"); exit (0);
	}} system ("Pause");
return 0;
 }


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.