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...
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...
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....
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...
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...
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an...
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t specify a size and don’t initialize with values. Starting with 2, pushing these into the back of the vector:   2, 4, 6, 8, 10 vector capacity (array size) changes and is dependent on the compiler. The size of the list is now 5. The vector capacity (array size) is 6. The back element is: 10 The front element is: 2 Now deleting the value at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT