Wednesday, June 10, 2020

CS201 Assignment 2 Solution 2020 with Download






#include<iostream>
using namespace std;

// Declaration of function showElements
void showElements(long s[][4]);
// Declaration of function PercentageDeath
void PercentageDeath(long s[][4], int i);
// Declaration of function PercentageRecovered
void PercentageRecovered(long s[][4], int i);

main()
{
long source_data[7][4]= {0,560433, 22115, 32634, 1,156363, 19899, 34211, 2,84279, 10612, 0, 3,82160, 3341, 77663, 4,71686, 4474, 43894, 5,56956, 1198, 3446, 6,5374, 93, 109};
showElements(source_data);
int user_choice;
do
{
cout<<"\nPress the country code to calculate percentage of dead and recovered persons\n";
cout<<"\n*** Press 0 for Pakistan ***";
cout<<"\n*** Press 1 for China ***";
cout<<"\n*** Press 2 for Italy ***";
cout<<"\n*** Press 3 for UK ***";
cout<<"\n*** Press 4 for Iran ***";
cout<<"\n*** Press5 for France ***";
cout<<"\n*** Press 6 for Turkey ***";
cout<<"\n*** Press 7 to Exit ***";
cout<<"\n\nPlease select an option use number from 0 to 7 : ";
input:
cin>>user_choice;
if(user_choice>=0 && user_choice<=6)
{
PercentageDeath(source_data, user_choice);
PercentageRecovered(source_data, user_choice);
}
else if(user_choice<0 || user_choice>7) 
{
cout<<"\n\nChoice should be between 0 to 7 ";
cout<<"\ninvalid choice ! please select again : ";
goto input;
}
}while(user_choice!=7);
}

// definition of function showElements
void showElements(long s[][4])
{
cout<<"Source Data : \n\n";
cout<<"Country\tCases\tDeaths\tRecovered\n\n";
for(int i=0; i<7; i++)
{
for(int j=0; j<4; j++)
{
cout<<s[i][j]<<"\t";
}
cout<<"\n";
}
}

// definition of function PercentageDeath
void PercentageDeath(long s[][4], int i)
{
float d_rate=(float)100*s[i][2]/s[i][1];
cout<<"\nPercentage of death is "<<d_rate;
}

// definition of function PercentageRecovered
void PercentageRecovered(long s[][4], int i)
{
float r_rate=(float)100*s[i][3]/s[i][1];
cout<<"\n\nPercentage of recocered is "<<r_rate<<"\n";
}


No comments:

Post a Comment