Thread: How do I get a computer to detect its own name and hardware?

  1. #16
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24

    It's done!

    I know it's probably a pile of lame compared to the sort of stuff most of you guys can probably make, but I'm happy with it, especially for a first C++ project.

    I called it 'Get To Know Your Computer'.

    You can download the .exe here and the source here.

    As you might have guessed, it's Windows only. Sorry about that guys, Linux may be better, but I need my adobe/macromedia suites/3dmax/computer games/everything else

  2. #17
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Any ideas on what else the computer knows about itself?

    From what I have gathered in my Intel 80x86 Assembly class, the computer doesn't know *anything* about itself. All it knows is 2 states of existence: on or off, 1 or 0, true or false. How we interperit(sp?) the data is the key to making computers useful. The only thing the computer might "know" about itself is how to send electrical currents according to the hardware architecture. Sorry to burst your bubble.

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    What the computer "knows" is a philosophical question. It can be programed to output some information from a database in response to a query but dose it realy know that information? It knows that it is the correct response but dosen't understand the conent.

    You could create a relational database with links between different facts to give the computer an "understanding" of the information it contains such that it would apear to understand things but still...
    Last edited by Quantum1024; 02-19-2006 at 11:50 PM.

  4. #19
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24
    Hehe, I was only talking philosiphically anyways, so my bubble's quite intact thanks . The same as how I was getting the computer to 'know' how long it has been 'awake'. The computer doesn't have any sort of knowledge of when it was turned on, but that information can be forced from it be the user... sort of. I'm not as clued up as you guys but I get the picture I think.

  5. #20
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Thats a nice little program! Very creative for a beginner. just
    some minor advice though with regards to the source:

    use cin.getline to read the name, as just using cin will stop
    at spaces and messes with your remaining I/P if they are entered.
    that cin.ignore wont fix that kind of user mistake.

    Avoid using goto. You are a beginner and many people condone
    it for beginners, but i've personally always thought that its a bad
    idea to get into bad habits at the start as they tend to be harder
    to drop than pick up. i've never once used a goto, there is always
    a way of avoiding it. since your label and the statement are so
    close in the code, it should be no trouble to use a while loop.
    although there is nothing wrong with your goto, people tend to
    be very aggressive towards it as it makes the code a little more
    vague than a while loop with a good condition.

    also, you went to the trouble of using the correct return type for
    main but you never return 0! Compilers fill this in but you
    wouldn't do it in your own functions!

    lastly, time.h is already a C header file, probably a good idea to
    name your header file something slightly different.

    all of these are fairly minor issues, i'm just trying to point them out
    in case you encounter them from someone else who might be a
    bit crueller! Overall, an excellent program for someone so new
    to C++, I look forward to your next project
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  6. #21
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quote Originally Posted by SirCrono6
    Well, you really shouldn't be concearning yourself with non-standard Windows only code so early on...
    I think this is true as well, however he is learning. All of his jumping in is also getting him familiar with files, programming environment, how functions work, (even an intro to Windows enviornment), etc; things which sometimes are overlooked, while books and classes jump right in to code (usually), and he can always get to that later.

    I originally started programming(VB) because a friend and I needed a custom program to periodically call (harass) my friend's dad; go figure.

    Besides, the best way to learn is experience, and this definately counts.
    Last edited by neandrake; 02-21-2006 at 01:57 AM.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  7. #22
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24
    Thanks for the advice, I'm only at home briefly at the moment but I'll amend the code later. I don't like using goto either but there was only the one result that needed a loop so I figured there would've been less code doing it that way that having a while loop.

    I downloaded the source for Quake 1 and 2, and whoah! It's pretty confusig stuff, I'm looking forward to being able to write that kinda stuff, but it's still early days.

    Also, where did i return 0 for main? I returned 0 for uptime(), but I didn't for main as far as I can see.

    See you in a bit when I amend stuff.

  8. #23
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    no what i meant was you were supposed to return 0, that u
    didn't do it.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  9. #24
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24
    Quote Originally Posted by Richie T
    no what i meant was you were supposed to return 0, that u
    didn't do it.
    According to the very first C++ tutorial on this site:

    Upon reaching the end of main, the closing brace, our program will return the value of 0 (and integer, hence why we told main to return an int) to the operating system. This return value is important as it can be used to tell the OS whether our program succeeded or not. A return value of 0 means success and is returned automatically (but only for main, other functions require you to manually return a value), but if we wanted to return something else, such as 1, we would have to do it with a return statement
    Here's the link too, it's the paragraph just above the 2nd example: link .

  10. #25
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    your missing my point, i already said that the compiler will return
    0 automatically if you forget to put it in. Then why mention it?
    i study programming as a module for a college course, and it
    is a common requirement for assignments that code should
    compile without errors or warnings. leaving out return 0
    will result in a compiler warning. its a small nitpick to some,
    but put yourself in the position of a career programmer,
    the same directive applies in most, if not all jobs they undertake
    for a company. the reason for this requirement is that not all
    compiler warnings are this trivial, and people decide to run their
    code with warnings and it results in a run time error, and they end
    up having to fix the warning at some point. i leave it to you to
    decide if this is meaningful or not, but i think it is...
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  11. #26
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24
    Fair enough man, I'll remember that one. Sorry if you got a tad wound up
    My compiler (Dev-C++) doesn't give me any warnings for not having it, but I guess you know your stuff and it can't hurt to have it. I'll get to amending everything now. Chers for the other stuff you pointed out too.

  12. #27
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24

    Thumbs up

    I've amended everything now, renamed "time.h" to "uptime.h", used cin.getline(name,30) for the name (whilst increasing the value from 20 to 30), got main to return 0, and i got around using a goto aswell, by using a do...while loop like this:
    Code:
        do {
            cout<<"How old are you, "<<name<<"?\n\n";
            cin>>age;
            cin.ignore();
            Sleep(600);
            if (age<0) {
                       cout<<"\nIt doesn't take a computer to know that's not possible.\n";
                       Sleep(1000);
                       cout<<"Stop being so silly.\n";
                       Sleep(1000);
            }
        } while (age<0);
    It's uploaded under the same names, replacing the old ones. Oh, and I also added you to the credits Richie T if you don't mind. Now to have a look at some more tutorials for a few days before I mess about with another program. Bye for now!

  13. #28
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    I love the enthusiasm put into this program.

    The Possibilities are Endless!

    Nice job on it however.

  14. #29
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    yeah, I like the program too, there is one thing I'd advise though eddwills, rename the title of the console like so:

    Code:
    SetConsoleTitle( "Name of console window thing" );
    I think you need to #include <windows.h> to do it.

    How long are you programming?

  15. #30
    edd of all trades
    Join Date
    Feb 2006
    Location
    Stafford, England
    Posts
    24
    ahh thanks for that one, that'll come in useful. I'll amend that quickly now. I've only been learning C++ for a few days, but I did learn BASIC quite a few years back now. Some of it has come in handy, but only a bit. Oh, and I've always been a whizz at maths so that helps too.

Popular pages Recent additions subscribe to a feed