[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
>Assignment for my C/C++ class due Friday...
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /adv/ - Advice

Thread replies: 33
Thread images: 1
File: readImage.jpg (13 KB, 323x301) Image search: [iqdb] [SauceNao] [Google]
readImage.jpg
13 KB, 323x301
>Assignment for my C/C++ class due Friday next week
>In danger of not getting it finished in time because despite working crazy hard on it I keep getting stuck on shit

I've never felt more discouraged and stressed about an assignment in my life. I honestly feel like I'm not picking any of the content up like I should be. Worst of all, next week is our "break" week so getting ahold of my teacher is much much harder.

What do /adv/
>>
>>16825502
whats the assignment about?
>>
>>16825502
Git gud. It's that simple
>>
>>16825510
We have to read in an array from the user sort it and then find a bunch of statistics about the contents (min, max, mean, median, mode, absolute deviation, variance, standard deviation and frequency distribution)
>>
>>16825525
Is this a joke?
If you're seriously that stupid just post on stackoverflow.
>>
>>16825525
data type of the array?
required algorithm?
>>
>>16825534
Thnx m8
>>
>>16825525
I take it you can't use any already written sorters? When in doubt: brute force. Good luck anon. This is actually a stack overflow question though lol
>>
>>16825544
Depends on what the teacher asks for. Probably they are asking him to use a specific algorithm.
>>
>>16825541
I forgot to ask. Do you have to implement your own data structures and sorting algorithm?
>>
>>16825544
I'm up to finding the modes of the array right now, I've been stuck on it for a few days, I've felt absolutely retarded.

Also, I should specify I'm using c for this assignment, not c++
>>
>>16825551
I was thinking more of using a Treemap which naturally sorts it's keys as things are added to it. It's kinda cheating since you don't actually write any sorting code whatsoever and depend on the languages version of natural sorting.
>>
>>16825576
Yeah, we can't use the library functions for them. This is my second college term btw, and my first term using c so that's why it seems so simple
>>
>>16825580
Oh... Well disregard my class sorting suggestion then.
>>
>>16825580
>When the for loops too loud
>>
>>16825581
I think OP is taking data structures since he is using C++/C and the implementation of your own algorithms is kinda mandatory. Probably quicksort, shell or bubble sort...?
>>16825586
Post code so we can help and see what's wrong, I myself am taking that class and I have a stack and heap assignment for tomorrow (kek i havent code anything).
>>
>>16825602
Should I just post it on here or is there some sort of website/service I can use that'll make it look all pretty and readable that I can just link here
>>
>>16825613
use the code tags.
[code]like this[/code]
>>
>>16825613
>>16825623
lol forgot this aint g. just post it or screen cap it.
>>
>>16825626
use pastebin newfags
>>
>>16825623
Alright, just a warning there's a chances I couldn't even be close to being headed in the right direction and should just scrap it and start over (although I don't think that's the case)

[code]
void findMode(double * a, unsigned int size)
{
double number = a[0]; //Used to to compare values in the array to see if they're similar
int count = 1; //Keeps track of number of occurences for each number
int max = 1; //Keeps track of max number of occurences found for each number
int uniqueNum = 1; //Keeps track of how many unique values in the array
int maxCount = 1; //Counts how many set's of numbers occur the max ammount of times
int elementNum = 0; //Keeps track of element number in mode array

for (unsigned i = 1; i < size; ++i)//loop to determine how many modes and unique numbers there are
{
if (number == a[i])
{
++count; //if the numbers the two numbers compared are the same, count is increased by 1
}
else
{
if (count == max)
{
++maxCount; //Keeps track of how many modes are in the array
}
if (count > max)
{
//If the two numbers compared are not the same and the count of the previous "set" of similar numbers is higher than the current max count, max is equal to the new count
max = count;
maxCount = 1; //Reset the max count if a new max is found
}
//Count is set back to 1 as we are counting a different number
count = 1;
number = a[i];
++uniqueNum; //Unique number variable gets incremented
}
}
[/code]

cont.
>>
>>16825623
whelp, it's a little too late not to use [code] now

here's the rest of it

count = 1; //sets count back to 1 for next loop

if ((double)size / max != uniqueNum)
{
double mode[sizeof((double)maxCount)]; //makes the mode array the right size to store all the modes
for (unsigned i = 1; i < size; ++i)//loop to determine what the modes are
{
if (number == a[i])
{
++count; //if the numbers the two numbers compared are the same, count is increased by 1
}
else
{
if (count == max)
{
mode[elementNum] = a[i];
++elementNum;
}
//Count is set back to 1 as we are counting a different number
count = 1;
}
}
printf("\nMode: {");
for (int i = 0; i <= (sizeof(mode) / sizeof(mode[0])); ++i)
{
printf(" %.3lf ", &mode[i]);
}
printf("}");
}
else
{
printf("\nNo mode");
}
}

Now the "no mode" part works perfectly fine, just when it does find a mode it prints a bunch of 0.000's
>>
http://pastebin.com/9Rvan8fi

pastebin link to make life a little easier for you
>>
>>16825647
>>16825650
I recommend that you take your project in the following way:
1.- get input and fill array to desired size (not ordered)
2.- Apply the sorting algorithm of your choice
3.- write the statistics functions and apply them

From what I see you are trying to sort and calculate mode at the same time, separate in previous steps ,I recommend you read about bubble sort which is a simple sorting algorithm and you can use an arraylist data structure model.

This links explains buble sort:
http://mathbits.com/MathBits/CompSci/Arrays/Bubble.htm

It shouldn't take more than to days to have everything ready.
>>
>>16825739
No I'm not trying to sort them in the findMode function. Basically the first for loop is used to determine if there are modes in the array and the second loop is used find what the mode is if there is one
>>
>Got banned from asking questions on stack overflow because I'm apparently a fucking idiot and this assignment has had me running for help that often
>Prof isn't responding to the e-mail I sent her about the problem
>I have like 2 friends in my program both of them are worse than me at this.

Guess I have re-taking this course to look forward too
>>
>>16825878
so you got point 1 and 2 covered?
>>
>>16825914
Yeah, that's all covered in the main method of my program, nothing in my findMode function was trying to sort the array? Jesus did I fuck it up that badly?
>>
Well sitting around bitching about it like you are isn't going to solve anything

But you know what will? Sitting down in front of your computer and coding
>>
>>16825998
I'm too goddamn busy freaking out and panicking to think
>>
>>16825917
No, i thought that was the only code you had and I was confused because that didnt covered points 1 and 2.

For mode I found some code snippets here:
http://stackoverflow.com/questions/19920542/c-calculating-the-mode-of-a-sorted-array

An idea I have for mode off my top of my head would be. If you have a sorted array say:

L =1,2,2,3,3,3,4,4,4,4

and variables:

last = 0,0
occurrence = 1

You do a for loop that loops through the entire array L. If L[i] equals L[i+1] you increase occurrence by 1, if not then you compare the current occurrence with last[1] (the last occurrance) if it's greater then you save the new number in last[1] and the new occurrence in last[1] and lastly yo set occurrence to 1 since a new number has been found.

I'll try it in a minute and post the code once it works.
>>
>>16826141
ok made a quick code snippet ad it seems to work well, here it is:

int last[2] = {0,0};
int occurrence = 1;
int L[10] = {1,2,2,3,3,3,4,4,4,4};

for(int i = 0; i < 10; i++){
if(L[i] == L[i+1])
occurrence++;
else{
if(occurrence > last[1]){
last[0] = L[i];
last[1] = occurrence;
}
occurrence = 1;
}
}
cout << "mode: " << last[0] << " occurrence: " << last[1];

It only works with sorted lists though. Some improvements would be to stop the algorithm once the occurence is greater than the remaining items to save some cycles and if there are two numbers with the same occurrence to save the biggest. You can easely encapsulate this little algorithm as a function.

I've never had to find the mode of a list so this was fun.
>>
>>16826042
>>16826141
>>16826182
sorry forgot identation shit, here is the code prettier:
http://pastebin.com/JPpwaw7X
Thread replies: 33
Thread images: 1
Thread DB ID: 528156



[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.