📄 assignment2.cpp
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body,td,p,th{font-size:14px;line-height:180%;}
input{font-size:12px;}
-->
</style>
<title></title>
<script language=javascript src="http://mimg.163.com/jsstyle/js/readletter.js"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" border=0>
<pre style="width:100%;white-space:normal;word-wrap:break-word">// Assignment2.h
// Written by Robert Ollington, 14/11/05
#include <iostream>
#include "Map.h"
#include "Town.h"
#include "Connection.h"
int main(){
int i,j; //loop counters;
Map* map; // the map
// temporary storage for towns and connections
Town* town;
Connection* conn;
// first get the number of towns and create the map
int numTowns;
cin >> numTowns;
map = new Map(numTowns);
// now set up towns
char buffer[100]; // buffer for town name
char* townName; // temp storage for town name
for (i=0; i<numTowns; i++){
// get the name and copy to new string
cin >> buffer;
townName = new char[strlen(buffer)+1];
strcpy(townName,buffer);
// create a town with this name and add it to the map
town = new Town(townName);
map->setTown(i,town);
}
// now set up the connections
for (i=0; i<numTowns-1; i++){ // the town to connect from
for (j=i+1; j<numTowns; j++){ // the town to connect to
// read the dist
int dist;
cin >> dist;
// if the connection is possible, create and add it to the map
if (dist != -1){
conn = new Connection(j,dist);
map->getTown(i)->addConn(conn);
}
}
}
// run Prim's algorithms, which will output the results
map->prim();
// delete the map
delete map;
// NOTE: the map destructor will be responsible for deleting all other objects
return 0;
}
</pre>
</body>
</html>
<!-- CoreMail Version 2.5 Copyright (c) 2002-2005 www.mailtech.cn -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -