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...
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...
Can you write a program for the card game WAR using linked lists in c++!
Can you write a program for the card game WAR using linked lists in c++!
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,...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program (we do not claim that every line of output makes sense ;-). public class Mystery { public static void main(String[] args) { String john = "skip"; String mary = "george"; String george = "mary"; String fun = "drive"; statement(george, mary, john); statement(fun, "george", "work"); statement(mary, john, fun); statement(george, "john", "dance"); } public static void statement(String mary, String john, String fun) { System.out.println(john + "...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT