Register to reply

[C++] Tutorial 1: Discussion

by dduardo
Tags: discussion, tutorial
Share this thread:
dduardo
#1
Jun26-04, 08:25 AM
Emeritus
dduardo's Avatar
P: 1,919
Please post your C++ questions or comments here for Tutorial 1.
Phys.Org News Partner Science news on Phys.org
Sapphire talk enlivens guesswork over iPhone 6
Geneticists offer clues to better rice, tomato crops
UConn makes 3-D copies of antique instrument parts
Nec
#2
Jun26-04, 09:00 AM
P: 56
Quote Quote by dduardo
Please post your C++ questions or comments here for Tutorial 1.
Man!
What do you mean by tutoriel ? hmm ?
dduardo
#3
Jun26-04, 09:17 AM
Emeritus
dduardo's Avatar
P: 1,919
Look at the sticky below this thread. I'm in the process of writing up the first part. I will post it very soon.

Nec
#4
Jun26-04, 09:31 AM
P: 56
[C++] Tutorial 1: Discussion

Sorry I didn't read your notice post right above before giving a comment,
OK, seriously, the topics you listed gave me an impression of my first days in college, biting my nails and my pencil from time to time listening to my Delphi teachers trying to explain what was necessary to become a programmer, because I was starting to learn programming languages with Delphi and Basic, although their syntax and structures have been utterly erased from my memmory. What a Cool tutor you are, I have to say that!
Before introducing about array, or perhaps while you are writing about it, i also think if pointer is important enough to be included, to be digged as deeply as possible.
I think conditional statements and iterative or control statements should also dig dig diged deeply too, especially should give students some ideas of how to use if/else effectively as possible since I believe these things will be mentioned more in their future (thisz juts my personal idea). Those who hav some basic skills in progremming will suun grasp the control statements, but handling problems with those are again letthem go back to how to correctly use iterators and operators.
Ok, frankly I'm sleepy now, I can only give some *rough* draft/ideas or acutlay nothing, hoep some piple will join in to make htis much interesting and more *beautiful*.
Finaly, Stick with the Standard and update infor all the time, yor tutoriels'll look as handsome as Mangan does! :D
+Nec

*I guess there're some thinkings taht I am Mangan , byt it only happens after i see my doctor and ask her to change my all *

(tomorrow or acouple of days later, I will try to write more about what i think)
Sorry for short and quite menaingless comments-if they turn out to be so.
dduardo
#5
Jun26-04, 10:00 AM
Emeritus
dduardo's Avatar
P: 1,919
Nec, yes, I will give plenty of real world examples. What I'll do is revise and add more content to my previous postings for those who are still have difficulty while still creating new tutorials so people who already have basic programming skills don't feel like the course is going slow.
exequor
#6
Jun27-04, 10:32 PM
exequor's Avatar
P: 393
hey dduardo this is a really cool idea. i enjoyed it from since the java classs was implemented and seeing c++ i was amazed because 1. i recently started the language and 2. i use dev c++ and thats a featured program in your tutorial so I just like to let you know that what you are doing is really appreciated. its like going to school on the web.
Monique
#7
Jun30-04, 02:33 PM
Emeritus
Sci Advisor
PF Gold
Monique's Avatar
P: 4,642
Very good dduardo!!
A good resource I can learn something from
00XeRo
#8
Jul7-04, 07:46 PM
P: 1
Hey, first I was want to say good job, It's nice to see somebody who's willing to input the effort and time to help others.

Anyways...
If I had to suggest something... I would ask you to clarify your code examples a little.
like this excerpt...

int x = 1, y = 3, z = 4;
int *num;
const float pi = 3.14;
z*=y;
y = x + (int)pi;
num = &y;

if you could go into a tad more detail I'm sure that I and others would appreciate it. I know that playing around with it is a good way to learn, but I'm having a hard time understanding what's going on there and I just think it would help if you gave a little push.

Other than that though, great tutorial and I'm looking forward to the next parts.
DarkAnt
#9
Jul7-04, 07:52 PM
P: 194
Hey this is great. I'm just about to take a c++ class this summer. Great timing dduardo
cronxeh
#10
Jul7-04, 09:30 PM
PF Gold
cronxeh's Avatar
P: 1,236
hey i got a question..

suppose class Foo has function returnMe. it has no variables (meaning returnMe() without any arguments)

Foo x;

x.returnMe();
this should return an OBJECT x. So basically it just returns itself.

How do i define Foo :: returnMe() { } ??
dduardo
#11
Jul8-04, 09:27 AM
Emeritus
dduardo's Avatar
P: 1,919
00XeRo, will do. I have been a little busy with my own software project, so updating has been a little slow.

*****Advanced C++ Below. It has nothing to do with the tutorial*****

cronxeh if you want a class to return itself use the this pointer. The this pointer is a c++ keyword. Here is an example of how it works:

#include <iostream>

using namespace std;

class foo {

public:

foo* returnme(void);

};

foo* foo::returnme(void) {
return this;
}

int main( int argc, char *argv[] ) {

foo x;
foo *y;

y = x.returnme();

cout << y << endl;
cout << &x << endl;

return 0;
}
If you run this program you will see that y points to the base address of x. Therefore y is x.
DarkAnt
#12
Jul8-04, 11:26 AM
P: 194
I always wonderd what the arguments were that are inside the main meathod

int main( int argc , char **argv )

what are int argc, char **argv?
dduardo
#13
Jul8-04, 04:08 PM
Emeritus
dduardo's Avatar
P: 1,919
The arguments inside of main are used to store command line arguments. For instances:

ping -A localhost

"ping" is the program name and "-A localhost" are the arguments. The environment your in will pass the argument part to your program. Argc or Argument Count will tell you that there are 2 arguments - "-A" and "localhost". Argv or Argument Value is an array of pointers (or a pointer to a pointer) that stores the actual agrument strings.

int main( int argc, char **argv) is equivalent to int main( int argc, char *argv[] )

[edit] gnome, your right, it is an array of pointers. I should make a point about that subtle distinction in my tutorial.

An array of pointers:
int *array[];

A pointer to an array
int (*array)[];
gnome
#14
Jul8-04, 04:28 PM
P: 1,047
/*They are there to allow you to pass parameters into the program from the command line.

argv[] is an array of pointers to your parameters; the parameters are stored as character strings.

argc is the number of parameters.

argv[0] always points to the name of the program, so argc is always >= 1

For example, here is a program that prints "hello" followed by whatever string the user types after the program name at the command line, or just "hello." if no parameters are supplied:
*/

#include<iostream>
using namespace std;

int main(int argc, char *argv[]){

cout << "hello";

if (argc>1)
cout << ",";

for (int i=1; i < argc; i++)
cout << " " << argv[i];

cout << "." << endl;

return 0;

}
DarkAnt
#15
Jul13-04, 11:45 AM
P: 194
ok, apparently I was supposed to know C before taking this class. My teacher wants me to use a header file. What exactly do I put in a header file and could you show me an example?
dduardo
#16
Jul17-04, 10:01 PM
Emeritus
dduardo's Avatar
P: 1,919
When you want to include a header in a file you should write something like this:
#include "myheader.h"

The header file should contain something like this:

#ifndef MYHEADER_H
#define MYHEADER_H

//CODE

#endif
DarkAnt
#17
Jul18-04, 04:36 PM
P: 194
what type of code would I put in there?
sorry I'm so dense
gnome
#18
Jul18-04, 05:19 PM
P: 1,047
In C++ typically you would put a class definition in a header file (.h) -- just the declaration of the class, containing a bunch of one-line declarations of all of the methods and data members of the class.

Then, the code to implement all of the methods goes in an implementation file (.cpp).


Register to reply

Related Discussions
CFD tutorial Mechanical Engineering 4
C# Tutorial Programming & Computer Science 13
GR Tutorial Special & General Relativity 2
Probability tutorial Academic Guidance 0
Tutorial La Tec General Math 1