Question

In: Computer Science

Write in C++ Write a program that accepts the names of three political parties and the...

Write in C++

Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received.   Be sure to provide labels (party name) and number-align your output values.

Solutions

Expert Solution

ANSWER:-

#include <iostream>
using namespace std;

int main() {
   string a,b,c;
   int x,y,z;
   cout<<"enter first party name and votes : ";
   cin>>a>>x;
   cout<<"enter second party name and votes : ";
   cin>>b>>y;
   cout<<"enter third party name and votes : ";
   cin>>c>>z;
   int total=x+y+z;
   float per_a=(float)(x*100)/total;
   float per_b=(float)(y*100)/total;
   float per_c=(float)(z*100)/total;
   cout<<"party name vote %"<<endl;
   cout<<a<<" "<<per_a<<endl;
   cout<<b<<" "<<per_b<<endl;
   cout<<c<<" "<<per_c;
   return 0;
}

OUTPUT :

// If any doubt please comment


Related Solutions

Write a program that accepts the lengths of three sides of a triangle as inputs. The...
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
Examine three roles of political parties in American politics. In what ways do political parties differ...
Examine three roles of political parties in American politics. In what ways do political parties differ from interest groups? How do parties contribute to democratic government?
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Using OOP, write a C++ program that will read in a file of names. The file...
Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
C++ // Program Description: This program accepts three 3-letter words and prints out the reverse of...
C++ // Program Description: This program accepts three 3-letter words and prints out the reverse of each word A main(. . . ) function and the use of std::cin and std::cout to read in data and write out data as described below. Variables to hold the data read in using std::cin and a return statement. #include <iostream > int main(int argc, char *argv[]) { .... your code goes here }//main Example usage: >A01.exe Enter three 3-letter space separated words, then...
Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT