Lab Program 3 – Pointers, Strings, & Integers

$25.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Abstract
Given an input file that contains a number of lists specified as the first number
in the file and wherein each list will consist of a number of elements in the list,
and a list of integers, or a list of strings, in any order, create a singly linked list
of the numbers or in a separate list, the strings – and so on for however many
lists there are in the input file. Then once the lists are completely linked, total
the numbers in the mode described below. Likewise, concatenate the strings as
described below. These tasks should be accomplished using pointer manipulations
only, that is arrays are not allowed. Also, make sure to demonstrate good memory
management techniques.
1 Objectives
1.1 Inputs
There are two basic inputs, the input file name, passed via the command line, and the
input file data defined below.
1.1.1 Command Line arguments
The input file name will be input as follows:
• pointerFun filename.ext
• In the event that the input file is not available or there is an error finding the
file, an appropriate error message shall be displayed. Use the example below for
guidance.
• pointerFun ERROR: File “bogusFilename” not found.
1
1.1.2 Input File fields
The first line of the file will have a single positive integer k, representing the number
of lists in the file. Each list will follow. The first line of each list will have an integer
number that represents the number of elements to be read and added to the linked list
created for this list of inputs. The linked list should preserve the order in which the
elements are read in.
Please note that it is incumbent upon the program to determine if the list contains
strings or integers. The input file will contain the appropriate number of elements corresponding to the number of elements specified for the test case.
HINT: If the list is a list of strings, it would be highly advantageous to create a linked
list structure that contained a pointer to the malloc’ed string buffer. A list of integers
could contain a linked list structure that contains integer data.
The input file, shown below, will NOT include comments. The comments and line
spacing shown below are for clarification.
2 //Number of test cases
4 //The count of numbers in the list
6 //First number in the list
4 //Second number in the list
5 //Third number in the list
6 //Fourth number in the list
4 //The count of strings in the list
“blue” //The first string in the list
“dog” //The second string in the list
“red” //The third string in the list
“cat” //The fourth string in the list
The actual file’s data would be as shown below:
2
4
6
4
5
6
4
blue
2
dog
red
cat
2 Process
The program can assume that once a list of integers or strings has begun, the rest of the
list will be of the appropriate type. That is a list of integers will always contain integers
thru the end of the list. This will also be true for strings.
Also note that the program will have to walk the singly linked list to get every other
element, then walk the list again to get the elements that were not totaled or concatenated in the first pass.
In the event the list contains strings make sure to create an output buffer that will
be large enough for every string and the terminating NULL.
3 Outputs
The output of the program will be for however many lists were read in and the corresponding data for each list.
For the data shown above the outputs are shown below.
The total of the odd numbered numbers 6, 5 is 11
The total of the even numbered numbers 4, 6 is 10
The concatenation of (blue, red) is “blue red”
The concatenation of (dog, cat) is “dog cat”
3
4 Grading
Scoring will be based on the following rubric:
Table 1: Grading Rubric
Percentage Description
-100 Cannot compile on Eustis
– 50 Cannot accept input filename as command
line argument
– 30 Cannot read input file
– 30 Does not calculate or concatenate the input
file’s data correctly.
5 Submission Instructions
The assignment shall be submitted via WebCourses.
The source file named pointerFun.c.
1
1 With comments that confirm – “Your statement that the program is entirely your own work and that
you have neither developed your code together with any another person, nor copied program code from any
other person, nor permitted your code to be copied or otherwise used by any other person, nor have you
copied, modified, or otherwise used program code that you have found in any external source, including but
not limited to, online sources”.
4