Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finding Mesas To be clear, all programming assignments in this class are individual assignments. In this assignment, you are tasked with using structs and dynamic

Finding Mesas
To be clear, all programming assignments in this class are individual assignments.
In this assignment, you are tasked with using structs and dynamic memory to find Mesas within a set of integers.
(This spec is long, and we recognize that. However, we attempted to answer a lot of questions that may come up within the spec. Please try to find the answers to your questions in here before asking.)
What is a Mesa?
A mesa is defined in the following way:
Given a set of non-negative integers, a mesa is a sequence of at least a given minimum identical values. The length of a mesa is the number of values in the sequence, and the mass of a mesa is the sum of the values in the sequence.
The first number in the dataset is the number of values to follow on that line. In the example below, the first number is 80, so there are 80 values following. The numbers highlighted in blue are on their own line. They represent the minimum length and minimum height of a valid Mesa in this set of data. In other words, there must be at least 34 of the same number in a row and that number must be at least 546 for a Mesa to be considered valid in this set of data.
80749749749749749749749749749749749749749749749749749
749749749749749749749749749749749749749749749749749546
546546546546546546546546546546546546546546546546546546
546546546546546546546546546546546546546546546546546546
546546546546546546546546546
34546
Given this data above, there are two valid mesas. The first mesa (highlighted in yellow) is the 34 values of 749 which have a mass of 25466(749*34) and the other (highlighted in purple) is the 46 values of 546 which have a mass of 25116(546*46). In this set of numbers the first mesa is the bigger of the two because it has a higher total mass, so that is the one we are asking you to find in this assignment.
Implementation
Download the starter code for the assignment:
array.cDownload array.c
array.hDownload array.h
mesa.hDownload mesa.h
main.cDownload main.c
Your implementation will be broken down into 3 files: main.c, array.c, and mesa.c. You will have corresponding header files array.h and mesa.h for the declarations in those C files.
array.c
We strongly encourage you to test that your array.c is working correctly and producing a clean Valgrind report before moving on. The more code you have, the harder it is to debug.
The array.c file will be responsible for handling operations related to the array input, including the management of the dynamic memory and the display of the formatted array in the output file.
The below declarations are all in the array.h file. You will be implementing 3 of them. read_data is implemented for you.
unsigned int* create_array( FILE* in, unsigned int *size );
unsigned int* free_memory( unsigned int* pointer );
void display_data( FILE* out, unsigned int count, unsigned int* data );
void read_data( FILE* in, unsigned int *data, unsigned int count );
When you submit your code, we will provide a file with this name with the appropriate declarations as shown as well as #includes for stdio.h and stdlib.h. If you need other libraries include, you will need to put those in your implementation file. (Hint: You shouldnt need any other header files.)
unsigned int* create_array( FILE* in, unsigned int *size );
FILE* in is an already opened pointer to the input file (assuming the input file was opened correctly and passed correctly from main)
unsigned int *size will store the number of elements remaining in the line that is read from the file once the function is over
The function returns a pointer to the dynamically allocated array of the given number of elements.
This function will read an unsigned integer from the file that is targeted by the FILE* named in. It will then dynamically allocate an array that is capable of storing the number of integers that was indicated by the number that was read. The array will not store fewer nor more integers than the number that was read indicates. Make an array that will store exactly that number of integers.
The function will return the pointer to the array that was dynamically allocated and the size parameter will store the number that was read in.
For example, if this is the line:
1012345678910
The array that is created will store 10 integers and the size parameter will store the value 10
unsigned int* free_memory( unsigned int* pointer );
unsigned int* pointer is a pointer to a previously dynamically allocated array of integers.
The function returns NULL so that the pointer can be reset in the calling function (the pointer itself will not change permanently in this function other than releasing the memory).
This function is given a pointer to a previously dynamically allocated array and releases the targeted memory, then returns NULL.
void display_data( FILE* out, unsigned int count, unsigned int* data );

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

=+a) Find the z-score of the observed proportion.

Answered: 1 week ago

Question

What were the reasons for their resistance?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago