在C++中创建患者程序菜单的视觉建议
visual Suggestions with creating a Menu for Patient Program in C++
所以我基本上已经完成了大部分编程。我想添加一个显示输出的菜单。例如,创建记录列表。全部输入后,我希望它在从菜单中选择数字时仅显示吸烟或患有高血压或高脂肪饮食的患者。现在我试图弄清楚这一点,但似乎无法理解它。关于如何让它工作的任何建议?现在,它仅设置为一次显示所有记录。
程序说明:显示患者记录的界面程序。
#include <iostream>
#include <string>
using namespace std;
struct Node
{
char name[20];
int age;
string smoker;
string hbp;
string hfd;
int points;
Node *ptr;
};
Node *startPtr = NULL;
void getInfo()
{
Node *p, *p2;
p = new Node;
int agePoints;
int smkPoints;
int hbpPoints;
int hfdPoints;
cout << " Please enter the name of the patient : ";
cin >> p->name;
cout << " Please enter the age of the patient : ";
cin >> p->age;
cout << " Is he/she a smoker (y/n) : ";
cin >> p->smoker;
cout << " Does he/she have high blood pressure? (y/n) : ";
cin >> p->hbp;
cout << " Does he/she have a high fat diet? (y/n) : ";
cin >> p->hfd;
cout << endl;
p->ptr = NULL;
// Age point system
if (p-> age > 30) {
agePoints = 3;
}
else if (p->age > 20)
{
agePoints = 2;
}
else
{
agePoints = 1;
}
// Habits Points System
if (p->smoker == "Y" || p->smoker == "y")
{
p->smoker = "Yes";
smkPoints = 4;
}
else
{
p->smoker = "non smoker";
smkPoints = 0;
}
if (p->hbp == "Y" || p->hbp == "y")
{
p->hbp = "High blood pressure";
hbpPoints = 2;
}
else
{
p->hbp = "Normal blood pressure";
hbpPoints = 0;
}
if (p->hfd == "Y" || p->hfd == "y")
{
p->hfd = "High fat diet";
hfdPoints = 1;
}
else
{
p->hfd = "Low fat diet";
hfdPoints = 0;
}
p->points = agePoints + smkPoints + hbpPoints + hfdPoints;
// Set up link to this node
if (startPtr == NULL) {
startPtr = p;
}
else
{
p2 = startPtr;
while (p2->ptr != NULL)
p2 = p2->ptr;
p2->ptr = p;
}
}
void delete_start_node()
{
Node *p;
p = startPtr;
startPtr = startPtr->ptr;
delete p;
}
void delete_end_node()
{
Node *p1, *p2;
if (startPtr == NULL)
cout << "The List is empty!n";
else
{
p1 = startPtr;
if (p1->ptr == NULL)
{
delete p1;
startPtr = NULL;
}
else
{
while (p1->ptr != NULL)
{
p2 = p1;
p1 = p1->ptr;
}
delete p1;
p1->ptr = NULL;
}
}
}
void disp()
{
Node *p;
p = startPtr;
if (p == NULL)
cout << "Empty List!n";
while (p != NULL)
{
if (p == NULL)
cout << "Empty List!n";
cout << " Name : " << p->name << endl;
cout << " Age : " << p->age << endl;
cout << " Smoker : " << p->smoker << endl;
cout << " Blood Pressure : " << p->hbp << endl;
cout << " Fat Diet : " << p->hfd << endl;
cout << " Points : " << p->points << endl;
cout << endl;
p = p->ptr;
}
}
Node* removeptr(Node* prev)
{
if (prev)
{
if (prev->ptr)
{
Node* p = prev->ptr;
prev->ptr = p->ptr;
return p;
}
}
else if (startPtr)
{
Node* p = startPtr;
startPtr = startPtr->ptr;
return p;
}
return NULL;
}
// sort by age in ascending order
void sortAge()
{
Node* startPtr2 = NULL;
while (startPtr)
{
Node* prev = NULL;
Node* curr = startPtr;
Node* prevMax = NULL;
int max = startPtr->age;
while (curr)
{
if (curr->age > max)
{
max = curr->age;
prevMax = prev;
}
prev = curr;
curr = curr->ptr;
}
// Node with the highest age found pass throug the list.
Node* xferNode = removeptr(prevMax);
if (xferNode)
{
xferNode->ptr = startPtr2;
startPtr2 = xferNode;
}
}
startPtr = startPtr2;
}
int main()
{
Node *p;
p = startPtr;
char selection;
do
{
cout << " Patient Menun";
cout << " =============================================n";
cout << " 1. Insert a new recordn";
cout << " 2. List smoker patientsn"; // smoker patient
cout << " 3. List HBP patientsn"; // high blood pressure patient
cout << " 4. List HFD patientsn"; // high fat diet patient
cout << " 5. Delete a patient record by given namen";
cout << " 6. Exit the programn";
cout << " =============================================n";
cout << " Enter your selection: ";
cin >> selection;
cout << endl;
switch (selection)
{
case '1':
getInfo();
break;
case '2':
disp();
break;
case '3':
break;
case '4':
break;
case '5':
break;
case '6':
cout << " Goodbye!n";
return 0;
break;
default:
break;
}
}while (selection != 6);
/*
disp();
cout << "________________________________________________n";
sortAge();
disp();*/
system("pause");
return 0;
}
Node *smokers, *hbp, *hfd = NULL;
您可以为每种类型保留一个单独的链表 - 吸烟者,hbp,hfd和更改
void disp()
// to
void disp(Node* linkedList)
并打印提供给它的清单
case '2':
disp(smokers);
break;
case '3':
disp(hbp);
break;
case '4':
disp(hfd);
break;
顺便说一句,闻起来像家庭作业:)
相关文章:
- 无法获取菜单选择以运行函数.C++
- 视觉studo 2019中的漫画和静态/动态绑定
- 如何改变c++应用程序的视觉效果
- 视觉工作室项目.提取源文件夹名称
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 视觉我希望一个函数在另一个函数C++中进行计算
- 视觉 如何循环访问C++中遵循类似格式的多个.txt文件?
- C++ 中的图形菜单
- C++ 程序菜单使用做同时和切换
- remove(str.begin(), str.end(), );无法正常工作(我正在使用视觉工作室 2012)
- 我正在尝试创建一个菜单,但我的代码一直在循环
- 背包问题,视觉工作室问题
- 如何在视觉c ++项目中添加箭头键作为修饰键Microsoft
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 触发另一个窗口的菜单按钮
- 视觉C++未按所需顺序打印
- 视觉C++使用 map 来比较字符串中的每个单词
- C++11 中好友模板类的视觉C++错误
- 在C++中创建患者程序菜单的视觉建议