Make a program that implements the sorting by pointers technique. A program cons
ID: 3576281 • Letter: M
Question
Make a program that implements the sorting by pointers technique. A program consists of modules (functions). The following is the calling hierarchy of the program you will build. It is a requirement that your program adhere to this calling diagram.
Here are the prototypes:
int getdata(double []);
void displayarray(double [], int)
void fillpointerarray(double[], double* [], int );
void sortby pointers(double*[],int);
void showdataviapaointers(doulbe*[],int);
The prototypes are requirements. There are no substitutes.
Here are the compilers:
The name of the C++ compiler is g++.
The name of the C compiler is gcc.
These compilers are requirements.
The switch or parameter to compile C++ code using the newest standard is
-std=c++11
The switch or parameter to compile C code using the newest standard is
-std=c99
The knowledge of the programmer is frequently seen in his or her use of command line parameters.
Required data types: The value in each cell of the data array is a double, which has size 8 bytes. Usually sort by pointers is implemented where each data object in the array is large in bytes. For instance, the object containing all the data about a student at CSUF including TDA is large. That object may have a size of 5 to 10 kilobytes. For simplicity in this program the data objects are reduced to type double.
Yes, I know you can sort aan array of doubles by traditional techniques, but that is of no interest here. Those techniques do not scale upward to large data objects.
Software requirements
The behavior of each module is is stated below. Each module must be implemented as stated. There are no alternatives
There are no work-arounds
There are no substitutions.
These are requirements.
At the corporation where you are employed (or will be employed) the customer has contracted with your employer to build a certain software system. The specifications state how the software will be built and how ti will perform. If the product you build does not meet the specs (also called requirements) you don’t get paid. That’s it.
Specifications for main
Main will be compiled with the C++ compiler. Main will call each of the other five functions whne needed. Main is responsible for producing output as shown in the sample run of this document. Main resides in a single file. Main declares all of the arrays needed in this program.
Specifications for getdata
This function is compiled with the C compiler. This function instructs the user to enter a sequence of double separated by white space until CNTL+D is entered. (Pressing the enter key is one way to input white space.) The getdata function counts the number of inputs and returns that integer to the caller . If no data are entered a zero is returned. These are fixed requirements: no alternative programming is accepted.
Specifications for displayarray
This function is compiled with the C compiler. This function receives and array of doubles and an integer from the caller, and displays the contents of the array one item per physical line. This function outputs no text and no messages. These are fixed requirements.
Specifications for fillpointerarray
This function is compiled with the C++ compiler. The function receives two arrays which we call the data array and the pointer array. Additionally, the function receives an integer. For each valid member of the data array this function will assign a pointer to the corresponding cell of the pointer array. For example, if the kth member of the data array is data[k] then the kth member of the pointer array will point to data[k]. This function does not output anything to the monitor nor to any file nor to any device. There are requirements: there are no work-arounds.
Specifications for sortbypointers
This function is compiled by the C++ compiler. This function receives exactly two parameters; the array of pointers and an integer. The programmer may select his or her favorite sort algorithm You, the programmer, must understand well your selected sort algorithm. Make this fundamental modification: “compare data items but swap pointers”. This function does not modify the data array. The data array is not passed to this function. This function does modify the pointer array. This function does not output any information: no text, no messages, no numbers.
Specifications for showdatabypointers
This function is compiled by the C compiler. The function receives the pointer array and an integer. For each element in the pointer array the function outputs the data value pointed to by that element. This function outputs one data value per line. This function does not output any text or headers or messages or anything else.
Specifications for classes and objects
There are no classes ,and no objects in this program mainly because C language does not support object oriented programming structures.
Optional matters
Header files are useful tools in both C and C++ languages. Most computer science majors at CSUF learn header files while learning C++. A header file typically has extension .h as in “sort.h” and typically contains function prototype(s).
There are no stated requirement for this program regarding the use of header files. If you learned to program using header files then feel free to use them here. In that case you will need:
getdata.h
displayarray.h
fillpointerarray.h
sortbypointer.h
showdataviapointers.h
Again, header files are a helpful tool, and you may decide to use them.
There are no stated requirements how to make functions available to the main function for calling. You may include the function in the main using a header file. An alternative technique is to simply place the function’s prototype in the file with the main function. For example,
int getdata(double[],int);
Because the getdata function resides in a separate file it may be necessary to declare that fact as in
extern “C” int getdata(double[],int);
The extern “C” is needed on prototypes of functions written in C++ and is not needed on functions written in C. Both techniques, including files or declaring prototypes, will accomplish the goal of making the function callable. You choose how to do it.
The script file is required.
This is a requirement. Script files must be part of your general open source knowledge. Make a script file that will compile each of the 6 source files, create an executable file, and execute that file. A script file is exceedingly easy to make and it must be part of your computer science general knowledge. An example of a Bash script file has been posted.
There is one alternative. If you know about makefiles then you may submit a makefile in place of a script file if desired. Makefiles are useful tools, but I don’t teach about them. You are free to use one in this programming assignment.
Sample run
This is a requirement; this shows how your output must appear.
Welcome to Sort by Pointers programmed by <your name>
Enter doubles, one per line, and press CNTL and D to terminate.
16.8
3.6
-4.5
10.2
0.0
6.3
4.1
Cntl and D were entered here; nothing appears as output.
7 doubles were inputted.
There values were saved in the data array:
16.8
3.6
-4.5
10.2
0.0
6.3
4.1
The pointer array will be populated next.
These are the data pointed to by the pointer arrray.:
16.8
3.6
-4.5
10.2
0.0
6.3
4.1
The data have been successfully sorted using the technique of sort by pointer.
Here are the sorted data:
-4.5
0.0
3.6
4.1
6.3
10.2
16.8
Here is the original unchanged data array:
16.8
3.6
-4.5
10.2
0.0
6.3
4.1
The main function will now terminate. Have a nice evening.
Testing
Test the script (or makefile)
First delete all existing object file and executable files.
Second enter ls -l to show the contents of the directory.
Third run the script fie (or makefile)
Fourth enter ls -l to show the contents of the directory.
Get data: Main: C Display array Fillpointerarra Sortbypointers: Showdataviapointers. C++Explanation / Answer
A perform definition in C programming consists of a perform header and a perform body. Here square measure all the components of a perform
Return sort A perform might come back a worth. The return_type is that the information form of the worth the perform returns. Some functions perform the specified operations while not returning a worth. during this case, the return_type is that the keyword void.
Function Name this is often the particular name of the perform. The perform name and therefore the parameter list along represent the perform signature.
Parameters A parameter is sort of a placeholder. once a perform is invoked, you pass a worth to the parameter. This worth is spoken as actual parameter or argument. The parameter list refers to the kind, order, and variety of the parameters of a perform. Parameters square measure optional; that's, a perform might contain no parameters.
Function Body The perform body contains a set of statements that outline what the perform will.
Example
Given below is that the ASCII text file for a perform known as max(). This perform takes 2 parameters num1 and num2 and returns the utmost worth between the 2
/* perform returning the GHB between 2 numbers */
int max(int num1, int num2) native variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
come back result;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.