• Hi guest! As you can see, the new Wizard Forums has been revived, and we are glad to have you visiting our site! However, it would be really helpful, both to you and us, if you registered on our website! Registering allows you to see all posts, and make posts yourself, which would be great if you could share your knowledge and opinions with us! You could also make posts to ask questions!

[Help] ADT (Abstract Data Type) Structure in C -- Need advice

Someone's asking for help!
Joined
Sep 9, 2021
Messages
9,697
Reaction score
5,256
Awards
33
So in my 200% effort Journal, I have listed source code for a project that would be easy for Agares and Jeliel. The program ran.c is concentrated on safely returning missing/runaways. In order to do this it is necessary down the line a scrolling LED Text functionality. Way down the road from where Im at.
Let me show you a bit of the source, and the function prototypes...
#include <stdio.h>
#include <stdlib.h>
#inlcude <math.h>
#include <ctype.h>
#include <string.h>
/* Pre-processor directives and includes */

/*
Purpose: This program reads two files, runaways and motivational/HelpNumbers.
The goal is to return the runaways to a SAFE environment.
Once a runaway is found, flags are updated to signal to update the returns file,
and unlink the runaway node and insert into the return list.
At that point the flags are read everything updated.
There is an interface engineers will have to create and implement.
*/

/* Abstract Data Type structure definitions */
/* Runner data and stats ADT using runners.dat file */
typedef struct Runner {
char* runner_name[40];
char* runner_age[3];
char* runner_gender[2];
char* runner_contact[20];
} runner;

/* Returns data and stats ADT using returns.dat file */
typedef struct Returns {
char* returns_name[40];
char* returns_age[3];
char* returns_gender[2];
char* returns_contact[20];
} returns;

/* Motivational messages ADT using motivation.txt file */
typedef struct Motivational
{
/* To comply with characters display size for LED text scroll devices */
char* Intro_String[40];
char* Core_Motivational_String[40];
char* List_Help_Num_String[40];
} motivational;

/* SAFE houses and mental health and DPS numbers ADT using SAFE.dat file */
typedef struct SAFENumbers {
char* SAFE_address[40];
char* SAFE_state[3];
char* SAFE_zipcode[6];
char* SAFE_contact[20];
} safenumbers;

/* FOR ENGINEERS TO IMPLEMENT -- interface for LED text scrolling devices */
typedef struct LED_Device_Interface { } LEDDevInterface;

typdef struct Histogram { } histogram;

typedef struct Statistics { } statistics;

typedef struct Set_ADT {
/*
Items are inserted and deleted, there is no inherent order in the
items in a given set. Merge_set, however does a merge-sort on the
items in the given set(s). Before any call is made to a set operation,
The set has been declared and a constructor has been applied.
The '==' and '<<' operators apply to values of ItemType.

} set_adt;
typedef struct set_adt set;

typedef struct List
{

}list_adt;
typedef struct list_adt list;

Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"
Runner runaway_list(list L);
list L, runaway_list, return_list, safe_list;
set S, S1, S2, MergedSet, joinedSet;
int numSetItems;

/* Function Prototypes */
Void setMakeEmpty(set S);
boolean setIsEmpty(set S);
boolean setIsFull(set S);
int setCardinality(set S);
int setUnion(set S1,S2);
int setIntersection(set S1, S2);
int setDifference(set S1,S2);
set setStore(set S; int item);
int setDeleteItem(set S, int item);
set setCreate(set S);
set setJoin (set S, S1, S2, joinedSet);
set setMerge(set S1, S2, mergedSet);
set setPrintSet (set S);
int setDestroy(set S);
FILE* chomp_file(&filename, &mode, 256);
FILE* slurp_file(&filename, &mode, 4196);
returns runawayfound();
runner runawayreturn();
void motivational();
void` helpresources();
list return_list():
list setItem_to_Node();
void print_stats(void);
void print_histogram(returns R1, runners R2, histogram H){ }

What I want to do is to merge set ADT functionality into what appears to be in need of an array of records or a cicular linked list, and perhaps a graph of the found sites. Would appreciate any and all advice.


Thanks,

Diluculo, Nocte Ac Die
Post automatically merged:

There is the possibility of the data types being the issue, as variable values of the same type should be able to be passed through different structures, as long as the return type is the same data type as the variable value.
There is also the possibility the types are incompatible, in which case there would be different functionality controlled in main.
I do like my idea of implementing a merge sort in the setMerge function. That could be useful as a bridge between runaways and returns.

Thoughts?
 
Last edited:

SkullTraill

Glorious Light of Knowledge and Power
Staff member
Custodian
Librarian
Joined
Apr 12, 2021
Messages
1,866
Reaction score
15,586
Awards
19
Like... what is this? There is no main function, there are random keywords and function calls that are not defined in the code nor in the imports... there's literally no logic/programming in this code that anyone could even review/give you feedback for. And more than all of that, there are so many spelling errors everywhere that means this code could never compile, which means you never actually ran this code...

So what really is this? It honestly looks like you read the first chapter of a C Programming book, or read a few code examples on Stack Overflow, and just extrapolated how you imagine the language works and wrote down whatever you imagined to be "cool code".

This isn't code, this is a work of literature. I'm beginning to doubt that you have ever written any actual, real, functioning code in your life.

If you are actually interested in programming, ditch C/C++ and start with something easier like python, and focus on making small programs that actually work first... and then once you fully understand the language, you can do whatever it is you're actually trying to do here. Don't be a pretender.
 
Joined
Sep 9, 2021
Messages
9,697
Reaction score
5,256
Awards
33
I understand, This has a magical application, comparing the results of this imagined result into a working real program that is seen through the world by runaways who can find a safe route to return and call home.
I spared the horrid code, but here is it in full as of the moment. Ignore main, there has been no work on that aside from starting with a histogram program as the model.

The question is in the abstract data type themselves, and the ability or inability to pass data through them without throwing exceptions everywhere.


Here is randr.c in full (no possible way this will compile at the moment and is still under progress of coding):
I do have learning disabilities to a lesser degree in my age, but I was also burning the midnight oil when coding.

#include <stdio.h>
#include <stdlib.h>
#inlcude <math.h>
#include <ctype.h>
#include <string.h>
/* Pre-processor directives and includes */

/*
Purpose: This program reads two files, runaways and motivational/HelpNumbers.
The goal is to return the runaways to a SAFE environment.
Once a runaway is found, flags are updated to signal to update the returns file,
and unlink the runaway node and insert into the return list.
At that point the flags are read everything updated.
There is an interface engineers will have to create and implement.
*/

/* Abstract Data Type structure definitions */
/* Runner data and stats ADT using runners.dat file */
typedef struct Runner {
char* runner_name[40];
char* runner_age[3];
char* runner_gender[2];
char* runner_contact[20];
} runner;

/* Returns data and stats ADT using returns.dat file */
typedef struct Returns {
char* returns_name[40];
char* returns_age[3];
char* returns_gender[2];
char* returns_contact[20];
} returns;

/* Motivational messages ADT using motivation.txt file */
typedef struct Motivational
{
/* To comply with characters display size for LED text scroll devices */
char* Intro_String[40];
char* Core_Motivational_String[40];
char* List_Help_Num_String[40];
} motivational;

/* SAFE houses and mental health and DPS numbers ADT using SAFE.dat file */
typedef struct SAFENumbers {
char* SAFE_address[40];
char* SAFE_state[3];
char* SAFE_zipcode[6];
char* SAFE_contact[20];
} safenumbers;

/* FOR ENGINEERS TO IMPLEMENT -- interface for LED text scrolling devices */
typedef struct LED_Device_Interface { } LEDDevInterface;

typdef struct Histogram { } histogram;

typedef struct Statistics { } statistics;

typedef struct Set_ADT {
/*
Items are inserted and deleted, there is no inherent order in the
items in a given set. Merge_set, however does a merge-sort on the
items in the given set(s). Before any call is made to a set operation,
The set has been declared and a constructor has been applied.
The '==' and '<<' operators apply to values of ItemType.

} set_adt;
typedef struct set_adt set;

typedef struct List
{

}list_adt;
typedef struct list_adt list;

Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"
Runner runaway_list(list L);
list L, runaway_list, return_list, safe_list;
set S, S1, S2, MergedSet, joinedSet;
int numSetItems;

/* Function Prototypes */
Void setMakeEmpty(set S);
boolean setIsEmpty(set S);
boolean setIsFull(set S);
int setCardinality(set S);
int setUnion(set S1,S2);
int setIntersection(set S1, S2);
int setDifference(set S1,S2);
set setStore(set S; int item);
int setDeleteItem(set S, int item);
set setCreate(set S);
set setJoin (set S, S1, S2, joinedSet);
set setMerge(set S1, S2, mergedSet);
set setPrintSet (set S);
int setDestroy(set S);
FILE* chomp_file(&filename, &mode, 256);
FILE* slurp_file(&filename, &mode, 4196);
returns runawayfound();
runner runawayreturn();
void motivational();
void` helpresources();
list return_list():
list setItem_to_Node();
void print_stats(void);
void print_histogram(returns R1, runners R2, histogram H){ }

/* Function Implementation */
set setCreate(set S) {
/* Purpose: to create a new set of runners, returns, and other structures as */
/* well as flags to signal to the reader to be updated in terms of statistics, */

}

Boolean setIsEmpty(S) { (S.numSetItems==0)?return TRUE:return FALSE; }

Boolean setIsFull(S) { (S.numSetItems==MAX_SET_ITEMS)?return TRUE:return FALSE; }

int setCardinality()
{

}

int setUnion(set S1,S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items || S2.items;
}
/*
S1=result;
return S1;
*/
return result;
}

int setIntersection(set S1, S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items && setB.items;
}
return result;

}

int setDifference(set S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items && setB.items;
}
return result;

}

set setStore(set S; int item)
{
do
{
/* merge sets by merge sort and return mergedSet */
setMerge(S1,S2,mergedSet);
/* save mergedSet */
S1=mergedSet;
/* reset S2 */
S2=NULL;
/* test if setIsEmpty and setIsFull */
()?:;
/* store item */

}
while(!setIsFull(S1))
return mergedSet;
}

int setDeleteItem(set S, int item)
{

}

set setJoin (set S, S1, S2, joinedSet)
{
/*
Purpose: to create a new set of runners, returns, and other
structures as well as flags to signal to the reader to be
updated in terms of statistics,
*/

}

set setMerge(set S1, S2, mergedSet)
{
/*
Purpose: to merge S1 and S2, which could contain data from
runners and returns, and returns a merged set in an ordered manner.
*/
/* mergedSet must be filled with a merge of sets S1 and S2 */
set TempArray[MAX_SET_ITEMS];
int index = leftFirst;
int saveFirst = leftFirst;
while ((leftFirst <= leftLast) && (rightFirst <= rightLast))
{
if (values[leftFirst] < values[rightFirst])
{
TempArray[index] = values[leftFirst];
leftFirst++;
}
else
{
TempArray[index] = values[rightFirst];
rightFirst++;
}
index++;
}
/* merge sort will be the preferred method. */

return mergedSet;
}

int mergeSort(int values[], int first, int last)
{
if (first < last)
{
int middle = (first+last)/2;
mergeSort(values, first, middle);
mergeSort(values, middle+1, last);
setMerge(values, first, middle+1, last);
}
}

set setPrintSet (set S) { ; }
{
/* Purpose: to print exact set pointed to. */

}

int setDestroy(set S)
{
/* Purpose: to destroy exact set pointed to, then deallocate memory and return */
/* the deallocated memory back to the heap to avoid memory leaks, free pointers */
/* to avoid dangling pointer/null pointer errors. */
}

FILE* chomp_file(&filename, &mode, 256);
{
/* Purpose: to split the current exact file pointed to that has read mode enabled, */
/* and returns the exact field values specified. */

}

FILE* slurp_file(&filename, &mode, 4196);
{
/* Purpose: to read the current exact file pointed to that has read mode enabled */
/* all at once. */

}

return runawayfound(runner);
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, then print motivational and help number */
/* message strings. runawayfound means that the structure node/element that */
/* the runaway node record fields now get inserted into a new return node. */
found = 1; /* found yet still lost */
returned = 0; /* found but not returned */
motivated = 1; /* found and motivated */
lost = 1; /* lost but found */
gotHelp = 1; /* runaway runner got help */
safe = 0; /* found but not returned or safe */
}

return runawayreturn(runner);
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayreturn means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
returned=1; /* not lost and safe */
found = 1; /* found and safe */
motivated = 1; /* motivated and got help */
GotHelp = 1; /* got help and motivated */
lost = 0; /* not lost and found */
safe = 1; /* found and safe */
}

def motivational();
{
/* Purpose: to signal to the reader to print a new motivational message and */
/* call helpresources() */be updated in terms of statistics, */
lost = 1;
motivated = 0;
Got help = 0;
Got help = 1;
Lost = 0;
print_stats();
helpresources();
}

def helpresources();
{
/* Purpose: to signal to the reader numbers that can be called toll free for */
/* help in being found, and reader to be updated in terms of statistics, */
motivated = 1;
GotHelp = 1;
motivational();
}

def return_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. returnlist means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
Return = Runner;
motivated =1;
GotHelp = 1;
found = 1;
safe = 1;
}

void print_stats()
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
while (n = 0)
{
read x
if (x = sentinel);then
n = n+1
y[n] = x
call_sort(y,n)
sum=0
for(i=0;i <= n;i++)
{
sum = sum+y
}
mean = sum/n
j = (n/2)
if (n/2-j = 0)
{
median = y[j]
else
median = (y[j]+y[j+1])/2
}
sum = 0
for (i=0;i<=n;i++)
{
sum = sum+(y-mean)^2
}
variance = sum/n-1
std_dev = sqrt(variance)
coeff_var = std_dev/mean
printf ("\nN:%f MEAN:%f MEDIAN%f\n",&n,&mean,&median)
printf ("\n%f %f",&x[j],&x[n])
printf ("\nVARIANCE:%f STD_DEV:%f COEFF_VAR:%f\n",&variance,&std_dev,&coeff_var)
}
}

runner runaway_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
# Set total Runaways R = 0
R=0
# Open file for read
*fp=fopen("RunFile.dat","r+")
# Loop R through file RunFile
fseek("RunFile",0,0)
while (*fp != NULL)
do
fread("RunFile",&i)
R=R+R
# Return Runaways=R
done
# Close RunFile
fclose("RunFile")
}

def return_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
# Set total Returns R = 0
R=0
# Open file for read
*fp=fopen("RetFile.dat","r+")
# Loop R through file RetFile
fseek("RetFile",0,0)
while (*fp != NULL)
do
fread("RetFile",&i)
R=R+R
# Return Returns=R
done
# Close RetFile
fclose(RetFile)
}

main()
{
def return_list():
def lagrange(y,j,n){ lagrange(returns,runners,n) }
def helpresources(){ }
def runawayfound(){ }
def runawayreturn(){ }
def print_histogram(returns R1, runners R2, histogram H){ }
def motivational(){Runners="RunawayData.txt"
Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"


printf("\n\nRunaways and Returns starting..");
printf("Slurping File ..");
slurp_file();
int n=0;
*fp =fopen(&Runners,"r+");
for (a=0;a!=NULL;a++)
{
fread $x;
x==sentinel?continue:break;
{
$n=$n+1;
y[$n]=$x;
}
}
fclose(&Runners);
sum=0;
i=0;
while($i<$n)
{
$i=$i+1;
$sum=$sum+$y[$i];
}
mean=$sum/$n;
j=$n/2;
if((n/2) == 0i)
then{
$median=$y;
else
$median=($y[j]+($y[j]+1));
}
$sum=0;
$i=0;
while ($i<$n)
{
$i=$i+1;
$sum=$sum+($y[$i]-$mean)/2;
variance=$sum/$n-1;
stddev=sqrrt($variance);
coeffvar=$stddev/$mean;
printf("\n%f %f $f",$n,$mean,$median);
x=pow($x,3);
printf("\n%f %f", $x[$i], $x[$n]);
printf("\n%f %f %f",$variance, $stddev, $coeffvar);
}
}

printf("Statistics run DayAndTime..");
print_stats();
print_histogram();
printf("\n\nPrinting motivaionalMessageString");
motivational();
prinf("\n\nProviding HelpNumbers...)";
help_numbers();
return 0;
}

And, yes, I failed out of Eastern Michigan University by stiupidly switching from an Anthropology Major-Computer Science Major to a Computer Science Major-Anthropology Minor, to go for the big money. I still found the money, but not through coding.

Post automatically merged:

The question is, can I pass set data into the runners or returns ADTs.
Post automatically merged:

The magical reason is the 200% effort without spirits help. This would correspond to February where I wrote this horrid mess of nonfunctional code, to emulate what Agares could do as only one power - return runaways. This is a technical application of that.
Post automatically merged:

And, a C++ Bootcamp program is on my current radar given that I stay in town for the next year, rather than packing and moving west somewhere.
Post automatically merged:

One problem lies in that the C language does not provide a library f functions for sets, which is fine, Ive coded them ages back in Pascal, so confident I could do the same in C. On the other hand, both C++ and Python have a library for set functions, and data types are easier to code given OOP.
Post automatically merged:

I can provide two more files within a day, one in C++ and one ion Python. Most likely they too will be nonfunctional;, but easier to implement. I just know that C is commonly used for hardware interfacing.
Post automatically merged:

Back in February, when I realized this project and started it, I was downtown that day and saw a missing poster for a local fourteen year old. I started on this immediately. The next day the girl was found dead in the UofM athletic field. No signs of foul play they said. So, consider this also a project of philanthropy. And honor for the dead who I was too late for in playing my part to help.


If anyone else wants to pick this up and run with it, you have my blessing. I would still like to know the coding answer however.
Post automatically merged:

I promise to continue to work on this, in the principle of finishing whats been started, and solving the problem.
After consideration, I considered near every variable type to be char type, for easier passing/ADT implementation.
 
Last edited:
Top