Answer to Question #232002 in Java | JSP | JSF for Zia

Question #232002
This assignment is to write a program using machine learning that will try to determine the political leanings of the user based on a survey.
You will be tasked to write this program in either C++ or Java, whichever you feel more comfortable
with.

2. The last question should ask which political party they affiliate with. This way you will be able to gather and store data corresponding to the results you acquire. Create at least 4 political party storage.
1
Expert's answer
2021-09-05T08:23:56-0400
#include<iostream>
using namespace std;
int main(){
	cout<<"The survery that will determine political leanings of user\n";
	int choice;
	int rep = 0, democratic=0, conserv = 0, republic = 0;
	
		cout<<"a. How can the government help the poor?\n";
		cout<<"1= Investing more funds in schools.\n";
		cout<<"2= Creating more employment opportunities for citizens\n";
		cout<<"3=Offering loans at low interest rate\n";
		cout<<"4= The government cannot help the poor\n ";
		cin>>choice;
		if(choice==1){
			rep++;
		}
		else if(choice==2){
			democratic++;
		}
		else if(choice==3){
			conserv ++;
		}
		else if(choice==4){
			republic++;
		}
		cout<<"b.The government should helps corporations to provide more employment opportunities\n";
		cout<<"1= Completely agree\n";
		cout<<"2= Somewhat agree\n";
		cout<<"3= Neutral\n";
		cout<<"4= Somewhat disagree\n";
		int choice1;
		cin>>choice1;
			if(choice1==1){
			rep++;
		}
		else if(choice1==2){
			democratic++;
		}
		else if(choice1==3){
			conserv ++;
		}
		else if(choice1==4){
			republic++;
		}
		cout<<"c. What can the government do to conserve the environment?\n";
		cout<<"1= Encourage people to plant more trees\n";
		cout<<"2= Recruit more people to take care of the environment\n";
		cout<<"3= The government should not do anything to conserve the environment since it is the role of the citizens\n";
		cout<<"4= The government should create strict rules and laws for environmental conservation \n";
		int choice2;
		cin>>choice2;
			if(choice2==1){
			rep++;
		}
		else if(choice2==2){
			democratic++;
		}
		else if(choice2==3){
			conserv ++;
		}
		else if(choice2==4){
			republic++;
		}
		cout<<"d. There should be more strict laws and regulations to eradicate corruption\n";
		cout<<"1= Completely agree\n";
		cout<<"2= Somewhat agree\n";
		cout<<"3= Neutral\n";
		cout<<"4= Somewhat disagree\n";
	   int choice3;
		cin>>choice3;
			if(choice3==1){
			rep++;
		}
		else if(choice3==2){
			democratic++;
		}
		else if(choice3==3){
			conserv ++;
		}
		else if(choice3==4){
			republic++;
		}
		cout<<"e. The government is liable to be transparent about all initiatives to the public\n";
		cout<<"1= Completely agree\n";
		cout<<"2= Somewhat agree\n";
		cout<<"3= Neutral\n";
		cout<<"4= Somewhat disagree\n";
		
		int choice4;
		cin>>choice4;
			if(choice4==1){
			rep++;
		}
		else if(choice4==2){
			democratic++;
		}
		else if(choice4==3){
			conserv ++;
		}
		else if(choice4==4){
			republic++;
		}
		cout<<"f. Which political party do you affiliate with?\n";
		cout<<"1=Rep\n";
		cout<<"2=Democratic\n";
		cout<<"3=Conservative\n";
		cout<<"4=Republic\n";
		int choice5;
		cin>>choice5;
			if(choice5==1){
			rep++;
		}
		else if(choice5==2){
			democratic++;
		}
		else if(choice5==3){
			conserv ++;
		}
		else if(choice5==4){
			republic++;
		}
		int choices[4] = {rep,democratic,conserv,republic};
		int max = choices[0];
		int index = 0;
		for(int i=0; i<4; i++){
			if(choices[i]>max){
				max = choices[i];
				index = i;
			}
		}
	string choices_string[4] = {"Rep","Democratic","Conservative","Republic"};


		cout<<"The political party is "<<choices_string[index]<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS