一个在加拿大上学的朋友的暑假作业

本文介绍了一个用于维护大学健康中心患者信息的软件项目。该系统使用结构体数组存储患者数据,并提供了添加、删除、搜索患者等功能。此外,系统还能按姓氏排序显示所有患者,并列出特定医生的所有患者。

Learning Objectives of the Project
In this project, students will learn to work with files (streams), structures, arrays and arrays of structures, and definitely teamwork.

Group Work
Students are supposed to work in groups of 2 or 3 members. If you have any problem finding group members, please let the Professor know.

Description of the Project
In this project, you will write a software for the Campus Health Centre located at a university called YouOIT to maintain patients’ information.

The health centre maintains a master text file, called patients.txt that contains the names of all patients, their SIN number, patients’ doctor name, and doctor ID.  The following figure shows an example of how the file looks like:

First name       Last name       SIN         Doctor Name       Doctor ID
Dave                  Ramdin           100         Mike                        1
Lili                      Bega                101         Mike                        1
Joe                     Biden               103         Helen                     2
…                        ...                      ...            ...                    ...

NOTE: The file does not contain the titles.

Task
Your task for this project is to develop a software that would allow a nurse to:
Add new patient

Remove patient

Search for a patient by SIN

Print all patients sorted by last name

Print all patients cared by same doctor. For example, Dr. Mike, with ID: 1 has two patients

       Dave Ramdin        100 

       Lili Bega                 101 


Exit the program and save all the updates to the file

Your program should read the data file, and fill an array of structures (one structure for each patient), and perform all operations on the array of structures. When the user asks to exit the program, the master text file would be replaced with the content of the array. Further explanation of the project will be given in the tutorial on June 8, 2009.

+ - + - + - + - + - + - + - + - + - + - + - + - + - + - +

整个题目本来是有部分中文翻译的,但有好几处翻译不是很准确,容易让阅读的朋友产生误会,比如:

“Remove patient” 被翻译成了删除病人的名字,实际上应该是删除病人

“Print all patients sorted by last name”被翻译成了打印所有病人的姓,而实际上应该是按姓排序,打印出所有病人等等。为避免misunderstanding起见,干脆就去掉了那些中文。除此目的外,也想让正在学校读书的DDMM们感受一下国外的题目是什么样子的,顺带练习一下e文。

 

这个题目的绝对难度并不大。但有很多细节需要给予系统性的考虑。尽管在Learning Objectives of the Project并未言明,另外一个更重要的目标就是,让大家在软件设计能力方面得到一次锻炼的机会。

 

下面是我给那个朋友提供的参考代码,用到了较多的STL,正在学习STL的朋友,也可以参考一下。代码在VS2005中编译通过,其中还有一些很小的细节需要完善。望各位硕学先进指正!

 

+ - + - + - + - + - + - + - + - + - + - + - + - + - + - +

#include <iostream>

#include <fstream>

#include <string>

#include <list>

using namespace std;

 

// the structure of patient

struct Patient

{

public:

         // constructor

         Patient();

         // overloaded constructor

         Patient(string first_name, string last_name, int sin, string doctor_name, int doctor_id);

         // variable to hold the first name of a patient

         string first_name;

         // variable to hold the last name of a patient

         string last_name;

         // variable to hold the SIN of a patient

         int     sin;

         // variable to hold the doctor's name

         string doctor_name;

         // variable to hold the doctor's id.

         int doctor_id;

 

         // friend member functions will be used for sorting and other purposes

         friend bool operator<(const Patient& p1,const Patient& p2);

         friend bool operator>(const Patient& p1,const Patient& p2);

         friend bool operator==(const Patient& p1,const Patient& p2);

         friend bool operator!=(const Patient& p1,const Patient& p2);

};

 

Patient::Patient()

{

}

 

Patient::Patient(string first_name, string last_name, int sin, string doctor_name, int doctor_id)

{

         this->first_name = first_name;

         this->last_name = last_name;

         this->sin = sin;

         this->doctor_name = doctor_name;

         this->doctor_id = doctor_id;

}

 

bool operator<(const Patient& first, const Patient& second)

{

         unsigned int i=0;

         while((i<first.last_name.length()) && (i<second.last_name.length()))

         {

                   if (tolower(first.last_name[i])<tolower(second.last_name[i]))

                   {

                            return true;

                   }

                   else if (tolower(first.last_name[i])>tolower(second.last_name[i]))

                   {

                            return false;

                   }

                   ++i;

         }

         if (first.last_name.length()<second.last_name.length())

         {

                   return true;

         }

         else

         {

                   return false;

         }

}

 

bool operator>(const Patient& first, const Patient& second)

{

         unsigned int i=0;

         while((i<first.last_name.length()) && (i<second.last_name.length()))

         {

                   if (tolower(first.last_name[i]) > tolower(second.last_name[i]))

                   {

                            return true;

                   }

                   else if (tolower(first.last_name[i]) < tolower(second.last_name[i]))

                   {

                            return false;

                   }

                   ++i;

         }

         if (first.last_name.length() > second.last_name.length())

         {

                   return true;

         }

         else

         {

                   return false;

         }

}

 

bool operator==(const Patient& p1, const Patient& p2)

{

         return ((p1.last_name == p2.last_name) && (p1.first_name == p2.first_name) && (p1.sin == p2.sin) && (p1.doctor_name == p2.doctor_name) && (p1.doctor_id == p2.doctor_id));

}

 

bool operator!=(const Patient& p1,const Patient& p2)

{

         return !((p1.last_name == p2.last_name) && (p1.first_name == p2.first_name) && (p1.sin == p2.sin) && (p1.doctor_name == p2.doctor_name) && (p1.doctor_id == p2.doctor_id));

}

 

 

class PatientDatabase

{

public:

         // constructor of class patientdatabase

         PatientDatabase();

 

         // load the data persisted in the data file before

         bool loadDatabase(string dataFilename);

 

         // save data to data file, returns how many patients stored in the data file.

         int saveDatabase(string dataFilename);

 

         // add a patient to the database

         bool addPatient(Patient patient);

 

         // another form of adding patient to the database, overloaded.

         bool addPatient(string first_name,string last_name, int sin, string doctor_name, int doctor_id);

 

         // remove a patient for database by his/her sin

         bool removePatient(int sin);

 

         // search a patient by sin

         Patient* searchPatient(int sin);

 

         // print all patients' last name

         void printAllPatientsSortedByLastname();

 

         // print all patients cared by the same doctor

         void printAllPatientsCaredBy(int doctor_id);

 

private:

         // the container of all the patients, namely database

         list<Patient> database;

};

 

 

// constructor of class patientdatabase

PatientDatabase::PatientDatabase()

{

}

 

// load the data persisted in the data file before

bool PatientDatabase::loadDatabase(string dataFilename)

{

         int location = 0;

         char linestring[100];

         string s;

 

         string first_name;

         string last_name;

         int     sin;

         string doctor_name;

         int doctor_id;

 

 

         // try opening the database

         ifstream fin(dataFilename.c_str());

         if(!fin)

         {

                   cout << "can not open the database..." << endl;

                   return false;

         }

 

         while(fin)

         {

                   // read one line from patients.txt, and store it in linestring

                   fin.getline(linestring, 100);

                   s = linestring;

 

                   // if it's the last line which is '/n' only, break the loop

                   if(s.length() == 0) break;

 

                   string stemp;

 

                   // retrieve first name

                   location = s.find_first_of(",");

                   first_name = s.substr(0, location);

                   stemp = s.substr(location + 1);

                   s.empty();

 

                   // retrieve last name

                   location = stemp.find_first_of(",");

                   last_name = stemp.substr(0, location);

                   s = stemp.substr(location + 1);

                   stemp.empty();

 

                   // retrieve SIN

                   location = s.find_first_of(",");

                   sin = atoi(s.substr(0, location).c_str());

                   stemp = s.substr(location + 1);

                   s.empty();

 

                   // retrieve doctor's name

                   location = stemp.find_first_of(",");

                   doctor_name = stemp.substr(0, location);

                   s = stemp.substr(location + 1);

                   stemp.empty();

 

                   // retrieve doctor's ID

                   location = s.find_first_of(",");

                   doctor_id = atoi(s.substr(0, location).c_str());

                   stemp.empty();

                   s.empty();

        

                   // load a patient into the 'list<patient> database'

                   addPatient(first_name, last_name, sin, doctor_name, doctor_id);

         }

         fin.close();

 

         return true;

}

 

// save data to data file, returns how many patients stored in the data file.

int PatientDatabase::saveDatabase(string dataFilename)

{

         int i = 0;

         string buffer;

         char temp[4];

         string tempstr;

 

         // open a text file as database on disk

         ofstream outfile(dataFilename.c_str());

         list<Patient>::iterator it;

         for(it = database.begin(); it != database.end(); ++it)

         {

                   buffer.append(it->first_name + ",");

                  

                   buffer.append(it->last_name + ",");

 

                   // we need to convert 'int' to 'string' before appended to 'buffer'

                   itoa(it->sin, temp, 10);       // itoa causes a depreciated warning, don't care, it doesn't hurt!

                   tempstr = temp;

                   buffer.append(tempstr + ",");

 

                   buffer.append(it->doctor_name + ",");

 

                   // we need to convert 'int' to 'string' before appended to 'buffer'

                   itoa(it->doctor_id, temp, 10);  // itoa causes a depreciated warning, don't care, it doesn't hurt!

                   tempstr = temp;

                   buffer.append(tempstr + ",/n");

 

                   outfile.write(buffer.c_str(), buffer.length());

                   buffer.clear();

                   i++;

         }

         return i;

}

 

// add a patient to the database

bool PatientDatabase::addPatient(Patient patient)

{

         database.push_back(patient);

 

         return true;

}

 

 

// another form of adding patient to the database, overloaded.

bool PatientDatabase::addPatient(string first_name,string last_name, int sin, string doctor_name, int doctor_id)

{

         Patient p;

         p.first_name = first_name;

         p.last_name = last_name;

         p.sin = sin;

         p.doctor_name = doctor_name;

         p.doctor_id = doctor_id;

 

         database.push_back(p);

 

         return true;

}

 

// remove a patient for database by his/her sin

bool PatientDatabase::removePatient(int sin)

{

         list<Patient>::iterator it = database.begin();

         while(it!=database.end())

         {

                   if(it->sin == sin)

                   {

                            // be careful here, database.erase(it) returns ++it.

                            // it's very easy to fall into the trap of infinite loop

                            it = database.erase(it);

                            //return true;

                   }

                   else

                   {

                            ++it;

                   }

         }

 

         return true;

}

 

// search a patient by sin

Patient* PatientDatabase::searchPatient(int sin)

{

         list<Patient>::iterator it;

         for(it = database.begin(); it != database.end(); it++)

         {

                   if(it->sin == sin)

                   {

                            return (Patient*)(&(*it));

                   }

         }

         return NULL;

}

 

// print all patients sorted by last name

void PatientDatabase::printAllPatientsSortedByLastname()

{

         database.sort(greater<Patient>());

 

         list<Patient>::iterator it;

         for(it = database.begin(); it != database.end(); ++it)

         {

                   cout << '/t' << it->first_name << '/t' << it->last_name << '/t' << it->sin << '/t' << it->doctor_name << '/t' << it->doctor_id << endl;

         }

}

 

// print all patients cared by the same doctor

void PatientDatabase::printAllPatientsCaredBy(int doctor_id)

{

         list<Patient>::iterator it;

         for(it = database.begin(); it != database.end(); ++it)

         {

                   if(it->doctor_id == doctor_id)

                   {

                            cout << '/t' << it->first_name << '/t' << it->last_name << '/t' << it->sin << '/t' << it->doctor_name << '/t' << it->doctor_id << endl;

                   }

                   else

                   {

                            continue;

                   }

         }

}

 

int main(void)

