Quantcast

Maximum PC

It is currently Wed Sep 17, 2014 11:02 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Ahhhh Please help me with simple C++ problem?
PostPosted: Wed Oct 06, 2004 7:51 am 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
I wanted to learn how to do some simple C++ programming so I bought this beginners book and software. Well the 2nd problem I'm suppose to do is a real bitch. The first one was easy but the 2nd one just confuses the hell out of me. It wants me to "loop" a program but hasn't explained how to do that...some book.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Problem Solving with C++
The Object of Programming
Problem #2

A hospital-supply company wants to market a program to assist with calculation of intravenous (IV) rates. Design and implement a program that prompts a clinician (typically a nurse) for dose as written by the physician, and the desired flow-rate format. The program must:

use a function to collect data and perform calculation for each problem (each type of calculation), returning the answer to its caller.
use a function that displays the menu, and returns the selected menu number to its caller.
output the answer rounded to the nearest whole number (NOT TRUNCATED).
continually re-prompt the user with the menu until the user enters 5 (Quit).
use local variables only.
be well commented/documented and use indentation appropriately.
use descriptive variable and function names.
display an error message if the user enters an invalid menu choice.
repeat until the user indicates that he/she wants to quit (menu item 5).


Here is the equation for problem 1 (drops per minute):

volume (ml) X drop factor (drops/ml)

----------------------------------------------
= drops / minute
time (min)


For more information on this "drop factor" equation, visit: http://www.cybernurse.org.uk/nursing/i_ ... _rates.htm

The program should interact with the user as follows:

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

INTRAVENOUS RATE ASSISTANT

Enter the number of the problem you wish to solve.

GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:

1) ml/hr and tubing drop factor drops/min
2) 1 L for n hrs ml/hr
3) mg/kg/hr and concentration in mg/ml ml/hr
4) units/hr and concentration in units/ml ml/hr
5) QUIT

Problem: 1
Enter rate in ml/hr: 150
Enter tubing's drop factor (drops/ml): 15
The drop rate per minute is 38.

Enter the number of the problem you wish to solve.

GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:

1) ml/hr and tubing drop factor drops/min
2) 1 L for n hrs ml/hr
3) mg/kg/hr and concentration in mg/ml ml/hr
4) units/hr and concentration in units/ml ml/hr
5) QUIT

Problem: 2
Enter number of hours: 8
The rate in milliliters per hour is 125.

Enter the number of the problem you wish to solve.

GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:

1) ml/hr and tubing drop factor drops/min
2) 1 L for n hrs ml/hr
3) mg/kg/hr and concentration in mg/ml ml/hr
4) units/hr and concentration in units/ml ml/hr
5) QUIT

Problem: 3
Enter rate in mg/kg/hr: 0.6
Enter patient weight in kg: 70
Enter concentration in mg/ml: 1
The rate in milliliters per hour is 42.

Enter the number of the problem you wish to solve.

GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:

1) ml/hr and tubing drop factor drops/min
2) 1 L for n hrs ml/hr
3) mg/kg/hr and concentration in mg/ml ml/hr
4) units/hr and concentration in units/ml ml/hr
5) QUIT

Problem: 4
Enter rate in units/hr: 1000
Enter concentration in units/ml: 25
The rate in milliliters per hour is 40.

Enter the number of the problem you wish to solve.

GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:

1) ml/hr and tubing drop factor drops/min
2) 1 L for n hrs ml/hr
3) mg/kg/hr and concentration in mg/ml ml/hr
4) units/hr and concentration in units/ml ml/hr
5) QUIT

Problem: 5
Goodbye...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



I didn't buy the solution manual for this book because I already spent a crap load of money for the book and software. It does give me this as a starting point but its a little to complicated. I understand parts of it but not all of it. Can anybody tell me what to do next or just solve this problem so I can see what you did? I've been trying to figure it out for days!!!! Bout to throw this programming crap away.




#include <iostream>
using namespace std;
int main (void)

int task = 0;
double rate = 0.0;
task = getProblem( );

if (task == 1)
else if (task == 2)

int getProblem (void);
double calcDropsPerMinute (void);
double litersToMlPerHour (void);
double calcRateFromWeight (void);
double calcRateFromUnits (void);
void displayRate (double rate, int task);

int main (void)

{
cout << "INTRAVENOUS RATE ASSISTANT \n\n";
double rate = 0.0; //Will contain the calculated rate
int task = 0; //Will contain the users menu response
bool done = false; //Flag used to tell when user quits

do
{
task = getProblem( );
if (task == 1)
rate = calcDropsPerMinute( );
else if (task == 2)
rate = litersToMlPerHour( );
else if (task == 3)
rate = calcRateFromWeight( );
else if (task == 4)
rate = calcRateFromUnits( );
else if (task == 5)
done = true;
if (!done)
displayRate(rate, task);

}while (!done);

cout << "Goodbye.\n";
return 0;

}


Top
  Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 8:27 am 
Coppermine
Coppermine

Joined: Wed Jul 07, 2004 11:07 am
Posts: 666
Location: Woodland Hills, CA
the solution is ez to code, but it would take more time than i want to code and test the code. However, you might want to get started with this tutorial:
http://www.intap.net/~drw/cpp/

It seems like the problem you are solving is exercising your knowledge on calling functions and loops.

I could probably be better help if you had more specific questions about the code.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 8:37 am 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
Hah I wish I had more specific questions, I just don't know where to start, it would be awesome if you could do part of it or start it but I can understand if you don't.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 6:44 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
Please use code tags!
Code:
#include <iostream>
using namespace std;

//you had a bunch of junk here.  I'll assume it was just a copying error

int getProblem (void);
double calcDropsPerMinute (void);
double litersToMlPerHour (void);
double calcRateFromWeight (void);
double calcRateFromUnits (void);
void displayRate (double rate, int task);

int main (void)

{
cout << "INTRAVENOUS RATE ASSISTANT" << endl << endl;//use stream operator endl rather than a newline character.
//endl also flushes the output stream.
double rate = 0.0; //Will contain the calculated rate
int task = 0; //Will contain the users menu response
bool done = false; //Flag used to tell when user quits

do
{
    task = getProblem( );

    if (task == 1)
    rate = calcDropsPerMinute( );
   
    else if (task == 2)
    rate = litersToMlPerHour( );
   
    else if (task == 3)
    rate = calcRateFromWeight( );
   
    else if (task == 4)
    rate = calcRateFromUnits( );
   
    else if (task == 5)
    done = true;
   
    if (!done)
    displayRate(rate, task);

}while (!done);

cout << "Goodbye." << endl;
cin.get();//gives the user a chance to read the output before the window closes
//purely optional, just nice if you're not running the program from a terminal
return 0;

}


int getProblem(void)
{
    //this will print the menu and get the menu response
    int response;//the user's response

    cout << endl <<"GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:" << endl << endl;

    cout << "1) ml/hr and tubing drop factor drops/min" << endl;
    cout << "2) 1 L for n hrs ml/hr" << endl;
    cout << "3) mg/kg/hr and concentration in mg/ml ml/hr" << endl;
    cout << "4) units/hr and concentration in units/ml ml/hr" << endl;
    cout << "5) QUIT" << endl; 

    cin.get(response);//get the response
    cin.ignore(1000000, '\n');//ignore everything to the newline, so we don't get a bogus value next time

    return response;
}


I did 1 function for you. Does it make a little more sense to you now?


Top
  Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 9:11 pm 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
Yes thanks alot. I got my code to work now.

Here's the final code that worked:



#include <iostream>
using namespace std;

int menu(void);//Menu is ran so user can select their choice
double prob1(void);//Declares prob1
double prob2(void);//Declares prob2
double prob3(void);//Declares prob3
double prob4(void);//Declares prob4

int main (void)

{
cout << "INTRAVENOUS RATE ASSISTANT\n\n";//Title at begining of program
int task;//Selection chosen for if statments
do//Runs users task and repeats menu if user selects correct value
{
task = menu ();//Tasks are brought in so user can decide which one to run
if (task == 1)//Runs task 1 and returns value
cout << "The drop rate per minute is "<<prob1()<<"."<<"\n\n";
else if(task == 2)//Runs task 2 and returns value
cout << "The rate in milliliters per hour is "<<prob2()<<"."<<"\n\n";
else if(task == 3)//Runs task 3 and returns value
cout << "The rate in milliliters per hour is "<<prob3()<<"."<<"\n\n";
else if(task == 4)//Runs task 4 and returns value
cout << "The rate in milliliters per hour is "<<prob4()<<"."<<"\n\n";
}while(task !=5);//Runs do statment as long as task does not equal 5

cout <<"\nProblem: 5\n";//Quits program when task = 5
cout <<"Goodbye...\n\n";
system("PAUSE");
return 0;
}

