d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Assignment With Arrays, Using C > Pictures Included
Add Reply New Topic New Poll
Member
Posts: 16,154
Joined: Nov 14 2009
Gold: 19.00
Mar 21 2016 05:06pm
I am in a basic, starting programming class using C and we just learned about using arrays and what they are used for

My professor then threw us into this assignment which I can't really wrap my mind around too much.

I am using notepad++ to edit code and Cygwin to run the code also.

The first image is the "task" that i need to complete. The second is the starting code for the actual program, and the third is a little cheat sheet for certain variables and functions.

Ultimately I am looking for someone that can point me in the right direction of how I should approach this possibly give me some pointers.

Any help is greatly appreciated, and if anyone can help me out quite a bit, I may even toss some fg out to those who can. Thanks in advance.







This post was edited by Betrayal on Mar 21 2016 05:16pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 21 2016 06:43pm
What specifically do you need help on?

It's easy enough to write this for you, but if you're asking for help, then at least post the parts you are stuck on.

Also why does every class which teaches C always end up with exploitable code in their projects.
Member
Posts: 16,154
Joined: Nov 14 2009
Gold: 19.00
Mar 21 2016 06:46pm
Quote (AbDuCt @ Mar 21 2016 08:43pm)
What specifically do you need help on?

It's easy enough to write this for you, but if you're asking for help, then at least post the parts you are stuck on.

Also why does every class which teaches C always end up with exploitable code in their projects.


Ultimately, I need help understanding which functions (from the third picture) belong where, and how they are supposed to interact with the base code

I am not asking for you to write the entire program, but but at least point me in that direction
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 21 2016 07:19pm
I would start by reading the comments in the file. They are pretty self explanatory and tells you exactly what to do.

First step is the histogram array. As per the instructions you should know exactly how many elements this array should hold and of what type. Initialization of the array can be done many ways depending on the platform. If you google "Initialize C array to zero" you can find many examples. In your case it wants you to use the predefined function in utils.cpp.

After that would be to load the data from the user inputted file into the statsArray which was already provided. As per the comments you use the loadArray function in the Utils.cpp file.

Then after that the code simply requires iterating (looping) through the array to calculate the sum, the mean, the deviation, the median, and finally fill the histogram array. As the last step which doesn't seem to be calculated you will need a nested loop in order to print the histogram and the asterisks that show a bar graph.

If you have steam or some other instant messaging platform it is much easier to help someone live than trying detail a problem to them over a static post.
Member
Posts: 12,786
Joined: May 17 2013
Gold: 4,010.00
Mar 22 2016 12:31pm
That utils.cpp function initializeArray is retarded.

Declare an array of integers the same way as the char array in 3rd picture on line 25 and adding = { 0 }, and every cell is initialized to zero.

This reeks of roundabout ways to do simple stuff.

This post was edited by Klexmoo on Mar 22 2016 12:43pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 22 2016 04:19pm
Watch out guys, we have a pro coder here.
Member
Posts: 1,178
Joined: Oct 28 2009
Gold: 1,389.00
Mar 23 2016 03:44am
Quote (Klexmoo @ 22 Mar 2016 22:31)
That utils.cpp function initializeArray is retarded.

Declare an array of integers the same way as the char array in 3rd picture on line 25 and adding = { 0 }, and every cell is initialized to zero.

This reeks of roundabout ways to do simple stuff.


why do people use malloc and then invent ways to zero it, when they have calloc?
also why do you cast malloc's result to (int*)? this isn't cpp

This post was edited by deadNightTiger on Mar 23 2016 03:46am
Member
Posts: 12,786
Joined: May 17 2013
Gold: 4,010.00
Mar 23 2016 01:31pm
Quote (deadNightTiger @ 23 Mar 2016 10:44)
why do people use malloc and then invent ways to zero it, when they have calloc?
also why do you cast malloc's result to (int*)? this isn't cpp


What you're saying makes no sense.

I pointed out a shitty piece of code that is redundant, since the language's own constructs support a simpler implementation of that same functionality.

Calloc vs. Malloc doesn't even compare, they each have their individual use cases and calloc was made so you don't have to zero your memory allocation by yourself after using malloc.

That's not even saying that calloc and malloc are overly complicated to use compared to what I suggested, which is relevant to someone who is new to C.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll