Question

In: Computer Science

Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...

Code should be Written in C

  1. Using initialization lists, create 5 one-dimensional arrays, one for each of these:
  • hold the names of the people running in the election
  • hold the names of the subdivision
  • hold the vote counts in the Brampton subdivision for each candidate
  • hold the vote counts in the Pickering subdivision for each candidate
  • hold the vote counts in the Markham subdivision for each candidate

Use the data from the example below.

* Your C program should take the data in the arrays and produce the output below, neatly formatted as shown:

Candidates                            Subdivisions                 Totals

                             Brampton  Pickering Markham        

Aubrey                     600            800          800            2200

Blake 700            700          600            2000

Chubbs 800           700          800           etc

Oliver 400            450         300             

Zamier 900            900       900            

Totals                     3400            etc                              etc

  1. Create a function that will find the total votes in one subdivision and return that to main( ). Call this function 3 times to produce the 3 totals in the last line of output.

  1. Create a function that will find the total votes for one candidate and return that to main( ). Call this function 5 times to produce the 5 totals in the last column of output. Be very careful with the parameter list here. Send the function only the information it needs.
  1. Create a function that will output the first 2 lines of headings.

Solutions

Expert Solution

IDE Used: Dev C++

Code: election.c (can be given any name with .c extension)

#include <stdio.h>
#include <stdlib.h>

//this function is to calculate total number of votes in each subdivision
//input parameter will be the name of array storing votes of subdivision

int total_sub_vote(int votes[])
{
   int i;
   int total=0;
   for(i=0; i<5;i++)
   {
       total=total+votes[i];
  
   }
   //It will return the total votes of that subdivision
   return total;
}

//This function is to calculate total votes of each candidate
//Input will be votes of that candidate in each subdivision

int tot_can_vote(int subdiv1, int subdiv2, int subdiv3)
{
   return subdiv1+subdiv2+subdiv3;
  
}

//function to display the first two lines of the header in output
void heading(char **subdiv_array)
{
   char column1[15] = "Candidate";
   char column2[15] = "Subdivision";
   char column3[15] = "Totals";
   printf("%s %17s %20s\n", column1,column2, column3);
   printf ("\t %10s %10s %8s\n", subdiv_array[0], subdiv_array[1], subdiv_array[2]);
  
}

//main function
int main()
{
   int i;
  
   //to store total votes of candidates
   int tot_vote_cand;
  
   //array to store candidate names
   char *candidates[5] = {"Aubrey", "Blake", "Chubbs", "Oliver", "Zamier"};
  
   //array to store subdivision name
   char *subdivision[3] = {"Brampton", "Pickering", "Markham"};
  
   //array to store votes in Brampton
   int vote_Brampton[5] = {600,700,800,400,900};
  
   //array to store votes in Pickering
   int vote_Pickering[5] = {800,700,700,450,900};
  
   //array to store votes in Markham
   int vote_Markham[5] = {800, 600, 800, 300, 900};
  
   //calling the function to print heading
   heading(subdivision);
  
  
   for(i=0;i<5;i++)
   {
   //calling the function to calculate total votes of candidates
   //it will be called three times

       tot_vote_cand = tot_can_vote(vote_Brampton[i],vote_Pickering[i],vote_Markham[i]);   
      
       //printing the result
       printf("%7s %10d %10d %8d %8d\n",candidates[i],vote_Brampton[i],vote_Pickering[i],vote_Markham[i], tot_vote_cand);
   }
  
   //calling the fucntion to calculate the total vote of each subdivision
   //it is called three times

   printf("%7s %10d %10d %8d\n","Total",total_sub_vote(vote_Brampton),total_sub_vote(vote_Pickering),total_sub_vote(vote_Markham));

   return 0;
}

Code Snippets

Output


Related Solutions

Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election hold the names of the subdivision hold the vote counts in the Brampton subdivision for each candidate hold the vote counts in the Pickering subdivision for each candidate hold the vote counts in the Markham subdivision for each candidate Use the data from the example below. Your C program should take the...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists,...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election (see note below) hold the names of the subdivision (see note below) hold the vote counts in the Aberdeen subdivision for each candidate hold the vote counts in the Brock subdivision for each candidate hold the vote counts in the Sahali subdivision for each candidate...
The code should be written in c++. It should be in only OpenGL // ***** ONLY...
The code should be written in c++. It should be in only OpenGL // ***** ONLY OpenGL PLEASE ******// write a program snippet that accepts the coordinates of the vertices of a rectangle centered around the origin, with edges that are parallel to the X and Y axes, and with aspect ratio W and converts it into a rectangle centered around the origin with aspect ratio of 1/W. The program has to figure W from the given points. You MUST...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4 and 192.3. In the gallons array, store the numbers 10.3, 15,6, 8.7, 14, 16.3, 15.7, 14.9, 10.7 , 8.3 and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the...
Compare PHP code used to create and update two-dimensional arrays to another programming language. Which is...
Compare PHP code used to create and update two-dimensional arrays to another programming language. Which is easier and more efficient? Why? Can be compared to any other well used language.
Code should be written in C++ using Visual Studios Community This requires several classes to interact...
Code should be written in C++ using Visual Studios Community This requires several classes to interact with each other. Two class aggregations are formed. The program will simulate a police officer giving out tickets for parked cars whose meters have expired. You must include both a header file and an implementation file for each class. Car class (include Car.h and Car.cpp) Contains the information about a car. Contains data members for the following String make String model String color String...
Code in C++. Using ONE of the following themes to create a class and demonstrate the...
Code in C++. Using ONE of the following themes to create a class and demonstrate the idea. Use this to create a solution (two ADTs and a driver program) to demonstrate the following concepts. Create a one page summary to describe where you are using each of these concepts. Themes:(PICK ONE) a house has a door a semester has a holiday break a cell phone has a shatterproof case a chair has a cushion Concepts to include: composition separating interface...
LEVEL ONE Lists and indexing Create a list x that spans 1 to 100 using 5...
LEVEL ONE Lists and indexing Create a list x that spans 1 to 100 using 5 unit increments.                                 Hint: Use the inline for and range(). Create a list y containing the elements from x that are divisible by 2.                                 Hint: Explore the for … if … statement. Do b. in another manner. Hint: Use , e.g., array() and where() from numpy. LEVEL TWO Arrays in numpy Create an array x that contains a random set of 100 uniform(0,10)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT