Question

In: Computer Science

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.

  1. 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

Use the data from the example below.

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

Candidates                           Subdivisions                  Totals

                             Aberdeen   Brock     Sahali        

Audrey                     600            800          800            2200

Brian                        700            700          600            2000

Elizabeth                  800           700          800           etc

Peter                        400            450         300             

Zachary                  900            900       900            

Totals                     3400            etc                              etc

Solutions

Expert Solution

// C code for given requirements

#include<stdio.h>
int main()
{
const char *names[]={"Audrey","Brain","Elizabeth","Peter","Zachary"};
const char *divisions[]={"Aberdeen","Brock","Sahali\n"};
int aberdeenvotes[]={600,700,800,400,900};
int brockvotes[]={800,700,700,450,900};
int sahalivotes[]={800,600,800,300,900};
int rowcount[5],total[3]={0},grandtotal=0,i;
//compute row total
for(i=0;i<5;i++)
rowcount[i]=aberdeenvotes[i]+brockvotes[i]+sahalivotes[i];
//compute column total
for(i=0;i<5;i++){
total[0]=total[0]+aberdeenvotes[i];
total[1]=total[1]+brockvotes[i];
total[2]=total[2]+sahalivotes[i];
}
//compute grandtotal
for(i=0;i<3;i++)
grandtotal+=total[i];
//printing output statements
printf("Candidates \t\t\t Subdivisions\t\t Totals\n");
printf("\t\t %s \t %s \t %s",divisions[0],divisions[1],divisions[2]);
for(i=0;i<5;i++)
printf("\n%s \t%d \t\t %d \t\t %d \t\t %d",names[i],aberdeenvotes[i],brockvotes[i],sahalivotes[i],rowcount[i]);
  
//column totals and grandtotal print statement
printf("\nTotals: ");
for(i=0;i<3;i++)
printf(" \t%d\t",total[i]);
//print grand total
printf("\t%d",grandtotal);
}


Related Solutions

Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
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...
Done in C++, Write a program to read the input file, shown below and write out...
Done in C++, Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets 6 Philadelphia 31, Tampa Bay 20 Green Bay 19,...
Write a  program in c++ using a map to create the following output. Here is the list...
Write a  program in c++ using a map to create the following output. Here is the list of students: 100: Tom Lee 101: Joe Jones 102: Kim Adams 103: Bob Thomas 104: Linda Lee Enter a student an ID to get a student's name: ID:  103 students[103] - Bob Thomas # of students: 5 Delete a student (Y or N)?  Y Enter ID of student to be deleted:  103 Here is the list of students after the delete: 100: Tom Lee 101: Joe Jones...
Can you write a program for snakes and ladder board game using linked lists in c++
Can you write a program for snakes and ladder board game using linked lists in c++
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight *...
Edit the given program to produce the following output in c++ mode: - Take in the...
Edit the given program to produce the following output in c++ mode: - Take in the name of a superhero & tell him how many villains he/she has to defeat today - The number of villains is randomly generated and should be a number between 11 and 42. - Use a seed of 7. Hint: Compile the program first before making edits What is your name? Hello Captain America There are 42 villains you need to defeat today Oops! one...
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the...
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the input via ignoring the case sensitivity. For example, sample outputs could be like below. Please input a string: This is a list of courses. CSC 1010 - COMPUTERS & APPLICATION Here is the letter frequency: Letter a or A appears 3 times Letter b or B appears 0 times Letter c or C appears 5 times Letter d or D appears 0 times Letter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT