Thread: My Comp Sci 2 class....

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    My Comp Sci 2 class....

    Hi i took computer science one last year, visual basic, and during my summer break i had gotten into learning a little c++ in preperation for this year. I had the thought that Void Main () was a bad programming habit, but thats how she is teaching it, i had been useing int main (). Any opinions on this? If i don't do it her way she will ***** but i'd like to know so in my out of class time i do it the better way.

    -Steve-

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    find yourself a copy of the ANSII standard and give her a printout of that section. What's the worst she could do? think you're being rude? She could actually start teaching it correctly though.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Play along with her to get the pass mark, but stay happy in the knowledge that you are right and she is wrong....

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    worst she could do? Allow me to list some of the things she kicked me out for last year lol:

    -Correcting her spelling
    -Asking why weren't useing option explicit
    -Finding a more effiecent way to program (the $ signs and such)

    She also insisted i couldn't know things as she hadn't taught em, but i do plan on ariseing this question.

    Where might i get my hands on this table? And how will it help me?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Ride -or- Die
    worst she could do? Allow me to list some of the things she kicked me out for last year lol:

    -Correcting her spelling
    -Asking why weren't useing option explicit
    -Finding a more effiecent way to program (the $ signs and such)

    She also insisted i couldn't know things as she hadn't taught em, but i do plan on ariseing this question.

    Where might i get my hands on this table? And how will it help me?
    Not sure if you can get it electronically

    Send her here

    Its upsetting that VC++ allows void main.....I guess its due to all the legacy code out there (there's still loads of MSDN code with void main!)...but it should show a warning IMHO....

  6. #6
    Registered User Dr. Bebop's Avatar
    Join Date
    Sep 2002
    Posts
    96
    I would question her ability to teach if she uses something that was proven wrong a long time ago. Let her know about it in private and if she doesn't change her ways then you can rest assured that she's stupid.

    Bebop
    Processing error: Stupidity detected.
    ------------------------------
    Dr. Bebop
    Windows XP Professional Ed.
    Microsoft Visual Studio 6

  7. #7
    -Ride or Die-
    Guest

    Cool

    Good to know i was in the right for once. I think i'll just email her about it, its much easier then getting in a match where she can throw me out.

    I would like to find the table online, i will search it up on yahoo ina bit. Anyway heres her code then the code i improved, please let me know if my version is properly done(i know it works but i want the format to be good habiting.)

    Hers:

    #include <iostream.h>

    Void Main ()

    {

    cout<<"Hello World"<<endl;

    }


    Mine:

    #include <iostream.h>

    Int Main ()

    {

    cout<<"Hello World"<<endl;

    return 0;

    }

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    int main(void){
    
    	cout<<"Hello World"<<endl;
    
    	return 0;
    }
    Dont capitalise int main or void.....if that was the code she gave then it wont even compile

    Also, llok at using the std headers without the '.h'.......you then need to specify what you want from the std namepsace with the using instruction

  9. #9
    -Ride or Die-
    Guest
    So without the .h i need to use the std stuff...ok i follow that.

    I capitalized them without realizing it...oops lol.

  10. #10
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    not only didn't i realize i wasn't logged in i also spelled ma username wrong...lmao

    anyway not sure if these are right but they are two diff tables i discoverd. For the first the lang pack isn't needed to read the table if it asks.

    http://www.upload.co.il/tutorials/ascii/ascii.html
    http://www.chris-spittles.co.uk/htdo...sii/ansii.html

  11. #11
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Her reply:

    Steve,

    Notice with void there is no return in the last line of the code. Hence void is
    indicating that that is no value that will be returned.

    Using any data type in front of main, indicates the type that will be returned.
    Notice the return (0); or return 0; both are acceptable in the last line of your
    code. Basically a value of int is being returned by the return 0. Actually no
    value is being returned. The return 0 indicates to the compiler that the
    program ran successfully. Yes, I will be going over this in class. Different
    books will present void initially and a data type return indication later or
    just stay with the data type return indication. A lot of opinions on the merits
    of void by a lot of authors.

    Hope this helps.

  12. #12
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    The return 0 indicates to the compiler that the
    program ran successfully
    The value is not returned to the compiler, but to the calling system (the OS). And yes, there is certainly a value left in the eax register after the program exits! So it *does* return something. Of course, it's up to the programmer to return non-zero on exit...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Ride -or- Die
    Her reply:

    Steve,

    Notice with void there is no return in the last line of the code. Hence void is
    indicating that that is no value that will be returned.

    Using any data type in front of main, indicates the type that will be returned.
    Notice the return (0); or return 0; both are acceptable in the last line of your
    code. Basically a value of int is being returned by the return 0. Actually no
    value is being returned. The return 0 indicates to the compiler that the
    program ran successfully. Yes, I will be going over this in class. Different
    books will present void initially and a data type return indication later or
    just stay with the data type return indication. A lot of opinions on the merits
    of void by a lot of authors.

    Hope this helps.
    Authors opinions and practices are not relevant....they dont define these languages...they just teach.......To answer this question you use

    [list=1][*]The standards - the most recent for both C++ and C jump on void main[*]Your common sense - Look at the C runtime for the compiler you use.....VC++'s runtime calls main and assigns the return value to an int...that int is then used in a call to exit() to destroy the process. [/list=1]

    .....if she has half a brain and more than a year's experience then she will be under no illusions on this point. If she still doesnt understand, then tell her to post here too....

  14. #14
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Well shes a stickler for her ways so i'm afriad theres nothing more i can do accept do it her way in class then come home and correct it when i put it into my personal lib.

  15. #15
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    the program WILL return something to the operating system. if you void main (), then either:

    1: the compiler will correct your error and return a value to the os
    2: random garbage will be returned to the operating system
    3: your program will crash
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM