Very Urgent Pleaaaaase Create a C++ program I) A democrat and a republican are r
ID: 3849721 • Letter: V
Question
Very Urgent Pleaaaaase
Create a C++ program
I) A democrat and a republican are running for an open seat in the House of Representatives. In an exit poll voters are asked which candidate they voted for. We want a program to calculate what percentage of votes each candidate received. We will do this in two steps (Submit ONE final program)
(a) Write a program to do the following. It asks the data entry clerk to enter which candidate each voter voted for. If the voter voted for the democrat, enter the letter ‘D’. If the voter voted for the republican, enter the letter ‘R’. If the voter voted for anybody else, enter the letter ‘O’. The program should use a while loop to asks for the votes one by one. When there is no more votes to enter, ‘Q’ will be entered to terminate the loop. Don’t count anything yet. Simply ask for the votes with a while loop. Remember that the user may enter uppercase or lowercase letters. Your program should be able to handle both.
(b) Modify the program in part (a) so that it will do the following using a switch statement:
(1) counts and display the number of votes the democrat candidate received
(2) counts and display the number of votes the republican candidate received
(3) counts and display the number of votes other candidates received, i.e. the number of times ‘O’ or ‘o’ is entered
(4) calculate and display what percentage of total votes each candidate received (democrat, republican, and others)
Create a C program that calculates and displays an employee's number of eligible vacation days based on their years of service at a company. The program should derive the number of vacation days using the information in the following table: Years of Service Eligible Vacation Days Less than 5 years 10 days 5-10 years 15 days 20 daystO of years cover 10 years x50% Over 10 years getEmployee NameAndrears0: a void function that asks for the employee's name and Number of Years of Service. Use pass-by-reference to send these two items to main0 calcVacationDays0: a value returning function that calculates and returns the number of Eligible Vacation Days to main0 The maino function should display theEmployee's full name and number ofEligible Vacation Days on the computer screen.Explanation / Answer
1.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char vote = 'A';
int democrat,republic,other;
democrat = republic = other = 0; //initialize count of votes to 0
while(vote != 'Q' && vote != 'q')
{
cin>>vote; //input vote
if(vote == 'Q' || vote == 'q')
break;
switch(vote)
{
case 'D':
case 'd': democrat++;
break;
case 'R':
case 'r': republic++;
break;
case 'O':
case 'o': other++;
break;
default : cout<<" Invalid vote";
}
}
cout<<" The number of votes the democrat candidate received : "<<democrat;
cout<<" The number of votes the republic candidate received : "<<republic;
cout<<" The number of votes the other candidate received : "<<other;
cout<<" percentage of democrat votes "<<democrat*100/(democrat+republic+other);
cout<<" percentage of republic votes "<<republic*100/(democrat+republic+other);
cout<<" percentage of other votes "<<other*100/(democrat+republic+other);
return 0;
}
Output:
d
r
D
r
o
O
D
D
q
The number of votes the democrat candidate received : 4
The number of votes the republic candidate received : 2
The number of votes the other candidate received : 2
percentage of democrat votes 50
percentage of republic votes 25
percentage of other votes 25
2
#include <iostream>
using namespace std;
void getEmployeeNameAndYears(char *name,int *years)
{
cout<<" Enter the full name of the employee : ";
cin.getline(name,20);
cout<<" Enter his years of service : ";
cin>> *years;
}
int calcVacationDays(int years)
{
if(years < 5)
return 10;
else if(years >= 5 && years <=10)
return 15;
else if(years > 10)
return (20 + (years-10)*0.5);
}
int main()
{
char name[20];
int years;
getEmployeeNameAndYears(name,&years);
cout<<" Number of eligible vacation days = "<<calcVacationDays(years);
return 0;
}
Output:
Enter the full name of the employee : Smith Jones
Enter his years of service : 12
Number of eligible vacation days = 21
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.