Page 4 of 4 FirstFirst ... 2 3 4
Results 61 to 78 of 78
  1. #61
    Banned.

    Join Date
    Aug 2007
    Posts
    2,547
    BG Level
    7

    I'd just like to go on record as saying your professor is an asshole for teaching you recursion before you even learn the basics of the language.

  2. #62
    Banned.

    Join Date
    Oct 2006
    Posts
    10,115
    BG Level
    9

    Right-o thanks

  3. #63
    Sea Torques
    Join Date
    Oct 2006
    Posts
    566
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Tajin View Post
    Instructions
    As I (may have) mentioned earlier, this is one of the problems I had with the assistance that the teacher was giving. I can see why someone might say this (they didn't each method overloading yet), but it really feels like a poor job being done by the teacher. (S)He has not done a very good job introducing basic programming concepts, which has made a fairly trivial problem difficult to understand. Recursion itself is not a difficult concept (a function that calls itself), but without an understanding of the stack, return types, and the steps in which the application executes, I'm not sure the students are gaining the information that they need to in order to prepare themselves for future tasks.

    Tajin: You probably shouldn't have copy-pasted that code. It has several syntax errors (recursive not always returning a value), incorrect prime logic (as was said a few posts back, one is not a prime), and your removal of the isPrime function makes it so a function that doesn't exist is being called.

  4. #64
    Banned.

    Join Date
    Oct 2006
    Posts
    10,115
    BG Level
    9

    You are correct good sir, fixing the mess.

    Edit: Done, it is still a mess but eh, you posted the answer anyway on page 1 <.<

  5. #65
    Old Lady Harem of the House of Weave
    Join Date
    Jun 2007
    Posts
    589
    BG Level
    5
    FFXIV Character
    Mne Jing
    FFXIV Server
    Gilgamesh
    FFXI Server
    Cerberus
    WoW Realm
    Hyjal

    I'm totally at a loss as to why you'd be instructed to learn recursion prior to learning a simple concept such as boolean anything. I mean, recursion is a pretty simple concept when you see it in action (properly), but seriously, case operations are so common that learning what boolean means and how to implement it should be something you learn early on... unless they don't touch on if-then-else stuff until later in the class, which I suspect is the case here.

  6. #66
    Very Sexy Nerd
    Join Date
    Oct 2005
    Posts
    8,731
    BG Level
    8
    FFXI Server
    Carbuncle

    Quote Originally Posted by Kaelan? View Post
    I can't tell how much it's him having trouble grasping the concepts (which is fine, recursion is one of the hardest things to understand out of all programming concepts you learn early on) and how much it's the teacher doing a shitty job teaching it, but to me it just looks like this wasn't was presented very well in the class.

    Introducing recursion before going through the basics of what native data-types are and how they work; as well as the relationships between function declarations, variables and valid operations on them is just rushing too much. It doesn't even seem like a proper explanation of the structure of your average recursive function was given.

    Spoiler: show
    i.e. always figuring out your terminating conditions first, the correct syntax to call a function within itself, how data gets passed down the recursive calls, then back up and out to the original calling function, etc.


    @OP: If you're serious about programming, I'd say right now you should take some time to make sure you understand why the things you were trying to do weren't working, and why doing it like other people suggested would work, regardless of what the scope of the assignment was. Have a C++ reference handy and mess about with the code for a while so you get a sense of why doing things like:

    Code:
    int function(int arg)
    {
       function = arg+1;
    }
    is a bad idea (and also doesn't do what you're trying to do), rather than just accepting that it's wrong. Understanding why all these things work or don't work is in the end a lot more useful than knowing how to solve any particular homework problem with them.

    @Taijin: In C++ ints always evaluate to false if 0 and true if anything else
    I agree with this <.< When I first saw the topic, I thought either: 1. the OP has no fucking clue what he's doing and is taking wrong class/wrong major, 2. the professor is shit, 3. OP isn't going to class/paying any attention in class.

    There's nothing wrong with teaching recursion early, but teaching it before the super basic stuff mentioned in the above post that the OP couldn't fully grasp is just, weird/wrong.

    And I don't get all the people bitching about booleans -_- Maybe it's because I didn't do C++, but regular C, which required doing retarded shit if you wanted to use the words true and false instead of 1/0, but it just seems silly. As long as you understand that 0=false and 1=true, I don't see the problem with either method. I mean, if the language supports booleans, using true/false is obviously better, but I still don't get all of the bitching. lol

    edit: 6666 <_>

  7. #67
    Sea Torques
    Join Date
    Oct 2006
    Posts
    566
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Toxictaru View Post
    I'm totally at a loss as to why you'd be instructed to learn recursion prior to learning a simple concept such as boolean anything. I mean, recursion is a pretty simple concept when you see it in action (properly), but seriously, case operations are so common that learning what boolean means and how to implement it should be something you learn early on... unless they don't touch on if-then-else stuff until later in the class, which I suspect is the case here.
    I would find it difficult to believe that the instructor didn't go over the if/then construct before giving this assignment.

    If I were teaching this class, the lesson plan would be something like:

    Primitive datatypes (char, int, long, short, byte, float, double, bool), specifically what these are (size in bits, signed and unsigned range, scenarios in which each should be used).
    Variable Declarations
    Control Structures (if/then/else, for, while, do while, switch, break, continue) with assignments taliored to using each structure.
    Methods (return types, naming conventions, and parameters)

    With these topics, an instructor has the ability to expand simple applications with new information. Recursion, for example, could be introduced after calculating prime numbers in a for loop. This would be a good way to not only how recursion changes the application structure, but also a way to introduce the stack, error cases, validating input, and operator overloading.

    Aristio: If you actually want to gain an understanding of programming, I would try to make sure you have a grasp on those topics. As I've said before, I don't know the scope of the class, but knowing datatypes and control structures will be important.

    Honestly, though, if the students are having trouble with recursion, I can't imagine what is going to happen when (s)he teaches them references/pointers/memory management.

  8. #68
    i'm awesome.
    Join Date
    May 2005
    Posts
    9,218
    BG Level
    8

    Recursion is tightly related to mathematics and it makes perfect sense if you're teaching programming from a mathematical point of view tightly related to functional programming.

    You don't need to know every primitive type in order to understand logic and functions. In fact I would argue it's an unimportant, trivial thing. He obviously understands the concept if he's using if statements appropriately.

  9. #69
    Anti-crusade crusader
    Join Date
    Oct 2008
    Posts
    1,438
    BG Level
    6
    FFXI Server
    Asura

    Quote Originally Posted by Tidane View Post
    I would find it difficult to believe that the instructor didn't go over the if/then construct before giving this assignment.

    If I were teaching this class, the lesson plan would be something like:

    Primitive datatypes (char, int, long, short, byte, float, double, bool), specifically what these are (size in bits, signed and unsigned range, scenarios in which each should be used).
    Variable Declarations
    Control Structures (if/then/else, for, while, do while, switch, break, continue) with assignments taliored to using each structure.
    Methods (return types, naming conventions, and parameters)

    With these topics, an instructor has the ability to expand simple applications with new information. Recursion, for example, could be introduced after calculating prime numbers in a for loop. This would be a good way to not only how recursion changes the application structure, but also a way to introduce the stack, error cases, validating input, and operator overloading.

    Aristio: If you actually want to gain an understanding of programming, I would try to make sure you have a grasp on those topics. As I've said before, I don't know the scope of the class, but knowing datatypes and control structures will be important.

    Honestly, though, if the students are having trouble with recursion, I can't imagine what is going to happen when (s)he teaches them references/pointers/memory management.
    I can tell you I've learned:
    • char
    • int
    • float
    • double
    • bool
    • if/else
    • for
    • while
    • do while
    • signed/unsigned


    I'm guessing variable declarations are "int x = 9" and naming conventions are what you went over on the first page. I'm working on a new assignment right now, and it has to deal with loops and bools. After everyone explaining it to me, the assignment is pretty simple. Stuck on one point, but I'm sure I'll figure it out.

  10. #70
    Unique and/or Creative Phrase
    Join Date
    Aug 2006
    Posts
    1,432
    BG Level
    6
    FFXI Server
    Shiva

    I didn't learn recursion until the end of my second java class.

  11. #71
    Anti-crusade crusader
    Join Date
    Oct 2008
    Posts
    1,438
    BG Level
    6
    FFXI Server
    Asura

    So, can anyone tell me what I'm doing wrong?
    Spoiler: show

    Code:
    #include <iostream>
    using namespace std;
    
    class StudentGrade {
    
                public:
                char getOverallLetterGrade(double mygrades)
                {
                    char gradeA = 'A';
                    char gradeB = 'B';
                    char gradeC = 'C';
                    char gradeD = 'D';
                    char gradeF = 'F';
                    if (mygrades >= 90)
                    {
                        return gradeA;
                    }
                    if (mygrades >= 80 && mygrades <90)
                    {
                        return gradeB;
                    }
                    if (mygrades >= 70 && mygrades <80)
                    {
                        return gradeC;
                    }
                    if (mygrades >= 60 && mygrades <70)
                    {
                        return gradeD;
                    }
                    if (mygrades > 60)
                    {
                        return gradeF;
                    }
                }
                double getOverallNumericGrade(int quiz, int midterm, int final)
                {
                    double mygrades;
                    mygrades = (quiz + midterm + final)/1.6;
                    return mygrades;
                }
            private:
                int quiz, midterm, final;
    };
    
    int main ()
    {
        StudentGrade grades;
        double mygrades;
        int quiz;
        int midterm;
        int final;
        cout << "Please enter the quiz score (0-10): \n";
        cin >> quiz;
        cout << "Please enter the midterm score (0-50): \n";
        cin >> midterm;
        cout << "Please enter the final score (0-100): \n";
        cin >> final;
        cout << "The student's overall grade is: " << grades.getOverallLetterGrade(mygrades) << " (" << grades.getOverallNumericGrade(quiz, midterm, final) << "%)" << endl;
        return 0;
    }


    Of course, homework help. I'm having trouble nesting the if statements properly in the class. Would I put the if statements before or after the return of each if statement?

  12. #72
    hey
    hey is offline
    listen!
    Join Date
    Apr 2011
    Posts
    7,234
    BG Level
    8
    FFXI Server
    Sylph

    Your problem is in main, not the ifs.

    Also, the "&& mygrades <x0"s aren't needed. If they weren't true, you wouldn't be checking the if in the first place.

  13. #73
    Anti-crusade crusader
    Join Date
    Oct 2008
    Posts
    1,438
    BG Level
    6
    FFXI Server
    Asura

    Everything in main works, when I compile and run the program, it always gives me F no matter the % grade. 160/1.6=100. Still says F though.

  14. #74
    hey
    hey is offline
    listen!
    Join Date
    Apr 2011
    Posts
    7,234
    BG Level
    8
    FFXI Server
    Sylph

    Quote Originally Posted by Aristio View Post
    Everything in main works, when I compile and run the program, it always gives me F no matter the % grade. 160/1.6=100. Still says F though.
    Nope. It doesn't. Try ignoring the input and hard coding a value for mygrades, and see what happens. This is an easy way of debugging simple problems like this. If hard coding a value makes it work, then you are feading the function the wrong value. If it doesn't, then the function is wrong.

  15. #75
    Anti-crusade crusader
    Join Date
    Oct 2008
    Posts
    1,438
    BG Level
    6
    FFXI Server
    Asura

    Quote Originally Posted by hey View Post
    Nope. It doesn't. Try ignoring the input and hard coding a value for mygrades, and see what happens. This is an easy way of debugging simple problems like this. If hard coding a value makes it work, then you are feading the function the wrong value. If it doesn't, then the function is wrong.
    Ignored the cin by putting // in front of each. Put each input manually as a C-grade values and it gave me an A. So the function is wrong. Am I getting the input from the user correctly?

  16. #76
    hey
    hey is offline
    listen!
    Join Date
    Apr 2011
    Posts
    7,234
    BG Level
    8
    FFXI Server
    Sylph

    No, you are sending garbage data in the mygrades variable. Either hard coding mygrades, or using a cout at the top of getOverallLetterGrade would have made that very obvious, even if you didn't know why.

    I'm going to bed now, see if you can figure it out from there.

  17. #77
    Banned.

    Join Date
    Oct 2006
    Posts
    10,115
    BG Level
    9

    You're not assigning the mygrades variable anywhere in your program, like hey said, you're sending garbage to the method.

  18. #78
    Relic Shield
    Join Date
    Jul 2008
    Posts
    1,951
    BG Level
    6
    FFXIV Character
    Audrey Weaver
    FFXIV Server
    Behemoth
    FFXI Server
    Asura

    Also, don't mix operations between ints and floats/doubles when there's division involved; cast everything appropriate type. I don't remember if all compilers handle 150/1.6 properly, but the opposite order (i.e. 3.6/2) will definitely give you a wrong answer thanks to implicit int conversions.

Page 4 of 4 FirstFirst ... 2 3 4

Similar Threads

  1. BG Homework Help (Grammar)
    By aduidarnenye in forum General Discussion
    Replies: 8
    Last Post: 2011-01-17, 06:36
  2. BG Cooks - Grilling Help Please. :(
    By Klutz in forum General Discussion
    Replies: 82
    Last Post: 2010-02-17, 17:25
  3. BG Legal Advice: HELP ME OUT!
    By Synbios in forum General Discussion
    Replies: 7
    Last Post: 2010-02-15, 04:00
  4. BG advice: Kitty help
    By Apelila in forum General Discussion
    Replies: 5
    Last Post: 2009-11-23, 11:52
  5. Paging Dr. BG, pregnancy scare??? help!!
    By Nitsuki in forum General Discussion
    Replies: 123
    Last Post: 2009-05-29, 17:13
  6. Replies: 29
    Last Post: 2008-06-06, 11:15
  7. BG Audiophiles... lil help?
    By Doombear in forum General Discussion
    Replies: 29
    Last Post: 2008-05-22, 11:28
  8. My homework HELP ME
    By Endo in forum General Discussion
    Replies: 48
    Last Post: 2005-10-09, 10:33