int menu(void)

{
int task;//Declares users task
cout << "Enter the number of the problem you wish to solve.\n\n";
cout << "GIVEN MEDICAL ORDER IN: CALCULATE RATE IN:\n\n";
cout << "1) ml/hr and tubing drop factor drops/min\n";
cout << "2) 1 L for n hrs ml/hr\n";
cout << "3) mg/kg/hr and concentration in mg/ml ml/hr\n";
cout << "4) units/hr and concentration in units/ml ml/hr\n";
cout << "5) QUIT\n";
cout << "Enter your selection: ";
cin >> task;//User enters their task
return task;//Returns task to main
}


double prob1(void) //First menu option, User types 1 the following will be used

{
double mlhr=0.0, dropfactor=0.0, droprate=0.0;//Declares variables for prob1
cout << "\n\nProblem: 1\n";
cout << "Enter rate in ml/hr: ";
cin >> mlhr;//User enters ml/hr
cout << "Enter the tubing's drop factor (drops/ml): ";
cin >> dropfactor;//User enters dropfactor
cout.setf(ios::fixed);
cout.precision(0);//Numbers are rounded to nearest whole number
droprate = ( mlhr * dropfactor) /60;//Formula for calculation
return droprate;//Droprate returned to main
}


double prob2(void) //Second menu option, User types 2 the following will be used

{
double hours=0.0, droprate=0.0;//Declares variable for prob2
cout << "\n\nProblem: 2\n";
cout << "Enter the number of hours: ";
cin >> hours;//User enters the number of hours
cout.setf(ios::fixed);
cout.precision(0);//Rounds to the nearest whole number
droprate = 1000/hours;//Formula for calculation
return droprate;//Returns droprate to main
}


double prob3(void) //Third menu option, User types 3 the following will be used

{
double mgkghr=0.0, kg=0.0, mgml=0.0, droprate=0.0;//Declares variable for prob3
cout << "\n\nProblem: 3\n";
cout << "Enter rate in mg/kg/hr: ";
cin >> mgkghr;//User enters mg/kg/hr
cout << "Enter the patient weight in kg: ";
cin >> kg;//User enters patient weight in kg
cout << "Enter the concentration in mg/ml: ";
cin >> mgml;//User enters concentration in mg/ml
cout.setf(ios::fixed);
cout.precision(0);//Rounds to the nearest whole number
droprate = (mgkghr * kg)/mgml;//Formula used for calculations
return droprate;//Returns droprate to main
}


double prob4(void) //Fourth menu option, User types 4 the following will be used

{
double unitshr=0.0, unitsml=0.0, droprate=0.0;//Declares variable for prob4

cout << "\n\nProblem: 4\n";
cout << "Enter the rate in units/hr: ";
cin >> unitshr;//User enters rate in units/hr
cout << "Enter the concentration in units/ml: ";
cin >> unitsml;//User enters units/hr
cout.setf(ios::fixed);
cout.precision(0);//Rounds to the nearest whole number
droprate = unitshr/unitsml;//Formula for calculation
return droprate;//Returns droprate to main
}


Top
  Profile  
 
 Post subject:
PostPosted: Sun Oct 10, 2004 2:35 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Gigahertz, please use the code tag in the future. No one wants to read a bunch of unformatted code. Thanks.


Top
  Profile  
 
 Post subject:
PostPosted: Sun Oct 10, 2004 3:41 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24224
Location: Granite Heaven
Does the code tag reformat text, or simply present with nice retro-green styling?

do {

if (indent==true)
Gadget.IQ=genius;
else
Gadget.IQ=submoron;

} while (code.tag != pretty)

Code:
do {

if (indent==true)
Gadget.IQ=genius;
else
Gadget.IQ=submoron;

} while (code.tag != pretty)


Nope ... just pretty. Still ... it helps us all if you use the [code] tags. :D


Top
  Profile  
 
 Post subject:
PostPosted: Sun Oct 10, 2004 9:02 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Jipstyle wrote:
Does the code tag reformat text, or simply present with nice retro-green styling?

Smart ass. :)

Gigahertz, if you haven't used proper indentation, do so. ;)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group