CS201 ASSIGNMENT NO2 SOLUTION FALL 2020

CS201 ASSIGNMENT NO2 SOLUTION FALL 2020

DOWNLOAD .CPP FILE FROM LINK AT END OF THE PAGE

#include <iostream>

using namespace std;

void showElements(int data[][5] ){
int i = 0;
int rows = 3, cols = 5;
cout<<“Source data:”<<endl<<endl;
cout<<“States Biden Votes Trump Votes Jorgensen Votes Total Votes”;
cout<<endl<<endl;
for(i; i < rows; i++){
int j = 0;
for(j; j < cols; j++){
cout<<data[i][j]<<” \t”;
if(j == cols – 2){
cout<<“\t”;
}
}
cout<<endl;
}
}

double PercentageBiden(int data[][5], int state){
return (double)data[state][1] * 100 / (double)data[state][5 – 1];
}

double PercentageTrump(int data[][5], int state){
return (double)data[state][2] * 100 / (double)data[state][5 – 1];
}

double PercentageJorgensen(int data[][5], int state){
return (double)data[state][3] * 100 / (double)data[state][5 – 1];
}

void ShowMenu(){
cout<<endl;
cout<<“Press the state code to calculate percentage of Trum, Biden and Jorgenson votes”;
cout<<endl<<endl;
cout<<“Press 1 for Florida.”<<endl;
cout<<“Press 2 for Georgia.”<<endl;
cout<<“Press 3 for Michigan.”<<endl;
cout<<“Press 4 for exit”<<endl<<endl;
}

void showStateWisePercentage(int data[][5], int state){
cout<<endl;
cout<<“Percentage of Joe Biden Vites is: “<<PercentageBiden(data, state)<<endl;
cout<<“Percentage of Joe Biden Vites is: “<<PercentageTrump(data, state)<<endl;
cout<<“Percentage of Joe Biden Vites is: “<<PercentageJorgensen(data, state)<<endl;
}

int main(){

int data[3][5] = {
{1, 5284453, 5658847, 70046, 11013346},
{2, 2465781, 2455428, 61894, 4983103},
{3, 2790648, 2644525, 60287, 5495460}
};

showElements(data);

int ch;

do{
ShowMenu();

cout<<“Please select an option, use numbers from 1 to 4: “;
cin>>ch;
if(ch < 1 || ch > 4){
cout<<“Choice should be between 1 and 4″<<endl;
cout<<“Invalid choice, please select again: “;
cin>>ch;
}
switch(ch){
case 1:
showStateWisePercentage(data, 0);
break;
case 2:
showStateWisePercentage(data, 1);
break;
case 3:
showStateWisePercentage(data, 2);
break;
}

}while(ch != 4 );

}

CLICK HERE TO DOWNLOAD .CPP FILE

Related Posts

Leave a Reply

%d bloggers like this: