Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me finish this code I have done. This is C language. The objective of this Final is to access your understanding of ADTs,

Please help me finish this code I have done.

This is C language. The objective of this Final is to access your understanding of ADTs, structs, reading and writing to files (text view), and setting up a multifile program. Write a function that addresses each requirement listed below. It should only contain the 3 required files.

Here is the assignment.

image text in transcribedimage text in transcribed

Here is the code I did for ADT.c file

#include

#include

#include

#include "adt.h"

// Function to create a new DataStorage object

DataStorage *createDataStorage() {

DataStorage storage = (DataStorage )malloc(sizeof(DataStorage));

if (storage == NULL) {

fprintf(stderr, "Memory allocation error ");

exit(EXIT_FAILURE);

}

storage->count = 0;

storage->records = NULL;

return storage;

}

// Function to free the memory allocated for DataStorage

void destroyDataStorage(DataStorage *storage) {

free(storage->records);

free(storage);

}

// Function to print records with record numbering

void printRecords(DataStorage *storage) {

// Implementation of printRecords function

}

// Function to add a new record to DataStorage

void addRecord(DataStorage storage, int index, const char name) {

// Implementation of addRecord function

}

// Function to remove a record by index

void removeRecord(DataStorage *storage, int index) {

// Implementation of removeRecord function

}

// Function to write records to a file

void writeToFile(DataStorage storage, const char filename) {

// Implementation of writeToFile function

}

// Function to read records from a file

void readFromFile(DataStorage storage, const char filename) {

// Implementation of readFromFile function

}

// Function to sort records in ascending order

void sortRecords(DataStorage *storage) {

// Implementation of sortRecords function

}

For this Final, you need to implement a program that solves the specific problem statement you have been given via canvas. Note that it is more important for you to solve each program requirement than fully address the problem statement. Your storage should be divided into 2 parts. An object that keeps track of the number of instances of data you have stored, as well as where that data is. And the struct that keeps track of an instance of data as specified in the problem statement. PROGRAM REQUIREMENTS - You should follow basic design principles with good variable names, well defined functions, a header comment with your name (in every file) and problem statement, and meaningful comments throughout your code. - You should store all data objects, during program execution, using struct(s) that you define and create. The client code should not have direct access to your data storage object (ADT). Follow the file naming rules in your problem statement. - You should have a client file that runs each command (see required functionality below), an ADT file that handles operations on your data, and a header file that only exposes necessary functionality to the client. - You should be able to print current data to stdout. You should include record numbering so the user knows how many records are present and what their index is - You should be able to add a record, any amount you want using dynamic memory. You should use a \#define LENGTH 50 array for any char arrays you need to store. This will involve a function that has 4 parameters matching your struct. You do not need to validate input, can assume it is valid. - You should be able to remove a record, by index. Check for no records. You can use any method you prefer to fill in the gap, EG shift down or copy last to gap. - You should be able to write records to a file. - You should be able to read records from a file, that were previously written. This should replace any existing records. You can assume file exists and has data. - You should be able to sort your records, see problem statement for specifics on how the data should be sorted. Only ascended sort needs to be implemented. - Valgrind should record no issues with reading or writing to unallocated blocks, and all memory should be freed correctly at the end of execution. Each bullet point is worth 10% of the grade for your final. Every operation, EG Save to File, should print a basic message when invoked. The client file does not need to have live interaction with the ADT. However you should be able to choose to do one of the following batch operations. - Create records (at least 5), print records, save to file, end program. - (from a blank state) load from file, add 5 records, display records, (repeat following 2 commands 11 times) delete last record, display records. Afterwards end program. - Create records (at least 2), save to file, create record, print records, load records, print records, end program. I will create additional scenarios to test your code, but if you can pass these 3 then you should be able to

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago