- 浏览: 477157 次
文章分类
最新评论
-
itway:
多谢,正好要找c#的。多谢了。
用 C# .net framework 实现ADSL自动拨号 -
laosi0829:
...
无需刻盘,在windows XP/VISTA/7下,硬盘安装ubuntu
一个在加拿大上学的朋友的暑假作业
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 SINDoctor Name Doctor ID
Dave Ramdin 100 Mike 1
LiliBega 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;
}
相关推荐
加拿大矢量SHP文件,可直接在arcgis打开
在IBM的帮助下,加拿大航空已经进入电子商务的领域,IBM在20世纪90年代中期就为加拿大航空开发了第一套在线预定和电子票务系统,这套系统也是在加拿大国内投入使用的第一套在线预定和电子票务系统。加拿大航空计划...
现在许多人都自学Struts,感觉到有点复杂,我认为只有实战才能真正的学好它,所以我暑假参加了实战培训,现在把Struts实验指导书拿出来分享,希望大家一步一步按照做一下,希望给大家带来点帮助!
自己通过编程实现了对2019年中国研究生数学建模E题中所给资源加拿大天气变化历史数据的一个汇总,方便大家查看,
加拿大名校滑铁卢大学CS246课程C++讲义
介绍了加拿大在航空监视ADS-B应用方面的工作,NAV CANADA公司在哈德森湾的ADS-B评估
最新加拿大租房子网站加拿大多伦XX租房通用版合同精编范文样本.docx
加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶中文考试题目.docx加拿大汽车驾驶...
加拿大的分级标准,参考一下。加拿大的分级标准,参考一下。加拿大的分级标准,参考一下。
加拿大java练习题,可以帮助同学了解国外的试卷题是怎么考的
在先前的调查合法性话语以在加拿大和英国的教育环境中恢复性司法实践的研究的基础上,当前的研究提出了相同的概念和分析框架,以对合法性进行初步分析,以对文件中的证词和证词进行叙事。加拿大真相与和解委员会...
WI-FI是一种短程无线传输技术,能够在数百英尺范围内支持互联网接入的无线电信号。在加拿大,各大城市早在15年前就开始营建无线网络的基础建设,采用的方式是将建设经营权完全交给电信公司经营运做。三家无线电信...
此Ajax的ppt是加拿大慧桥培训的内部教材,我拿来与大家共享!希望对大家有用!
Whitemud Drive是一条横穿加拿大阿尔伯塔省埃德蒙顿市的市内高速公路,全长28公里,基本限速为80千米/小时。作为试验道路,Whitemud Drive 在主干道和闸道上装有地感线圈(Loop Detector),用于观测车流量、车速...
加拿大的管理咨询业.pdf
加拿大灰点SDI相机手册,了解这款相机的主要性能及接口。
Tellus公司是加拿大最主要的通信公司之一,它向全球客户提供通信产品和服务,将加拿大与整个世界连接起来。...这是一个灵活的架构,客户通过该架构可从任何地方、在任何时候、通过任何设备执行Web业务。
声速仪在多波束声呐中的应用,加拿大AML公司培训资料
加拿大
加拿大魁北克省2020年后续发行人信用评级报告-2020.8-16页精品报告2020.pdf