Ideas for learning C++

Pyotr

New Member
I've got some basic understanding of programming and C++, and am supposed to learn a bit more the coming month.
But I'm totally unimaginative (is that a word), and so I can't come up with a good project that would teach me a lot while at the same time not being too difficult.
I know "a month" isn't much time to learn a programming language, but it's better than nothing and I'll be doing nothing else all day. :p
So, anyone got any bright ideas? :)
 

dragon2309

P.I Dragon
you might wanna start off the basics, simply print a word or sentance and then end the prgram. Also, dont get into windows GUI yet, thats way advanced, stick with console applications, standard .exe files.

Bare with me, its been a while:

Code:
#include <stdio.h>

int main(void)
{
     printf("Hello there!!");
}

That will simply print on screen the phrase "Hello There!!"

If you want to get more advanced then try using numbers and calculations

Code:
#include <stdio.h>
#include <math.h>

int main(void)
{
     int first;
     int second;
     int result;

     first=8;
     second=4;
     result=first + second

          printf("%d", "result");
}

And yes, i dont know C++ at all, i know C, so forgive me if this has nothing to do with C++ whatsoever, im under the impression that they are much alike on basic levels but C++ has a few extra functiosn and possibly the syntax is different.....

dragon2309 :D
 

Pyotr

New Member
That doesn't look like C++ at all really. ;) I'm capable of doing console stuff, and "Hello world" was the first thing I tried. ;)
Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int number,bnumber,snumber;
    char name2[20];
    cout<<"Hello world!"<<endl;
    cout<<"Input number: ";
    cin>>number;
    cout<<endl<<"Number was: "<<number<<endl<<endl;
    cout<<"Good job."<<endl<<endl;
    cout<<"Now input a big number: ";
    cin>>bnumber;
    cout<<endl<<"And now a small number: ";
    cin>>snumber;
    cout<<"The numbers were "<<bnumber<<" and "<<snumber<<". The big number minus the small number is "<<bnumber-snumber<<"."<<endl
    <<"The big number divided by the small number is "<<bnumber/snumber<<"."<<endl;
    cout<<"What is your name? ";
    cin>>name2;
    cout<<endl<<"Hello "<<name2<<"."<<endl;
    
    
    system("PAUSE");
    return 0;
}
That's my first program I made today (added some boring stuff just to see if I remembered it). I'm not a complete beginner, but certainly not an advanced user. Thanks for answering though. You should try C++ some day. ;)
 

Jerkstore

New Member
What platform and compiler are you programming on?

1. Learn how to build classes with .cpp files and .h(pp) files
2. Learn how to use the argc and argv arguments
3. Learn about vectors, lists and priority_queue
4. Learn how to use pointers

That should give you a great deal of flexability for now.
Once you have that under your belt, try some sockets. Maybe start getting into threading. I'd stick with that until you understand it a bit better, then you can start designing your own user interface designs.

As far as projects go...some of my first programs consisted of: -A "grep" type of application using argc/argv. -A simple number guessing game...randomly choose a number, take a guess and have your app return if you're higher or lower until you get it right. -A simple calculator app. -Simple simulations (balls bouncing, Fish tank, Tavern simulation, Coffeeshop simulation)

Good luck in your endevours, feel free to PM me if you require assistance.
 

Pyotr

New Member
Jerkstore said:
What platform and compiler are you programming on?

...

2. Learn how to use the argc and argv arguments
http://www.bloodshed.net/devcpp.html <-- That's my compiler (Windows). Can't say much about it except it looks like Microsoft's .NET thingy.

Never heard about argc or argv before starting the program, but I'm sure I'll be learning more about them now. :)
Using a beginner's book now. Latest program I made compared two numbers to see if they were the same, and if they were divisible. Not advanced, but might as well start from scratch.
 

Jerkstore

New Member
You gotta start somewhere :)

argc and argv are used for command line arguments.
ex.
Say you want your application to compare 2 strings to see if they are the same... (we'll call the app 'compare.exe')

from the command line you would run it as: C:\compare string1 string2
just like you would use for something like the ping command... ping 192.168.1.10
in the case of ping, the IP number after the program call would be the first runtime argument.

the main method will look something like the following:

Code:
#include <iostream>
#include <string>

int main( int argc, char * argv )
{
  if( argc == 2 )
  {
    std::string firstArg = argv[1];
    std::string secondArg = argv[2];
  }
  
  std::cout << "Arg1: " << firstArg << std::endl;
  std::cout << "Arg2: " << secondArg << std::endl;
  
  if( firstArg == secondArg )
    std::cout << "these arguments are the same" << std::endl;
  else
    std::cout << "these arguments are not the same" << std::endl;

  return 0;
}

This is a very simple explaination....however what happens here is that argc is the number of arguments passed at run time. 0 is the actual application name, 1 is the first argument and 2 is the second argument. Argv holds all the actual string value array used in the command. Therefor argv[0] is the zero(th) element in the array which again, is the app name, argv[1] is the first argument's string value and argv[2] is the second arguments string value.

I hope this helps you understand.
 
Top