
Zarya G.
asked 03/31/21Part 1- Make an application in which you need to implement all discussed programming tools i.e. ordered arrays, Abstract data types, linked lists, recursion etc. must be implemented
Part 1- Make an application in which you need to implement all discussed programming tools i.e. ordered arrays, Abstract data types, linked lists, recursion etc. must be implemented
Part 2- Make a report of your application. Report should clearly justify following things
1) Your different code sections where above mentioned programming tools have been used.
2) Reason, which tool has been selected in which scenario.
3) How many tools you have implemented.
1 Expert Answer

Patrick B. answered 04/01/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define STR_SIZE (25)
typedef struct _TDataRec
{
long longIntNum;
double flAmount;
char str[STR_SIZE];
} * TDataRec;
typedef struct _TDatarec datarec;
#define DATA_REC_SIZE (sizeof(struct _TDataRec))
typedef struct _TQueueNode
{
struct _TDataRec dataRec;
struct _TQueueNode * next;
} * TQueueNode;
typedef struct _TQueue
{
TQueueNode first;
TQueueNode last;
int count;
} * TQueue;
Queue_Init(TQueue queue)
{
queue->count=0;
queue->first = queue->last = NULL;
}
Queue_Push(TQueue queue, TDataRec dataRec)
{
TQueueNode newNode = (TQueueNode) malloc(sizeof(struct _TQueueNode));
newNode->next = NULL;
memcpy(&newNode->dataRec,dataRec,DATA_REC_SIZE);
if (queue->count==0)
{
queue->first = queue->last = newNode;
}
else
{
queue->last->next = newNode;
queue->last = queue->last->next;
}
queue->count++;
}
Queue_Destroy(TQueueNode cur)
{
if (cur->next!=NULL)
{
Queue_Destroy(cur->next);
}
free(cur);
}
typedef int (*FilterCallback) (TDataRec);
DataRec_Init(TDataRec dataRec, long n, double amt, char * str)
{
dataRec->longIntNum = n;
dataRec->flAmount = amt;
memset(dataRec->str,0,STR_SIZE);
strncpy(dataRec->str,str,STR_SIZE-1);
}
int CompareDataRecByNumber(const void * rec1, const void * rec2)
{
TDataRec dataRecPtr1 = (TDataRec)rec1;
TDataRec dataRecPtr2 = (TDataRec)rec2;
int iReturn=0;
long longIntNum1 = dataRecPtr1->longIntNum;
long longIntNum2 = dataRecPtr2->longIntNum;
if (longIntNum1!=longIntNum2)
{
iReturn = (longIntNum1>longIntNum2) ? 1 : -1;
}
return(iReturn);
}
int CompareDataRecByAmount(const void * rec1, const void * rec2)
{
TDataRec dataRecPtr1 = (TDataRec)rec1;
TDataRec dataRecPtr2 = (TDataRec)rec2;
int iReturn=0;
double amount1 = dataRecPtr1->flAmount;
double amount2 = dataRecPtr2->flAmount;
if (amount1!=amount2)
{
iReturn = (amount1>amount2) ? 1 : -1;
}
return(iReturn);
}
int CompareDataRec(const void * rec1, const void * rec2)
{
TDataRec dataRecPtr1 = (TDataRec)rec1;
TDataRec dataRecPtr2 = (TDataRec)rec2;
return(
stricmp(dataRecPtr1->str,dataRecPtr2->str)
);
}
int CompareDataRecBySubtotal(const void * rec1, const void * rec2)
{
TDataRec dataRecPtr1 = (TDataRec)rec1;
TDataRec dataRecPtr2 = (TDataRec)rec2;
double subtotal1 = dataRecPtr1->longIntNum * dataRecPtr1->flAmount;
double subtotal2 = dataRecPtr2->longIntNum * dataRecPtr2->flAmount;
int iReturn=0;
if (subtotal1!=subtotal2)
{
iReturn = (subtotal1 > subtotal2) ? 1 : -1;
}
return(iReturn);
}
int Menu()
{
int iChoice;
cout << " (1) Sort/Filer by number " << endl;
cout << " (2) Sort/Filer by amount " << endl;
cout << " (3) Sort/Filer by Stricker" << endl;
cout << " (4) Sort/Filer by subtotal" << endl;
cout << "---------------------" << endl;
cout << " INPUT SELECTION OR ZER0 to QUIT :>";
cin >> iChoice;
return(iChoice);
}
void RandomDataRec(TDataRec dataRec)
{
dataRec->longIntNum = rand()*rand()%999999;
dataRec->flAmount = rand()*1.0f/rand()*rand();
int nStrLen = rand()%11;
for (int iLoop=0; iLoop<nStrLen; iLoop++)
{
dataRec->str[iLoop] = 'A' + rand()%26;
}
dataRec->str[nStrLen]=0;
}
Queue_Display(TQueue queue)
{
TQueueNode cur=queue->first;
for (int iLoop=0; iLoop<queue->count; iLoop++)
{
cout << cur->dataRec.longIntNum << " " << cur->dataRec.flAmount << " " << cur->dataRec.str << endl;
cur=cur->next;
}
}
Go()
{
int N=0;
double minVal=0;
double maxVal=0;
srand(time(NULL));
while (N<=0)
{
cout << "How Many ??? :> ";
cin >> N;
}
while (minVal<0)
{
cout << "Min Value :> ";
cin >> minVal;
}
while (maxVal<=0)
{
cout << "Max Value ??? :> ";
cin >> maxVal;
}
if (minVal>maxVal)
{
double tempVal = minVal;
minVal=maxVal;
maxVal=tempVal;
}
TDataRec dataRecs = (TDataRec) malloc(N*DATA_REC_SIZE);
for (int iLoop=0; iLoop<N; iLoop++)
{
RandomDataRec(&dataRecs[iLoop]);
}
int iMenuChoice=-1;
while ((iMenuChoice=Menu())!=0)
{
switch (iMenuChoice)
{
case 1:
{
qsort(dataRecs,N,DATA_REC_SIZE,CompareDataRecByNumber);
break;
}
case 2:
{
qsort(dataRecs,N,DATA_REC_SIZE,CompareDataRecByAmount);
break;
}
case 3:
{
qsort(dataRecs,N,DATA_REC_SIZE,CompareDataRec);
break;
}
case 4:
{
qsort(dataRecs,N,DATA_REC_SIZE,CompareDataRecBySubtotal);
break;
}
} //switch
struct _TQueue Q;
Queue_Init(&Q);
for (int iLoop=0; iLoop<N; iLoop++)
{
cout << dataRecs[iLoop].longIntNum << " " << dataRecs[iLoop].flAmount << " " << dataRecs[iLoop].str;
if (iMenuChoice==4)
{
cout << " subtotal = " << dataRecs[iLoop].flAmount * dataRecs[iLoop].longIntNum;
}
if ((dataRecs[iLoop].longIntNum>=minVal) && (dataRecs[iLoop].longIntNum<=maxVal))
{
Queue_Push(&Q,&dataRecs[iLoop]);
}
cout << " "<< endl;
}
cout << "******* FILTER *******" << endl;
Queue_Display(&Q);
cout << "*****************" << endl;
cout << "--------------------------------------------------------------------\n\n" << endl;
Queue_Destroy(Q.first);
} //while
free(dataRecs);
}
int main()
{
Go();
}
Zarya G.
thank you very much04/01/21
Zarya G.
sir can you explain. For which purpose this program is used??04/01/21

Patrick B.
I sorts and filters an array of data records (STOCK records) where the integer is the # of shares, the float is the price and the string is the stock ticket04/02/21
Zarya G.
Sir.. can you explain briefly?04/02/21

Patrick B.
Sorts the array by number, or by amount, or by string. THEN the records whose numbers are LESS than 500k are stored in the queue, which ; After output, Recursively frees the queue04/04/21

Patrick B.
I have asked TWICE what this assignment is about and what the program is supposed to do. I did not receive an answer so it appears as though you are free to code whatever you like as long as it features sorted arrays, linked lists, and recursion. Take the code and go.04/04/21
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
1) arrays are sorted by number, amount, string, and subtotal 2) queue contains the filter results 3) queue_destroy recursively frees the nodes in the queue04/01/21