[Site Home] [Forum Home] [Articles] [File DB] [News Archives]

General PC Talk -> Basic C++


(View original topic)


wtd - Jun-08-2005 server time
QUOTE (aznsamaritan @ Jun 8 2005, 01:14 AM)
._. im confjused..

About what?

aznsamaritan - Jun-08-2005 server time
._. im confjused..

MikeDB - Jun-03-2005 server time
well i see alot of people sort of answerd. Sorry i took so long i had a problem with my parents but anyways i started up a new website oh and when you get there just to let you know that you internet is not down just keep scrolling down till you find a link saying ENTER ok http://members.shaw.ca/mike-db (its not quite done yet but its getting there biglaugh.gif

syb - May-25-2005 server time
or you can whip out the MBR ( if MBR means master boot record) If you have nothing worth saving. Okay thanks. I'll install win 2k then put on linux.

Red Squirrel - May-25-2005 server time
Yeah just ensure to install a linux bootloader so you can boot windows and linux, and NEVER uninstall that installation of linux, unless you plan to fdisk your entire drive. I learn't that the hard way. em320.gif

Actually, there's ways to recover from that, but they're a risk, it involves rebuilding the MBR and well, if it goes wrong, you're screwed. (I believe this would even affect non-bootable partitions on that drive, but I'm not 100% sure)

wtd - May-25-2005 server time
When you dual boot with Windows, always install Windows first. Windows doesn't play well with others, but Linux does, so if Windows goes second it'll screw up the bootloader. If Linux goes second, Windows basically doesn't even know it's there, which is just fine. smile.gif

syb - May-25-2005 server time
Okay thank. I am sure i'll have some questions.

I just thought of one. You said your running linux right now. Well i was wondering if you knew how to partion with linux already as your OS.

I am using redhat 8.0 and want to put daul boot (one as win 2k and the other as redhat) on it but all the stuff i've found was how to partion with win 2k then put on linux.

wtd - May-25-2005 server time
Some simple Turing -> Python comparisons

Conditionals:

CODE
if 42 < 34 then
  put "Hello"
elsif 56 > 89 then
  put "World"
else
  put "Foo bar!"
end if


CODE
if 42 < 34:
  print "Hello"
elif 56 > 89:
  print "World"
else:
  print "Foo bar!"


Defining a function:

CODE
function square (a : int) : int
  result a * a
end square


CODE
def square(a):
  return a * a


While loop:

CODE
var counter := 0

loop
  put "Hello"
  counter += 1
  exit when counter = 5
end loop


CODE
counter = 0

while counter < 5:
  put "Hello"
  counter += 1


Looping over an array/list:

CODE
var arr : array 1 .. 5 of int := init (3, 4, 1, 7, 8)

for i : 1 .. upper (arr)
  put arr (i)
end for


CODE
arr = [3, 4, 1, 7, 8]

for x in arr:
  put arr

wtd - May-25-2005 server time
Feel free to ask Python questions.

syb - May-25-2005 server time
I think i'll start with python. Thank you for the info.

wtd - May-24-2005 server time
QUOTE (syb @ May 24 2005, 08:32 PM)
Interesting.. I am defiantly going to look into to it. Just one thing. Commercially which is used more often or are some better then others for a specific type of programing?

That's a very complicated question, so it deserves a thorough answer.

Certainly C and C++ are used very widely in the business world. Java is becoming their new mainstay as well. Visual Basic and C# will be relevant simply due to Microsoft's influence on the market.

That pretty much covers the widespread, really boring "corporate" languages. smile.gif

Now, what about the interesting ones?

Well, Objective-C is the language of choice for Mac development. It uses the Cocoa framework, which is just a work of art and a joy to use. Obviously, the Mac market is relatively small, comparatively, but it's an enthusiastic market, and that counts for a lot. You canw rite a killer program for Windows and you'll find there are already ten other programs that do the same thing. There're still lots of opportunities on the Mac side of the fence to make an impact.

Ada is big in the aerospace and defense industries. It's taken a lot of abuse, but it has a lot of really neat features, and the fact that it's relatively low-profile means there might be good opportunities if you can put it on your resume.

Python is the new Java. It's getting lots of hype, and lots of use at places like ILM and notably in the next version of Civ3, among many other uses. I believe Google even gives preference or did to programmers with Python in their toolbox.

If Python is the new Java, then Ruby is the new Python. It's exciting and it's starting to get a lot of attention due to Ruby on Rails, an amazingly easy framework for building web applications. Definitely worth checking out to "get in on the ground floor".

O'Caml is gaining popularity, mostly as an alternative to C++ which offers really fast executables and easier coding.

Haskell is mostly academic, but it has a lot to teach. Haskell programmers are better C++ programmers.

In conclusion...

I've learned a lot of programming languages over the years, so take it from me, it gets easier each time.

Since it gets easier each time, your best bet is to learn the languages that make it easiest first. You hae time before you're going to be looking for a programming job anyway, so learn a few other languages like Ruby, Python, or O'Caml before C++ or even Java.

The biggest stumbling block I think is going to be object-oriented programming, and wrapping your mind around it. It was for me (until I got to the serious functional programming).

You're going to be happy for an interactive interpreter when you're trying to grasp concepts like inheritance, encapsulation, and polymorphism. You're going to write a lot of stupid little classes that do nothing, and having to go through the "edit, save, compile, run" process each time you make a change will get frustrating.

In conclusion: don't worry about which language is used the most. Pick the one that'll make learning concepts the easiest. Save the hard stuff for later.

Red Squirrel - May-24-2005 server time
C++ is probably the most comonly used language for applications, while php and asp are the in the lead in terms of web based programming, php is probably more widely used. asp is Microsoft's version of php. Not sure wether or not it's good as I've never tried it, but some sites (such as a MS's tongue.gif) do use it.

Visual basic is another one that has not been mentioned, but it's ...basic. Personally I don't like it, the syntax is just way off track compared to other languages. It will do nothing but confuse you if you are learning another language at the same time. But it can be useful for making quick windows based applications.

syb - May-24-2005 server time
Interesting.. I am defiantly going to look into to it. Just one thing. Commercially which is used more often or are some better then others for a specific type of programing?

Red Squirrel - May-24-2005 server time
Actually when I started learning php (alreading knowing C++) I found that to be nice that you don't have to define types. Saves allot of headaches I find, for example a function that needs a char, but some other function returns a Cstring, then you have to somehow convert it to char so you can use the function. In php you don't have to worry about that. Php variables are also unlimited, well limited to memory I guess. But what's nice is you don't have to pre-allowcate the memory for each var.

I once found a way to run php as an interpreter and type commands directly in it and get the result, but I just checked and can't seem to find it now.

wtd - May-24-2005 server time
Well, Python and Ruby are different in that they're not statically typed.

You see, in C++, every variable has a type.

CODE
int a;
double b;


"a" is an integer and "b" is a double precision floating point number.

However, the value stored in the variable has no type.

Now, in Python and Ruby it's exactly the opposite. The value has a type, and the variable doesn't. The variable is just a name. I can reuse the name for an entirely different kind of value.

I could assign a value of 5 to "a", then immediately afterwards assign a string to the same variable.

CODE
a = 5
a = "hello"


This is perfectly legal in both Python and Ruby (and at least here they have the same syntax).

The way things are enforced in this kind of situation is what's often called "duck typing". That is, if my code wants a duck, and I give it something that quacks like a duck and walks like a duck, then what I've given it might as well be a duck. smile.gif

Ruby and Python also feature more friendly syntax than C++. It's more straightforward. In C+ the keyword "const" can have about half a dozen different meanings depending on where it is. This certainly gives the language flexibility, but it comes with a steep learning curve attached, and that steep learning curve can be frustrating.

Both languages make it easier to deal with object-oriented programming, and they feature conveniences for even simpler bits of code. Want to loop over an array in Python or Ruby, as compared to C++?

C++
CODE
int a[] = {3, 4, 5, 1, 2, 9, 8};

for (int i(0); i < 7; ++i)
{
  std::cout << a[i] << std::endl;
}


Python:
CODE
a = [3, 4, 5, 1, 2, 9, 8]

for x in a:
  print a


Ruby:
CODE
a = [3, 4, 5, 1, 2, 9, 8]

for x in a
  puts x
end


Ruby (other option):
CODE
a = [3, 4, 5, 1, 2, 9, 8]

a.each { |x| puts x }


Now, O'Caml and Haskell are a bit different. They are statically-typed like C++, but they infer types based on how you use values. They also support generics much better than C++, and generally provide lots of syntctic convenience.

They make implementing data structures beautiful. Let's consider creating a binary tree.

C++
CODE
#include <iostream>

template <typename T>
class binary_tree_node
{
  private:
     const T value;
     binary_tree_node<T> * left, * right;
  public:
     binary_tree_node(T init_value)
     : value(init_value)
     , left(NULL), right(NULL)
     { }

     binary_tree_node(T init_value, binary_tree_node<T> * l, binary_tree_node<T> * r)
     : value(init_value)
     , left(l), right(r)
     { }

     ~binary_tree_node()
     {
        if (left) delete left;
        if (right) delete right;
     }

     int length() const
     {
        int len(1);
        if (left) len += left->length();
        if (right) len += right->length();
        return len;
     }
};


O'Caml:
CODE
type 'a binary_tree = Empty | Leaf of 'a | Branch of 'a binary_tree * 'a * 'a binary_tree;;

btree_length tree =
  match tree with
     Empty -> 0
   | Leaf _ -> 1
   | Branch (l, _, r) -> 1 + btree_length l + btree_length r;;


Haskell:
CODE
data BinaryTree a = Empty | Leaf a | Branch (BinaryTree a) a (BinaryTree a)

btreeLength Empty = 0
btreeLength (Leaf _) = 1
btreeLength (Branch l _ r) = 1 + btreeLength l + btreeLength r


And for all four, with some exceptions in Haskell's case, you needn't create any source files or do any compilation. Just type your code at the prompt and hit return.

syb - May-24-2005 server time
I never heard of those except for Python. I looked each one up and read the short intro on them. I have a C++ for dumies book. I was going to try and give a crack but now I don't know weather I should. What's the major differnce between those and more commonly know C++ ?

wtd - May-17-2005 server time
Once you're done that you'll have the various tools available in your Start menu somwhere. I'm in Linux at the moment (yes, they all work within Linux, Windows, Mac OS X, etc.), so I can't say for certain. smile.gif

MikeDB - May-17-2005 server time
Oki Doki

wtd - May-17-2005 server time
Install the interpreters. smile.gif

O'Caml
Ruby
Python
Haskell


MikeDB - May-17-2005 server time
Ok and how do i do that?

wtd - May-17-2005 server time
I would highly recommend starting out with a language that has an interactive interpreter where you can enter code, run it and immediately see results. No saving to a file, compiling, running as separate steps.

user posted image

MikeDB - May-17-2005 server time
OOK i still dont understand what you are talking about but whatever.

wtd - May-17-2005 server time
QUOTE (Red Squirrel @ May 17 2005, 10:12 PM)
I don't think extension matters but usually you save as a .cpp file and .h file for header files.

Accepted extensions for C++ source files are typically .cpp, .cxx, and .C. The latter is not looked upon well due to case-insensentive file systems. ".cpp" is usually preferred. ".h" is used for all header files. ".hpp" is an option, which differentiates between C and C++ header files, but is rarely used.

MikeDB - May-17-2005 server time
And that means?...

Red Squirrel - May-17-2005 server time
I don't think extension matters but usually you save as a .cpp file and .h file for header files.

MikeDB - May-17-2005 server time
Ok i sort of get it. Now I have Edit Plus 2 if i were to use this would i put it in there and save it as a C++ file? (If i were to use C++)

wtd - May-17-2005 server time
If you're new to programming, why not take a look at a truly high-level programming language?

The biggest benefits is probably the presence of interactive interpreters in languages like Ruby, Python, Haskell, Scheme, and O'Caml.

Let's look at "Hello world" programs in a number of languages.

CODE
/* C */

#include <stdio.h>

int main()
{
  puts("Hello world!");

  return 0;
}


CODE
// C++

#include <iostream>

int main()
{
  std::cout << "Hello world!" << std::endl;

  return 0;
}


CODE
(* O'Caml *)

print_endline "Hello world!";;


CODE
-- Haskell

main = putStrLn "Hello world!"


CODE
# Perl

print "Hello world!\n";


CODE
# Python

print "Hello world!"


CODE
# Ruby

puts "Hello world!"


CODE
; Scheme

(display "Hello world!")
(newline)


CODE
// D

int main()
{
  printf("Hello world!\n");

  return 0;
}


CODE
// Java

public class HelloWorld
{
  public static void main(String[] args)
  {
     System.out.println("Hello world!");
  }
}


CODE
// C#

using System;

public class HelloWorld
{
  public static void Main(string[] args)
  {
     Console.WriteLine("Hello world!");
  }
}


CODE
-- Eiffel

class HELLO_WORLD
creation make
feature
  make is
     do
        std_output.put_string("Hello world!")
        std_output.put_new_line
     end
end


CODE
-- Ada95

with Ada.Text_IO; use Ada,Text_IO;
procedure Hello_World is
begin
  Put_Line("Hello world!);
end Hello_World;

MikeDB - May-14-2005 server time
Ok cool... now i have to find someone who has alot of spare time on ther hands. biglaugh.gif

Red Squirrel - May-14-2005 server time
C++ is actually easier then C, at least I find. Only difference I know is i/o, and C++'s i/o is much easier. ex: you can go cout<<"string"<<variable<<"string"<<variable<<variable; and mix and match like that. In C, you'll have to have a bunch of printf's and all that, forget exactly how it works, I just know C++ is easier in that sense.

MikeDB - May-14-2005 server time
hmmm well what about C? can someone bother with that? or maybe something else? I was hoping on making a thing so when you activated it, it had a popup that said "hello!"

Cold Drink - May-13-2005 server time
Look for Thinking in C++ and Beej's Guide to Network Programming. Both free and effective. Although both assume some level of competance with C, you can wing it without.

Red Squirrel - May-13-2005 server time
Good luck with that. I know exactly how it is, I've been wanting to brush up C++ but it's hard to find the right resources, I find the basic stuff is the hardest. For example, I've been trying to turn a socket application into non blocking, and set a time out for connect for the longest time. I KNOW its something really simple, but it's the thing of knowing how to do it. And you can try C++ forums but I find C++ programmers tend to be rude about helping others, I don't know why. Lot of them assume you should just know stuff off the bat, but that's not how things work.

Feel free to ask your questions here and maybe someone can help, I think a few members here know C++ and I know enough to help with basic stuff though I have not programmed much in a while.

Books are the best bet, but they're bloody expensive, and hard to get in Canada unless you want to order from the US and pay insane shipping and border fees. But it IS an option, and probably the best way to learn.

MikeDB - May-13-2005 server time
Hi all just wondering if anyone could teach me some basic C++ becuase i found that google aint so good.

(Showing 50 last posts, newest on top)