14 Replies - 819 Views - Last Post: 10 November 2018 - 02:13 AM Rate Topic: -----

#1 brownmonkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-October 18

What does this mean?

Posted 05 November 2018 - 06:12 PM

So, I just got another programming project. I want to try to do it, but I don't get what exactly the question wants to me to create. Can you guys help me to make it clear?

Here is the question in direct pdf:
Attached File  hw5.pdf (255.17K)
Number of downloads: 34

If you don't feel like downloading it, you can go here. Go to Homework Detail -> Homework5

Is This A Good Question/Topic? 0
  • +

Replies To: What does this mean?

#2 MentalFloss   User is offline

  • .
  • member icon

Reputation: 595
  • View blog
  • Posts: 1,551
  • Joined: 02-September 09

Re: What does this mean?

Posted 05 November 2018 - 07:45 PM

I'm sorry, but I can only give you advice on how to approach this.

  • Read that project description over and over.
  • Write out on paper a sample run of how it should behave (as much as you can) to get an idea of what it would be in code.
  • Ask your instructor about things you are unclear on.
  • After you get your answers, go back to reading that project description over and over.
  • Study the input file, and try to understand what is being processed.
  • Write some pseudo code to give a description of the algorithm.
  • Figure out generally how your functions are to be interacting.
  • DON'T try to tackle it all at once. Logically build it up slowly, and deliberately - ensuring each piece works.

This post has been edited by MentalFloss: 05 November 2018 - 07:46 PM

Was This Post Helpful? 3
  • +
  • -

#3 jimblumberg   User is offline

  • member icon

Reputation: 5594
  • View blog
  • Posts: 17,261
  • Joined: 25-December 09

Re: What does this mean?

Posted 05 November 2018 - 08:59 PM

Break the program down to discrete steps. For example do you know how to get the program to accept command line arguments?

Jim
Was This Post Helpful? 1
  • +
  • -

#4 brownmonkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-October 18

Re: What does this mean?

Posted 06 November 2018 - 04:33 AM

View PostMentalFloss, on 05 November 2018 - 07:45 PM, said:

I'm sorry, but I can only give you advice on how to approach this.

  • Read that project description over and over.
  • Write out on paper a sample run of how it should behave (as much as you can) to get an idea of what it would be in code.
  • Ask your instructor about things you are unclear on.
  • After you get your answers, go back to reading that project description over and over.
  • Study the input file, and try to understand what is being processed.
  • Write some pseudo code to give a description of the algorithm.
  • Figure out generally how your functions are to be interacting.
  • DON'T try to tackle it all at once. Logically build it up slowly, and deliberately - ensuring each piece works.

So I have asked the prof about this, and I think I get it now, well, at least half of it.
I suppose I was tasked to create a limited random number and make it print out in a "bucket" where the size of the "bucket" is also pretty much random. Am I right?
So, I have given it some thought. I thought to tackle the problem with multi-dimensional array to deal with the "bucket" and use "%" to set limits for rand(). What do you think? Am I at least in the right direction?
Was This Post Helpful? 0
  • +
  • -

#5 Thomas1965   User is offline

  • D.I.C Regular

Reputation: 108
  • View blog
  • Posts: 408
  • Joined: 09-September 16

Re: What does this mean?

Posted 06 November 2018 - 04:50 AM

The size of the bucket is given to you so it can't be random.
Each integer inside the bucket must be in a certain range so yes you could use rand for this.
Don't forget to set the seed for srand with the given number.
Was This Post Helpful? 1
  • +
  • -

#6 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What does this mean?

Posted 06 November 2018 - 05:53 AM

So you have basically 4 questions to cover,

why not break them down into 4 programs each program should cover 1 question, then when you have all that join them together to form one single program.

Yes, you should be using a two-dimensional array, the limits of which are set by n and m.

rand is a well-documented C function a trip to Google searching for 'rand in c documentation' will give you plenty of examples on how to use that function.

while you are in the Land of Google also research 'two-dimensional arrays in C'.
Was This Post Helpful? 1
  • +
  • -

#7 brownmonkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-October 18

Re: What does this mean?

Posted 06 November 2018 - 09:46 AM

Since I am going to use arrays, it's probably better that I make arrays to be very clear first. So because I am going to make the number of integers inside the bucket to be random, then there is possibility that I might not fill all the array. Is that alright? Or should I change the way I think?

This post has been edited by Skydiver: 06 November 2018 - 03:56 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#8 Thomas1965   User is offline

  • D.I.C Regular

Reputation: 108
  • View blog
  • Posts: 408
  • Joined: 09-September 16

Re: What does this mean?

Posted 06 November 2018 - 11:29 AM

Regarding the array you have two choices. You can create them dynamically with malloc or declare them static setting rows and columns to max i.e. 100, which is definitelt less hassle.

This exercise isn't easy. Are you sure you don't jump ahead of yourself?
Was This Post Helpful? 0
  • +
  • -

#9 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What does this mean?

Posted 06 November 2018 - 01:45 PM

Have you read the assignment?

At the bottom of hw5.pdf it tells you in some cases new buckets might not be full, and why not start with question 1 as that is important but not as hard as question 2 and since question 2 relies on some aspects of question 1 it seems logical you should start with question 1.

You are also going to have to deal with dynamically creating arrays at some point and the sizeof keyword to create the 'new mapping array'.
Was This Post Helpful? 0
  • +
  • -

#10 brownmonkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-October 18

Re: What does this mean?

Posted 07 November 2018 - 01:21 AM

Okay, I think I have covered question 1 and 2. Here is what I come up with:
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char*argv[])
{
    int n,m,d,s;
    n = atoi(argv[1]);  //bucket
    m = atoi(argv[2]);  //max num in bucket
    d = atoi(argv[3]);  //range
    s = atoi(argv[4]);  //seed
    srand(s);

    int arr[n][m],i,j,x;
    for(i = 0; i < n; i++)
    {
        printf("%d / ", i);
        m = (rand()%m+1);
        for(j = 0; j < m; j++)
        {
            arr[i][j] = x;
            x = (rand()%d);
            printf("%d ", x);
        }
        printf("\n");
    }
    return 0;
}


It printed out fine, but I saw a pattern that the "seemingly random integer" only makes 1 array every time it approaches the end of array. I don't know if I make any sense. I'll just copy the output. Is this correct?

Quote

0 / 4 2 5 1 3 3 2 1
1 / 2 5 6 4 6 0
2 / 1
3 / 2
4 / 0 //makes only 1 array
5 / 2
6 / 5
7 / 6

Was This Post Helpful? 0
  • +
  • -

#11 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2241
  • View blog
  • Posts: 4,327
  • Joined: 30-May 10

Re: What does this mean?

Posted 07 November 2018 - 03:29 AM

> 17 m = (rand()%m+1);
You trash your value of 'm' every time you do this.

By doing this, m will tend towards 1 over time.

Follow the guide in your assignment PDF, and pick meaningful variable names for everything.
Except perhaps for the apparently mandated int n,m,d,s;

> 20 arr[i][j] = x;
> 21 x = (rand()%d);
You assign the array some garbage value (the first time around), and then compute a random entry.
Was This Post Helpful? 1
  • +
  • -

#12 brownmonkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-October 18

Re: What does this mean?

Posted 09 November 2018 - 04:21 AM

Okay, I've fixed the bug. I guess I am done with question 2. Moving on to question 3.
How should I view the question? Do I need to look into union function or is it possible to finish with a simple for-loop?
Can't figure out how though if it can be solved just by for-loop
Was This Post Helpful? 0
  • +
  • -

#13 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What does this mean?

Posted 09 November 2018 - 06:19 AM

Read the questions 3 & 4 as 4 tells you your function definitions for question 3.

In addition to main() you are to use at least three functions.

int bucket_union() (returns an index so seems fair enough)

int new_mapping() (to return an array so the return type doesn't seem adequate)

and

void fprint_result() (where you print the buckets)

again break it down do one function at a time and do not get distracted by thinking of the other functions before you finish the first.
Was This Post Helpful? 1
  • +
  • -

#14 jimblumberg   User is offline

  • member icon

Reputation: 5594
  • View blog
  • Posts: 17,261
  • Joined: 25-December 09

Re: What does this mean?

Posted 09 November 2018 - 08:37 AM

You should also be validating the command line values before you try to use them. There should be 4 parameters each of which should be 1 to 100. Because all of the numbers must be within that range you can make your arrays with the size of 100. By the way none of those numbers should change within the course of the program so when you convert the strings to numbers the numbers can be const qualified to prevent their changing const int m = atoi(argv[3]); in inadvertently.

Trying to use runtime sizes for your arrays is probably not what your assignment expects. You should either be using arrays sized to be large enough to hold any allowable sized array (100) or dynamically allocate the the arrays with the sizes provided.


Jim
Was This Post Helpful? 1
  • +
  • -

#15 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: What does this mean?

Posted 10 November 2018 - 02:13 AM

Yes Jim, Exactly, personally I think the OP has to dynamically allocate the arrays.


And also free() them at the end of course.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1