Create a programm that will determine there correct vaccine for every candidate. Use the switch statement and the for loop to determine the right vaccine for individuals by using their temperature readings
-30-33 for Mordena
-34-36 mRNA
-37-38 Johnson and Johnson’s Janssen
-39-40 Pfizer-BioNTech
The program must be able to read temperatures up to four(4) decimal places after the comma & convert it to two(2) decimals. A summary of all the people that are vaccinated along with their associated vaccines must be listed in the output in a table form as follows:
Name and surname Temperature Vaccine
Mzamani Nkuna 34,37 mRNA
Themba Manana 37,66 Johnson and johnson’s Janssen
Charles Nkosi 32,55 Mordena
Norwell Mbewe 39,78 pFizer-BioNTech
Take note of the following :
1. Use an appropriate operator to convert an expression to a specified type.
2. Use an appropriate operator to set correct precision for decimals
3. Use an appropriate operator to manage the alignments in the summary of your candidates
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Candidate{
string fullName;
float temperature;
string vaccine;
};
int main(){
int numberCandidates=-1;
while(numberCandidates<=0){
cout << "Ente the number of candidates: ";
cin>>numberCandidates;
}
Candidate* candidates=new Candidate[numberCandidates];
for(int i=0;i<numberCandidates;i++){
cin.ignore();
cout << "Ente the name and surname of candidate "<<(i+1)<<": ";
getline(cin,candidates[i].fullName);
cout << "Ente the temperature of candidate "<<(i+1)<<": ";
cin>>candidates[i].temperature;
switch ((int)candidates[i].temperature)
{
//-30-33 for Mordena
case 30 ... 33:
candidates[i].vaccine="Mordena";
break;
//-34-36 mRNA
case 34 ... 36:
candidates[i].vaccine="mRNA";
break;
//-37-38 Johnson and Johnson’s Janssen
case 37 ... 38:
candidates[i].vaccine="Johnson and Johnson’s Janssen";
break;
//-39-40 Pfizer-BioNTech
case 39 ... 40:
candidates[i].vaccine="Pfizer-BioNTech";
break;
break;
}
}
cout<<fixed<<left<<setw(30)<<"Name and surname"<<setw(30)<<"Temperature"<<setw(30)<<"Vaccine\n";
cout<<"\n";
for(int i=0;i<numberCandidates;i++){
cout<<setw(30)<<candidates[i].fullName<<setw(30)<<setprecision(2)<<candidates[i].temperature<<setw(30)<<candidates[i].vaccine<<"\n";
}
delete[] candidates;
cin>>numberCandidates;
return 0;
}
Comments
Leave a comment