Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Exclamation Dr. Scheme Homework

    I missed the last two days of my programming class and I have homework due tomorrow and I am completely lost. I need some help.

    Write functions to implement the following.
    a. f(n)= 3n+1
    b. g(n,m)= 2n+m
    c. H(L)= (two times the length of L) - (the first element in L)
    d. ff(L,n)= the smaller of the first element of L and n

    3. Write a recursive function that takes a list of integers as an argument and returns how many of them were greater than 100.

    4. Write a recursive function that takes two arguments: e and L (where L is a list of numbers). This function should return #t if e is in L and should return #f otherwise



    Help me please. I have no idea and I have to turn this in

  • #2
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    Have you done anything for the homework yet? No one here will do your homework for you, but most will be glad to point you in the right direction. You could start by offering a little more detail about what you are doing, what OS, what language, what your level of programming experience is, and post anything that you have done already.

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Dr. Scheme is the program. We are using the language Essentials of Programming Languages (3rd ed.) I am using Windows XP professional 2002, service pack 3. This is my FIRST programming class. I'm a freshman in college. I have no prior experience with it. I had to miss 2 days of class due to an emergency surgery.

    I started out the HW assignment by giving the results of functions such as car, cdr, null, length, and list. I have no problem with giving the results of functions, but I am totally clueless when it comes to actually writing them.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well start with problems a-d, each one of those would be one function. So for the first one, the function would be called f and take one parameter called n and perform the operation after the equal sign and return the result.
    OracleGuy

  • Users who have thanked oracleguy for this post:

    CatiePaige0821 (09-08-2009)

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    How do I write out the operation? I can't just put 3n + 1, correct?

  • #6
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    I'm not personally familiar with scheme, but a quick google search turned up this, looks very lisp like, I would study up on the syntax a bit: http://pages.cs.wisc.edu/~fischer/cs538.s08/drscheme.intro.html
    Last edited by brad211987; 09-08-2009 at 10:18 PM.

  • Users who have thanked brad211987 for this post:

    CatiePaige0821 (09-08-2009)

  • #7
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Honestly, you should be emailing your professor about your special case. You should also read through your text to see example functions.

    Do you know what a variable is? If not, read your text. Do you know how to store a result into a variable? If not, read your text.

    I'll give you a sample function (written in pseudocode, scheme, and Java):
    Code:
    // This function converts cups to ounces
    // Example: cupsToOunces(2) returns 16
    function cupsToOunces(integer cups)
        // There are 8 ounces to a cup
        integer ounces = cups * 8
    
        // Return ounces
        return ounces;
    end function
    
    ; This function converts cups to ounces
    ; Example: cupsToOunces 2 returns 16
    (define (cupsToOunces cups) (* cups 8))
    
    // This function converts cups to ounces
    // Example: cupsToOunces(2) returns 16
    public static int cupsToOunces(int cups)
    {
        // There are 8 ounces to a cup
        int ounces = cups * 8;
    
        // Return ounces
        return ounces;
    }
    The above example is not one of your a-d problems, but it should give you an idea.

    You should write some pseudocode first and then go from there.

    -Shane
    Last edited by TheShaner; 09-08-2009 at 10:38 PM.

  • Users who have thanked TheShaner for this post:

    CatiePaige0821 (09-08-2009)

  • #8
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    There is no text for the class. It is actually a JAVA programming class, but we have started out with scheme. So I don't have anything to refer to. The only thing I have are the notes from the first 4 days of class and they only covered what was on the first part of the HW which I completed. I have no idea how to do the other half b/c I wasn't in class.

    Brad- Scheme is like relative of lisp. They are a lot alike and share some similarities, but have a lot of differences. Thank you for the article.

  • #9
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You should also try and get notes from someone else in class or as Shane suggested email the professor, they can probably send you the slides from the days you missed if they aren't on their website. Or find out when your professor has office hours and go talk to them in person and hopefully they will help answer your questions in addition to the help we can provide.

    I would hope the professor's slides from the days you missed would have examples that can help you solve those problems. But it sounds like you need to read up on functions more and how they work. You might be able to find some scheme tutorials on the internet. If not, any programming tutorial that describes functions will work since the concept is the same on any language, its just the syntax (how you write it) that depends on the language.
    OracleGuy

  • Users who have thanked oracleguy for this post:

    CatiePaige0821 (09-08-2009)

  • #10
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I emailed the instructor. He hasn't gotten back to me, which isn't a surprise to me. I do not live on campus, I am a commuter and I only have class MWF, so getting the notes right now isn't all that easy. I will get the notes tomorrow from someone in class.

    Is there anybody that is willing to lend me a hand. I've been reading about this all afternoon. I have a basic understanding of what I need to do, I'm just not sure how to put it together.

  • #11
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have figured out 3 of the problems. I just have 3 left. I've been trying things left and right. I'm still confused on these 3...

    ff(L,n)= the smaller of the first element of L and n

    Write a recursive function that takes a list of integers as an argument and returns how many of them were greater than 100.

    Write a recursive function that takes two arguments: e and L (where L is a list of numbers). This function should return #t if e is in L and should return #f otherwise.

  • #12
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    L stands for list? I'm just going to assume that they mean an array of whatever type you need. So you are passing an array to the function and another value. If you're programming in C/C++ then a pointer will do for the array.
    To get the result you need, all you need to do is check if the first element of this array is smaller or greater than the other parameter passed to the function.

    The second one you'll need to go throw each element of the list and see if it is bigger than 100, each time, you could for example increment a variable serving as a counter and return this.

    That last one I'm assuming you have to check if there is an element in L that has the same value as e? Again, iterate through the list and break to return true if you find a match, otherwise return false.
    Last edited by BrickInTheWall; 09-09-2009 at 07:39 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •