Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to write a C program which includes the use of an array and 3 functions and follows the instructions below. Follow these detailed

You are to write a C program which includes the use of an array and 3 functions and follows the instructions below. Follow these detailed instructions:

1. First, read this document in its entirety.

2. Include the usual (detailed) comment block including program name, author, date, class & section #, professor, inputs, outputs and description, followed by your preprocessor directives.

3. An outline (Skeleton-code) of the source code is shown below and you are REQUIRED to follow this outline. Insert appropriate printf statements where needed to get the desired output. The outline has four sections where you are to enter in your code and complete the program.

a. Part 1: You are required to open a file for input and read the data in that file into an array (named data). Use the variable size to count how many elements in the file. Create the file yourself in notepad and call it data.txt so that it has the following numbers in order: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

b. Part 2: You are required to write the function called display which accepts an array, and a parameter named size which indicates the size of the array. This function prints the array (using the following format. List ==> # # # # # #) to the screen. A sample output is shown below. Display the original data array.

c. Part 3: You are required to write the function called reverse which accepts an array, and a parameter named size which indicates the size of the array. This function reverses the values in the array. In other words, flip the array from beginning to end. Display the flipped array using the function display created in part 2. A sample output is shown below. You are not allowed to create an extra integer array to solve this part, i.e., only the array that was sent from the main function is to be manipulated.

d. Part 4: You are required to write the function call countZerosOnes which counts the 0s and 1s from the array. The function MUST return the totalcount which will be the total of ones and zeros found. Display the number of 0s (numZeros) and number of 1s (numOnes). The number of 0s and 1s MUST be printed from main(). Also print the totalcount from main(). To be clear numZeros & numOnes will be passed to countZerosOnes by pointers and totalcount will be returned from countZerosOnes.

e. A sample output is shown below.

Deliverable: Submit ONLY your source code to Blackboard.

EGR 106 Structured Programming in C Fall 16 - 3 -

Input file: data.txt 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 Sample output: Original Data: List ==> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 Flipped Data: List ==> 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 Number of zeros in original array = 3. Number of ones in original array = 2. Total count of ones & zeros = 5.

OUTLINE OF THE SOURCE CODE:

#include // include other header files that you need

#define MAX 100

void reverse (int data[MAX], int size);

int countZerosOnes (int data[MAX], int size, int *pNumZeros, int *pNumOnes);

void display (int data[MAX], int size);

int main (void) { FILE *fp; int size=0,numZeros,numOnes,totalcount; //totalcount= return the number of zeros and ones found in the array int data[MAX];

//Code for PART 1 goes here, open & read the file. Include ALL error checks. //Display the array //Call function to reverse data //Display the array //Call function to count 0s and 1s. //Print number of 0s (numZeros) and 1s (numOnes) found in array. Print in main. //Print total number (totalcount) of 0s and 1s found in the array. This value must be returned from the function countZerosOnes. Print in main. return 0; } // Code for PART 2 goes here // Code for PART 3 goes here // Code for PART 4 goes here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions