Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose- This lab investigates an all too common occurrence: the bug in someone

ID: 3721568 • Letter: P

Question

Purpose-This lab investigates an all too common occurrence: the bug in someone else’s C++ program.

Procedure

The program to be investigated during this lab procedure is provided for you in the Lab 14 assignment on WyoCourses. Your task is to debug the provided program and insert your modifications to correct its functionality.

The Setting: You’ve just started an internship with the IT department on the graveyard shift at the local medical center (eerie feeling, I know). The medical records team is in the midst of generating bedside applications for reducing the amount of repetitive handwriting required of nurses and technicians (and you thought those doctors couldn’t write because they were just spastic). The first application is supposed to generate a set of labels containing nurse, patient and simple vital sign information (to be stuck onto all of the various places that it needs to be recorded). The programmer assigned to the task has called in sick for the week (works in a hospital, go figure), so you are left with a buggy program. Here is how it works, in dialog form...

This is an okay run, but .... the name information on the label is not correct:

Enter nurse’s name: Betty

Enter patient’s name: Joe

Enter pulse rate: 60

Enter systolic BP: 120

Enter diastolic BP: 66

****************************************

Patient: Betty

Nurse: Joe* Pulse: 60

BP: 120/66

****************************************

When the input data for the names are expanded (full names), it really goes bad:

Enter nurse’s name: Josephine Nightingale

Enter patient’s name: Enter pulse rate: 82

Enter systolic BP: 140

Enter diastolic BP: 96

****************************************

Patient: Josephine

Nurse: Nightingale

Pulse: 82

BP: 140/96

****************************************

And here is an example dialog of the desired behavior:

Enter nurse’s name: Josephina Wilhemina Frankenheimerstein III

Enter patient’s name: Poor Unfortunate Soule

Enter pulse rate: 72

Enter systolic BP: 124

Enter diastolic BP: 80

****************************************

Patient: Poor Unfortunate Soule

Nurse: Josephina Wilhemina Frankenheimerstein III

Pulse: 72

BP: 124/80

****************************************

Your only communication with the original programmer consisted of a phone call (subdued sounds of ocean surf and seagulls in the background) and a text message, both involving hints toward “I’ve never really gotten used to this C++ thing, C worked so well,” and “I should have used string::getline() or something like that”, oh, and “don’t forget about buffer overflow!”

1.Build a new project and insert the “problem code.”

2.The files are all available on the WyoCourses assignment. Lab14.cpp, Lab14Funcs.cpp, Lab14Funcs.h

3.Build and run the program with debugging enabled. That way you might see what is going on, especially if you step through the program.

4.Make your edits to the Lab14 files as necessary. This will likely involve some use of the iostream getline() method and the string::getline() function.

You might search the Web (cplusplus.com for example) for documentation and examples of the use of these.

You might also consider validating the user’s input. For instance, the values used for a BP or a pulse are always integers.

You cannot limit the length of the nurse’s name or patient’s name. You need to handle relatively large/long names. For instance, deciding that the name should only be 50 characters would be too small.

Test your solution to ensure that the example desired behavior is achieved.

Make sure that YOUR NAME appears in all the files’ comment headers.

Upload your solution as four (4) files to the Lab 14 assignment.

The source code of your solution: Lab14.cpp, Lab14Funcs.cpp and Lab14Funcs.h

An annotated text file containing demonstration of your program’s behavior:

Lab14Test.txt.

Here are the source files:

// Lab14.cpp
//
// COSC1030, Sp 2018
// Lab 14
// Main program

// Purpose: prompt for patient record information, display label summary.

#include "Lab14Funcs.h"

int main()
{
string patient;
string nurse;
int pulse, systolic, diastolic;

getNurse(nurse);
getPatient(patient);
getPulse(pulse);
getBP(systolic,diastolic);

displayRecord(nurse,patient,pulse,systolic,diastolic);

return 0;
}

// Lab14Funcs.cpp
//
// COSC1030, Sp 2018
// Lab 14
// Definitions for functions

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <iomanip>
using std::setfill;
using std::setw;

#include "Lab14Funcs.h"

// This function is used to prompt the user for
// the nurse's name and nothing else
void getNurse(string& dnurse)
{
cout << "Enter nurse's name: ";
cin >> dnurse;
}

// This function is used to prompt the user for
// the patient's name and nothing else
void getPatient(string& dpatient)
{
cout << "Enter patient's name: ";
cin >> dpatient;
}

// This function is used to prompt the user for
// Pulse rate and nothing else.
void getPulse(int &dpulse)
{
cout << "Enter pulse rate: ";
cin >> dpulse;
}

// This function is used to prompt the user for
// BP and nothing else.
void getBP(int &dsyst, int &ddiast)
{
cout << "Enter systolic BP: ";
cin >> dsyst;
cout << "Enter diastolic BP: ";
cin >> ddiast;
}

// This function only formats and displays its arguments
// and nothing else.
void displayRecord(string& dpatient, string& dnurse, int dpulse, int dsyst,
int diast)
{
cout << setfill('*') << setw(40) << "*" << endl;
cout << "* " << "Patient: " << dpatient << endl;
cout << "* " << "Nurse: " << dnurse << endl;
cout << "* " << "Pulse: " << dpulse << endl;
cout << "* " << "BP: " << dsyst << "/" << diast << endl;
cout << setfill('*') << setw(40) << "*" << endl;
}

// Lab14Funcs.h
//
// COSC1030, Sp 2018
// Lab 14
// Prototypes for the functions

#ifndef L13FUNCS_H
#define L13FUNCS_H

#include <string>
using std::string;

void getNurse(string &);
void getPatient(string &);
void getPulse(int &);
void getBP(int &, int &);
void displayRecord(string &, string &, int ,int ,int );

#endif

Enter nurse’s name: Betty

Enter patient’s name: Joe

Enter pulse rate: 60

Enter systolic BP: 120

Enter diastolic BP: 66

****************************************

Patient: Betty

Nurse: Joe* Pulse: 60

BP: 120/66

****************************************

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

//try following function for correct working of program.....
void getNurse(string& dnurse)
{
cout << "Enter nurse's name: ";
cin.clear();
getline(cin,dnurse);
}

// This function is used to prompt the user for
// the patient's name and nothing else
void getPatient(string& dpatient)
{
cout << "Enter patient's name: ";
cin.clear();
getline(cin,dpatient);
}

// This function is used to prompt the user for
// Pulse rate and nothing else.
void getPulse(int &dpulse)
{
cout << "Enter pulse rate: ";
cin.clear();
cin >> dpulse;
}

// This function is used to prompt the user for
// BP and nothing else.
void getBP(int &dsyst, int &ddiast)
{
cout << "Enter systolic BP: ";
cin.clear();
cin >> dsyst;
cout << "Enter diastolic BP: ";
cin >> ddiast;
}

// This function only formats and displays its arguments
// and nothing else.
void displayRecord(string& dpatient, string& dnurse, int dpulse, int dsyst,
int diast)
{
cout << setfill('*') << setw(40) << "*" << endl;
cout << "* " << "Patient: " << dpatient << endl;
cout << "* " << "Nurse: " << dnurse << endl;
cout << "* " << "Pulse: " << dpulse << endl;
cout << "* " << "BP: " << dsyst << "/" << diast << endl;
cout << setfill('*') << setw(40) << "*" << endl;
}
int main()
{
string dnurse,dpatient;
int dpulse,dsyst,diast;
getNurse(dnurse);
getPatient(dpatient);
getPulse(dpulse);
getBP(dsyst,diast);
displayRecord(dpatient,dnurse,dpulse,dsyst,diast);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote