PDF
Answer question 1
#include <iostream>
using namespace std;
int main()
{
char sn;
do{
char line[150];
int punct, lower, upper, spaces,i=0,w=0;
punct = lower = upper = spaces = 0;
cout << "Enter a line of string: ";
cin.getline(line[0]);
cout<<"\n\nList of words in the string above:";
while(line[i]!='\0'&&line[i] != ' '&& line[i] != '\t'){
if(line[i] != ' '&& line[i] != '\t'&&line[i]!='\0' ){
++w;
cout<<"\nWord "<<w<<" = ";
while(line[i] != ' ' && line[i] != '\t'&&line[i]!='\0' )
{
cout<<line[i];
++i;
}
cout<<endl;
}
++i;
}
for(i=0;line[i]!='\0';++i)
{
if(line[i]>='a'&& line[i]<='z')
{++lower;
}
else if(line[i]>='A'&& line[i]<='Z')
{++upper;
}
else if(line[i]==' ')
{++spaces;
}
else
++punct;
}
cout << "Number of words = " << w << endl;
cout << "Number of spaces = " << spaces << endl;
cout << "Number of punctuations = " << punct << endl;
cout << "Number of characters = " << i << endl;
cout << "Number of uppercase letters = " << upper << endl;
cout << "Number of lowercase letters = " << lower << endl;
cout<<"\nDo you want to enter a new string? [Press 'Y' to continue]: ";
cin>>sn;
cout<<"\n\n\n";
}while(sn=='y'||sn=='Y');
cout<<"Thank you for using our system"<<endl;
return 0;
}
Answer question 2
#include <iostream>
#include <cmath>
using namespace std;
int getProblem();
void getRateDropFactor();
void getKgRateConc();
int figDropsMin(float,float);
int byWeight(float,float,float);
int main()
{int p,l;
do{
p=getProblem();
if(p==1)
{getRateDropFactor();
}
if(p==2)
{getKgRateConc();
}
else if(p==3)
{cout<<"You have chosen to quit the program.\nThank you for using our system."<<endl;
}
else if(p!=1&&p!=2&&p!=3)
{cout<<"Please run the system again and choose a problem number between 1 and 3.";
exit(0);
}
}while(p==1||p==2);
return 0;
}
int getProblem()
{
int pr;
cout<<"\nINTRAVENOUS RATE ASSISTANT\n\nEnter the number of the problem you wish to solve.\n\tGIVEN A MEDICAL ORDER IN \t\t CALCULATE RATE IN\n(1) ml/hr & tubing drop factor \t\t\t\tdrops/min\n(2) mg/kg/hr & concentration in mg/ml \t\t\tml/hr\n(3) QUIT\n\nProblem =>";
cin>>pr;
return pr;
}
void getRateDropFactor()
{float mlhr,dml;
cout<<"Enter rate in mh/hr => ";
cin>>mlhr;
cout<<"Enter tubing's drop factor(drops/ml) => ";
cin>>dml;
cout<<"The drop rate per minute is "<<figDropsMin(mlhr,dml)<<endl;
}
void getKgRateConc()
{float mghr,kg,mgml;
cout<<"Enter rate in mg/hr => ";
cin>>mghr;
cout<<"Enter patient weight in kg => ";
cin>>kg;
cout<<"Enter concentration in mg/ml =>";
cin>>mgml;
cout<<"The rate in millilitres per hour is "<<byWeight(mghr,kg,mgml)<<endl;
}
int figDropsMin(float a,float b)
{int u;//u is the rate
u=b*a/60;
return round(u);
}
int byWeight(float c,float d,float e)
{int z;//z is the rate
z=c*d*e;
return round(z);
}