{

         short action;

         string dataFilename = "patients.txt";

         PatientDatabase* pdb = new PatientDatabase();

 

         string first_name;

         string last_name;

         int sin;

         string doctor_name;

         int doctor_id;

 

         int pid;

         int did;

 

         while(true)

         {

                   system("cls");

                   cout << "/t0. Load database" << endl;

                   cout << "/t1. Input patient's data" << endl;

                   cout << "/t2. Search a patient by SIN" << endl;

                   cout << "/t3. Print all patients sorted by last name" << endl;

                   cout << "/t4. Print all patients cared by the same doctor" << endl;

                   cout << "/t5. Remove a patient" << endl;

                   cout << "/t6. Save database" << endl;

                   cout << "/t7. Quit" << endl;

                   cout << "/t---------------------------------------" << endl;

                   cout << "/tPlease enter your action:" << endl;

                   cout << "/t";

                   cin >> action;

                   if(action < 0 || action > 7)

                   {

                            cout << "/tSorry, you can only enter a number between 0 and 6, please return :)" << endl;

                            cout << "/t";

                            system("pause");

                            continue;

                   }

                   switch(action)

                   {

                   case 0:

                            if(pdb->loadDatabase(dataFilename))

                            {

                                     cout << "/tDatabase was successfully loaded" << endl;

                                     cout << "/t";

                                     system("pause");

                            }

                            break;

                   case 1:

                            cout << "/tFirst Name: ";

                            cin >> first_name;

 

                            cout << "/tLast Name: ";

                            cin >> last_name;

 

                            cout << "/tSIN: ";

                            cin >> sin;

 

                            cout << "/tDoctor Name: ";

                            cin >> doctor_name;

 

                            cout << "/tDoctor ID: ";

                            cin >> doctor_id;

 

                            if(pdb->addPatient(first_name, last_name, sin, doctor_name, doctor_id))

                            {

                                     cout << "/tPatient's data was successfully accepted." << endl;

                            }

 

                            cout << "/t";

                            system("pause");

                            break;

                   case 2:

                            Patient *pSearched;

                            cout << "/tPlease enter the patient's ID to be searched" << endl;

                            cout << '/t';

                            cin >> pid;

                            pSearched = pdb->searchPatient(pid);

                            if(pSearched != NULL)

                            {

                                     cout << '/t' << pSearched->first_name << " " << pSearched->last_name << " was selected out." << endl;

                            }

                            cout << "/t";

                            system("pause");

                            break;

                   case 3:

                            cout << "/tAll patients sorted by lastname(z->a)" << endl;

                            pdb->printAllPatientsSortedByLastname();

                            cout << "/t";

                            system("pause");

                            break;

                   case 4:

                            cout << "/tPlease enter the doctor's ID:" << endl;

                            cout << '/t';

                            cin >> did;

                            pdb->printAllPatientsCaredBy(did);

                            cout << "/t";

                            system("pause");

                            break;

                   case 5:

                            cout << "/tPlease enter the patient's ID to be removed" << endl;

                            cout << '/t';

                            cin >> pid;

                            pdb->removePatient(pid);

                            cout << "/t";

                            system("pause");

                            break;

                   case 6:

                            cout << '/t' << pdb->saveDatabase(dataFilename) << " records were successfully saved to " << dataFilename.c_str() << endl;

                            cout << "/t";

                            system("pause");

                            break;

                   case 7:

                            exit(0);

                   }

         }

        

         return 0;

}

成都市作为中国西部地区具有战略地位的核心都市,其人口的空间分布状况对于城市规划、社会经济发展及公共资源配置等研究具有基础性数据价值。本文聚焦于2019年度成都市人口分布的空间数据集,该数据以矢量格式存储,属于地理信息系统中常用的数据交换形式。以下将对数据集内容及其相关技术要点进行系统阐述。 Shapefile 是一种由 Esri 公司提出的开放型地理空间数据格式,用于记录点、线、面等几何要素。该格式通常由一组相互关联的文件构成,主要包括存储几何信息的 SHP 文件、记录属性信息的 DBF 文件、定义坐标系统的 PRJ 文件以及提供快速检索功能的 SHX 文件。 1. **DBF 文件**:该文件以 dBase 表格形式保存与各地理要素相关联的属性信息,例如各区域的人口统计数值、行政区划名称及编码等。这类表格结构便于在各类 GIS 平台中进行查询与编辑。 2. **PRJ 文件**:此文件明确了数据所采用的空间参考系统。本数据集基于 WGS84 地理坐标系,该坐标系在全球范围内广泛应用于定位与空间分析,有助于实现跨区域数据的准确整合。 3. **SHP 文件**:该文件存储成都市各区(县)的几何边界,以多边形要素表示。每个多边形均配有唯一标识符,可与属性表中的相应记录关联,实现空间数据与统计数据的联结。 4. **SHX 文件**:作为形状索引文件,它提升了在大型数据集中定位特定几何对象的效率,支持快速读取与显示。 基于上述数据,可开展以下几类空间分析: - **人口密度评估**:结合各区域面积与对应人口数,计算并比较人口密度,识别高密度与低密度区域。 - **空间集聚识别**:运用热点分析(如 Getis-Ord Gi* 统计)或聚类算法(如 DBSCAN),探测人口在空间上的聚集特征。 - **空间相关性检验**:通过莫兰指数等空间自相关方法,分析人口分布是否呈现显著的空间关联模式。 - **多要素叠加分析**:将人口分布数据与地形、交通网络、环境指标等其他地理图层进行叠加,探究自然与人文因素对人口布局的影响机制。 2019 年成都市人口空间数据集为深入解析城市人口格局、优化国土空间规划及完善公共服务体系提供了重要的数据基础。借助地理信息系统工具,可开展多尺度、多维度的定量分析,从而为城市管理与学术研究提供科学依据。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值