topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday November 8, 2024, 9:14 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Exploring C++  (Read 17876 times)

arunpawar

  • Participant
  • Joined in 2007
  • *
  • Posts: 60
    • View Profile
    • Donate to Member
Exploring C++
« on: November 22, 2007, 05:41 AM »
I have Dev-C++ 4.9.9.2.I'm trying to create fun programs with it.So i pick up something

interesting and I'm attempting to create console based program to get the system details

such as:
1.CPU type (Name,specification,Speed)
2.Installed Operating system
3.Current Time
4.Motherboard Type
5.Cache Memory
6.Memory Slot detection (Type of Memory)

The problem i'm facing is how can i retreive this type of data from system using console based program?If i'm writing the program in C++,what header files i have to include? Which functions of the header are necessary to call in such case?Is it possible to create the same programs in Borland C++ Builder 6?Where to look into the help files?Which methods usually?It is really hard to find something in the help file,i hope i can get some pointer to work with.

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member

Gothi[c]

  • DC Server Admin
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 873
    • View Profile
    • linkerror
    • Donate to Member
Re: Exploring C++
« Reply #2 on: November 22, 2007, 05:55 AM »
Things like detecting memory, cpu usage etc, are very platform specific. Basically, you have to ask the operating system for that info. On windows those will be win32 API calls, on GNU/Linux you can query the files in /proc

Here's an example + source code for windows: http://www.codeproje...stem_information.asp

If you want to make it cross-platform, you can detect the operating system with #ifdef statements and have a block of code for each OS you want to implement.

Yes, this can also be done in C++ builder. C++ builder is fully compatible with C++, but then it will be windows-only of course.

There are functions to get the current time in the C time library which comes with most if not all C++ compilers by default. Info here: http://www.cplusplus...ence/clibrary/ctime/ Example here: http://www.informit....usplus&seqNum=65

When coding C++, the standard template library is your friend. Reference: http://www.cppreference.com/cppstl.html

Also, lots of things have been done before, and exist in libraries. And since pure C++ is cross-platform, I recommend you stick to cross-platform libraries for your programs if you're not using C++ Builder, in case your users ever want to use your application on a different operating system. (wxWidgets is a good cross-platform library (mainly for GUI, but has increasingly lots of other handy stuff like filesystem access, time, locales, etc,...)

« Last Edit: November 22, 2007, 06:00 AM by Gothi[c] »

arunpawar

  • Participant
  • Joined in 2007
  • *
  • Posts: 60
    • View Profile
    • Donate to Member
Re: Exploring C++
« Reply #3 on: November 26, 2007, 05:33 AM »
Thanks all i'm just get started with it.As devcp uses mingw i have to search for files specific to these.I'll let u know abt that.

also i was looking for creating some winamp style visualization with c++ graphics i wonder how to create cool visualization like these.?

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Exploring C++
« Reply #4 on: November 26, 2007, 05:53 AM »
Since you're on windows, consider looking at VC++ 2008 Express instead of devcpp/mingw - it's a more fully-featured product, and it's free.

As for cool C++ graphics and winamp visualisations, get comfortable with C++ and you IDE first...
- carpe noctem

Gothi[c]

  • DC Server Admin
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 873
    • View Profile
    • linkerror
    • Donate to Member
Re: Exploring C++
« Reply #5 on: November 26, 2007, 12:55 PM »
As for cool C++ graphics and winamp visualisations, get comfortable with C++ and you IDE first...

Golden advice.
However, once you're comfortable enough with C++, your IDE, and not to forget your debugger, you could use a few methods to achieve those effects.
1) using DirectX (DirectDraw and/or Direct3D)  (windows only)
2) using SDL (cross platform library for 2d graphics or 3d graphics through an opengl cross-platform wrapper)
3) using pure OpenGL (cross platform) good tutorials here(see tutorials menu on the left).
4) for the actual sound response you can use DirectSound (windows only), Audiere (cross platform), SDL(cross-platform) again (see here), or IRRKlang(also cross platform). (there's others too of course, if you google long enough ;))

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Exploring C++
« Reply #6 on: November 26, 2007, 05:19 PM »
Notice that OpenGL isn't 100% cross-platform - you need some per-platform init code, and to do anything interesting you need extensions, which also requires a bit of platform specific code to use.
- carpe noctem

arunpawar

  • Participant
  • Joined in 2007
  • *
  • Posts: 60
    • View Profile
    • Donate to Member
Re: Exploring C++
« Reply #7 on: November 27, 2007, 04:36 AM »
Thanks for the advice. :D
What is STL? And how it is going to help C++ programmer like me?
Also Where can i see the usage of functions mentioned in header files?For example ctime.h  has time related structure or function where to look for usage?

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Exploring C++
« Reply #8 on: November 27, 2007, 05:37 AM »
STL = Standard Template Library = "libc++"... basically things in the std:: namespace, like vectors and strings.

SDL = Simple Directmedia Layer, graphics (and more) library.
- carpe noctem

Gothi[c]

  • DC Server Admin
  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 873
    • View Profile
    • linkerror
    • Donate to Member
Re: Exploring C++
« Reply #9 on: November 27, 2007, 07:13 AM »
Notice that OpenGL isn't 100% cross-platform - you need some per-platform init code, and to do anything interesting you need extensions, which also requires a bit of platform specific code to use.

Unless you use it through SDL like I mentioned, which seems to be the easiest way to get (complete) cross-platform openGL applications to compile without editing anything on about any platform

(SDL supports:
"Linux, Windows, BeOS, MacOS, MacOS X, FreeBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
The code contains support for Windows CE, AmigaOS, Dreamcast, Atari, NetBSD, AIX, OSF/Tru64, RISC OS, and SymbianOS, but these are not yet officially supported. ")

arunpawar

  • Participant
  • Joined in 2007
  • *
  • Posts: 60
    • View Profile
    • Donate to Member
Re: Exploring C++
« Reply #10 on: February 11, 2008, 05:54 AM »
I'm going thru confusion after reading herbt scildt book of complete reference.It causesmore
pain than cure.I have some of the questions which are not properly answered by this book,can
you take a look at that & let me know you perspective.

1. What #include<filename> can do?can we use our own C++ file to include in our program,is
it possible to access classes from that file,what about main function in that file,how it
will be treated?

2. What is preprocessor directive?Where and why it is used?(I want to know the situations
and limitations of this thing)

3. When to use which loops i.e when to use "for" or "While" loop?(Actually i think using
"while" in most of the cases will put you into infinite loop mode if you go wrong,right)

4. What are cin,cout (Operators or objects of iostream) in comparison with printf and
scanf?Simmilarly what are scanf & printf?

5.What is Strong type checking & Type casting? (Both sounds simmilar but  type casting  is
rarely used while type checking is abt the code we write ,am i right?)

6.What is late binding & Dynamic binding?(I understand thru books is that till run time your
code is unknown to compiler is known as dynamic binding,i think i m right here.)

7.What is reference variable? What is the major use of this variable?

8.What is Namespace? what are these?
I have searched the internet for them but unable to get quite beginner friendly tutorial for
it.

Just let me know about these concepts of C++.Just post your perspectives about them.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Exploring C++
« Reply #11 on: February 11, 2008, 06:35 AM »
#1: "#include <file.h>" does exactly the same thing as opening file.h and copy-pasting it where the "#include <file.h>" statement is located. No more, no less.

#2: preprocessor directives are the things that start with a "#" hash sign. It can be used for preprocessor macros (you generally want to stay away from those), pragmas to control compiler-specific behavour, the classic #ifdef/#endif, and perhaps the most important, #include.

#3: you use loops when you need a loop? :P

#4: cin,cout are C++ iostreams, which are a lot more flexible than C-style scanf/printf (they let you write your own output formatters, and a lot more). They also have the potential to be buffer-overflow safe, which scanf/printf don't.

#5: type checking is done all the time by the compiler, to ensure you don't shoot of your leg doing something stupid. C has pretty weak strong type checking, C++ has relatively strong but not over-insane type checking (contrast that to Pascal which has 'char' and 'byte' types that need typecasting >_<). You use typecasting when you need to convert one "unrelated" type to another - this doesn't happen often with decently designed C++ code, but happens a lot if you need to interface with legacy C code. Prime example is using the PlatformSDK for Windows.

#6: dynamic binding/polymorphism... let's say you have a whole class of output streams you can support (to file, to console, to network, to memory...). You design an interface class for this, with all virtual functions. You can't instantiate this interface class directly, but you can instantiate the concrete derived classes (ie, FileStream, NetworkStream, ...), but all code that uses the streams can use the GenericStream class interface. Using dynamic binding, the "generic" calls are bound to the "concrete" calls of the class you're using.

That explanation was probably a bit confusing, but it's pretty simple in practice.

#7: a reference variable is similar to a pointer variable, but they're not equal. One thing is the syntactic sugar: with a pointer, you need to do "*ptr = value" or "ptr->field = value". With a reference, you can simply do "ref = value" or "ref.field = value". Also, references can't be reassigned, and they don't take up any additional memory - the are the variables they refer to. Think of them as aliases.

#8: namespaces are wonderful :-* basically, they were created to avoid polluting the global namespace, and having variable/function/class name clashes in large projects, or when using libraries. If two people wrote functions called SuperFormatter(), you'd usually be in trouble, but if they were put in separate namespaces, you aren't.

PS: is this a homework assignment?
- carpe noctem

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
Re: Exploring C++
« Reply #12 on: February 11, 2008, 07:36 AM »
Error C:\DC\ARUNPAWAR.CPP 001: Undefined symbol 'herbt scildt'

SCILDT SUX!!! C0M p1lers scuk ev3n M0re!
 


arunpawar

  • Participant
  • Joined in 2007
  • *
  • Posts: 60
    • View Profile
    • Donate to Member
Re: Exploring C++
« Reply #13 on: February 12, 2008, 05:08 AM »
 ;D
I never ask homework stuff cause i'm graduated with electronics engg major.