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...
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...
Need this C++ code to be modified to work in C, still using 2d arrays... #include...
Need this C++ code to be modified to work in C, still using 2d arrays... #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; //Implementation of main function int main() { srand(time(NULL)); //Declaration of output,result,i,j,k ,figure as integer type and //assign flog with 0 int output[5][5], result[5], i, j, k, figure = 0; //Display statement cout << "The classic BINGO cards contains 25 squares arranged in five vertical" << endl; cout << "columns and five side to side rows. Each...
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)...
Code: C++ Write a very general sort method that can sort any type of data arrays/lists....
Code: C++ Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT