View Full Version : Dr. Scheme Homework

CatiePaige0821

09-08-2009, 08:54 PM

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

:confused:

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

brad211987

09-08-2009, 08:56 PM

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.

CatiePaige0821

09-08-2009, 09:04 PM

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.

oracleguy

09-08-2009, 09:06 PM

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.

CatiePaige0821

09-08-2009, 09:11 PM

How do I write out the operation? I can't just put 3n + 1, correct?

brad211987

09-08-2009, 09:16 PM

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

(http://pages.cs.wisc.edu/%7Efischer/cs538.s08/drscheme.intro.html)

TheShaner

09-08-2009, 09:29 PM

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):

// 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

CatiePaige0821

09-08-2009, 09:34 PM

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.

oracleguy

09-08-2009, 10:09 PM

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.

CatiePaige0821

09-09-2009, 01:04 AM

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.

CatiePaige0821

09-09-2009, 01:54 AM

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.

BrickInTheWall

09-09-2009, 06:24 AM

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.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.