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....
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...
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that contain what ever arbitrary integers and print out the array including the elements and use different functions so that the main only contains variables and function calls.
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT