joshua50187

c++ learning and comprehension

78 posts in this topic

well im not trying to seem like i have a big ego but i know the way i learn and no i read them i don't just look at the preety pictures of code i do lack a basic comprehension of functions and everyting the guy who replied before you helped more then any one else he understood the title of this discussion and that is how everyone else learnt and what helped them with learning and comprehension of the different data types and features of c++ i don't have to stroke my ego online im asking for simple help with by finding out what helped you. i read the books over and over again the more i read the less i understand

Is it me or are the last few posts essentially the same thing where he whines and keeps pushing for someone to explain the basic concept of a function?

Have you tried writing a simple function and then trying to use it in different ways so maybe you would learn visually and from practical experience? That helps me sometimes.

Maybe something like : (Excuse my java)

int Add(num1, num2) {
return num1+num2;
}

and then using that function as a part of a larger code?

Maybe you could get two numbers, execute the function, and then print out the value of the function?

That would be a simple program.. I really don't know how to explain it any simpler.

0

Share this post


Link to post
Share on other sites

like this

int add(num1, num2){
return num1 + num2;
}
main()
{
int num1, num2;
cin >> num1;
cin >> num2
add();
cout << add();
return 0;
}

hold on i m going to run this real quick

0

Share this post


Link to post
Share on other sites

#include <iostream> //1

using namespace::std; //1

int add(int num1, int num2){ // 4
return num1 + num2;
}

main()
{
int num1, num2;
cin >> num1;
cin >> num2; //2
cout << add(num1, num2); //3
return 0;
}

This is a working version of the code you posted.

The changes have been numbered in the comments:

1. didn't import iostream so the program couldn't use cin or cout

2. no semi-colon on the line: cin >> num2

3. called add with no arguments.

The function is delcared with two arguments: int add(int num1, int num2)

so when you call it you need to supply two ints in the brackets: add(3, 4) or add(num1, num2)

4. no types given for arguments in function delceration (you need to write the types of the input that the function)

When a function is declared it needs to know what type of arguments to expect:

int add(num1, num2) doesn't tell it what num1 and num2 are, they might be ints but they could just as easily be characters or anything else.

you need to write:

int add(int num1, int num2) so that it knows to expect ints.

0

Share this post


Link to post
Share on other sites

ok thank you very much and when i ran it i fixed the semicolon problem and i re read the code and this helps uber mucho thank you so much

0

Share this post


Link to post
Share on other sites

i have another question too i know what arguments are in the above program but i sometimes hear of command line arguments and other things where there is just one funstion like hold on

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}

what are these arguments for

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

0

Share this post


Link to post
Share on other sites
ok thank you very much and when i ran it i fixed the semicolon problem and i re read the code and this helps uber mucho thank you so much

Ironically, after you've finally convinced someone to give you an example of a function, it looks exactly like (surprise!) examples you might find in your 15 C++ books. I don't mean to drone on and on here, but you did exactly what I said you would. Someone finally answered your question that could have easily been answered by reading your books, and then you turn around and ask another such question. The argc and argv variables are covered in your 15 C++ books.

0

Share this post


Link to post
Share on other sites
ok thank you very much and when i ran it i fixed the semicolon problem and i re read the code and this helps uber mucho thank you so much

Ironically, after you've finally convinced someone to give you an example of a function, it looks exactly like (surprise!) examples you might find in your 15 C++ books. I don't mean to drone on and on here, but you did exactly what I said you would. Someone finally answered your question that could have easily been answered by reading your books, and then you turn around and ask another such question. The argc and argv variables are covered in your 15 C++ books.

I think it's time to just give up on this thread. He is going to continue answering questions that are all answered well in at least one of his books. This are all very basic concepts of C++ (as well as other languages), just imagine when he gets into object...He claims to be 18, but I'm sure that at least one of his 15 books could explain at least this much of C++ to anyone who was able to read. They might not be a good programmer, but they could probably at least understand the topic being explained.

0

Share this post


Link to post
Share on other sites

actually they aren't mentioned at all i just checked. and dude before me look at the topic learning and comprehension i don't understand something so i ask it in that bit of code i just gave i have no idea why they are there and have even googled it and i get nothing comprehensible to my question and what is a forum for other then to talk about the issues you have about one subject or another and im having problems with learning and comprehending c++ i don't need to be spoon fed just smoothed down around the edges about the basic of things im rereading teach yourself c++ 7th edition by al stevens right now and it does mention functions just not clearly there is no arguments in the example and when i put it into the compiler it i get errors

0

Share this post


Link to post
Share on other sites

I just don't know what to say. Al Stevens is a very good writer, many people here might know him from his "C Programming" column in Dr. Dobbs Journal. I'm looking at the table of contents of "Teach Yourself C++" and it seems very in-depth, this looks like an excellent C++ book for beginners. From Amazon's nifty search feature, it looks like argc and argv are covered on page 210. Now that we know you have a decent book (even though the other 14 may be less than decent), I don't understand why you keep coming back and asking questions. I doubt anyone here can describe this any better than the venerable Al Stevens. Chapter 3 is even devoted entirely to functions, how is some half-assed example code someone posting on the forums here helping you at all?

But what can I say? If this book doesn't click with you, try another one. You seem to have plenty of them. Sadly, I can't recommend a book for you. I learned C++ from "The C++ Programming Language" which, honestly, would frustrate you with the first chapter alone.

0

Share this post


Link to post
Share on other sites

as you know, every c++ program has a main function. 
The main function has two parameters that you have not seen yet,
because none of the programs have defined those parameters.
All the programs so far have defined main with a empty parameter list.
But main does indeed have two parameters. The two parameters are an
int and a pointer to an array of char pointers the int parameter contains
the number of command line arguments that the user types on the command
line to run the program. The char*[] argument points to an array of
character pointers, which themselves point to the textual command-line
arguments although you may name these two parameters anything you
like, the convention is to nmae them argc and argv and to declare then
in the main function header [code]int main()
{
//...
}[/code]

the argc parameter always has a count of at least 1, and has a higher

count if the user types arguments on the command line. There is always at

least one char pointer in the array pointed to by argv, and it, argv[], points to

the name of the program's executable file. if argc is greater then 1, the

following argv parameters, argv[1], argv[2], and so on, point to the

command-line arguments as they were entered on the command line

arguments are separated by whitespace. If a command-line argument needs

white space, the user surrounds the phrase with quote marks("), assuming your

operating enviroment supports such command-line expansion.

For example, consider the following command-line, which includes the

program name that you type to run the program :

pr13002 foo bar "foo bar"

The parameters point to the following null-terminated strings as shown in table 13-1

{ argv[0] pr1301

{ argv[1] foo

{ argv[2] bar

{ argv[3] foo bar

[code]#include <iostream>
using namespace std;
int main()
{
cout << "This program is " << argv[0] << endl;
for(int arg = 1; arg < argc; arg++)
cout << "Argument " << arg << ": " << argv[arg] << endl;
return 0;
}[/code]

this program displays the command-line arguments on standard output

by iterating the argv array through the element subscripted by the argc

parameter. if you enter the command lines shown above and run the program

from within the compiler. An application program interprets the meaning the

meaning of command line arguments and modifies how the program works

accordingly. command-line arguments can include program switch settings,

modes, filename lists, path specifications, and so on.

ok so what argc does is store the number of arguments while argv stores the

characters in a pointer to arrays 0 being the name of the program its self i see

in the above program how to print the contents of of argv but later on it says that it

could be used for switch settings i know how it could store the path specifications and

lists but switch settings im lost and wouldn't some one have to be familiar with the

program to start with in order to put in the right arguments to pass to the program

READ: the above writtn code was taken from teach yourself c++ by al stevens

and released here by the gnu license agreement

Edited by Avatar/Oroborus
0

Share this post


Link to post
Share on other sites

Erm.. I don't think you quite understand the GPL. You can't just release someone else's work under the GPL. Has the author released this under the GPL?

And yeah, that's kind of the point. You need to read the docs before you can use the command-line switches.

0

Share this post


Link to post
Share on other sites
Erm.. I don't think you quite understand the GPL. You can't just release someone else's work under the GPL. Has the author released this under the GPL?

And yeah, that's kind of the point. You need to read the docs before you can use the command-line switches.

GPL is a ugly, ugly beast.

0

Share this post


Link to post
Share on other sites

ohm i just gave credit for the code to al stevens and said it was able for what ever you want and yeah i don't quite understand them either i just know that if you try to release anything under the gnu you have to realease everything

0

Share this post


Link to post
Share on other sites

But you can't release other people's work under a license. The GPL is not a tool for plagiarizing or reproducing work illegally.

0

Share this post


Link to post
Share on other sites

im not releasing work illegally its just like taking notes or coping a part of a statment it totally legal cause i boght the material and it is only for viewing im not releasing anything im using my property that was wrote by someone else to explain a difficult subject in a disscusion it would be totally gay to even talk about it cause i did it and would love to see anyone try to charge me for it i gave the arthur props on his work so im not saying it is mine so it is not plageirism and i did not break any copy written laws cause i did not produce the book in its entirety just a excerpt of it for a discussion

0

Share this post


Link to post
Share on other sites

Well if the author hasn't released his work under the GPL license, then you aren't releasing his work under the GPL license agreement... If he has, then it's my mistake.

0

Share this post


Link to post
Share on other sites

im not releasing his work i took a part his work im not breaking anylaw cause i am not making any money from it as well as i did not reproduce the whole book it's like amazon takes pages out of the book and displays them do you think they ask every authur hey can we do this no its just a little bit , what i said about the license is that the code was released under the gpl and that the thing i wrote was written by al stevens and not me

0

Share this post


Link to post
Share on other sites

its the same basis as peer to peer sharing i could copy the fuck out of the book and give it to anybody i wanted as long as i wasn't selling it to make money

0

Share this post


Link to post
Share on other sites

You obviously don't know much about copyright laws, and yes, Amazon does get permission (as far as I know) to put up those chapter excerpts from a book.

Edited by livinded
0

Share this post


Link to post
Share on other sites
You obviously don't know much about copyright laws, and yes, Amazon does get permission (as far as I know) to put up those chapter excerpts from a book.

Yup. Actually on one old BRR episode, Stankdawg and his co-host we're talking about that. It believe it was either 18 or 19.

Edited by relyt_123
0

Share this post


Link to post
Share on other sites
its the same basis as peer to peer sharing i could copy the fuck out of the book and give it to anybody i wanted as long as i wasn't selling it to make money

Um.. but that is illegal. Copyright controls who has the right to copy a body of work. Making hundreds of copies and sending them to people over the internet is something you do not have the right to do. It doesn't matter if you're making a profit or not.

Edited by Ohm
0

Share this post


Link to post
Share on other sites

study this i had to right a paper on copy right laws in 8th grade

Criminal offences

For the most part, the criminal law is only used for commercial copyright infringement with one exception, and an offence is committed when, knowing or reasonably suspecting that the files are illegal copies, and without the permission of the copyright owner, a person:

* makes unauthorised copies e.g. burning music files or films on to CD-Rs or DVD-Rs;

* distributes, sells or hires out unauthorised copies of CDs, VCDs and DVDs;

* on a larger scale, distributes unauthorised copies as a commercial enterprise on the internet;

* possesses unauthorised copies with a view to distributing, selling or hiring these to other people;

* while not dealing commercially, distributes unauthorised copies of software packages, books, music, games, and films on such a scale as to have a measurable impact on the copyright owner's business.

* publishing someone else's original copy work and claiming you have made it. (This is known as plagiarism and is completely different than copyright infringement, but laws concerning it come under the section of copyright law in some countries)

The penalties for these "copyright infringement" offences depend on the seriousness of the offences:

* before a magistrates' Court, the penalties for distributing unauthorised files are a maximum fine of £5,000 ($9,202) and/or six months imprisonment;

* in the Crown Court, the penalties for distributing unauthorised files are an unlimited fine and/or up to 10 years imprisonment.

Also note s24 Copyright and Related Rights Regulations 2003 which creates a range of offences relating to the distribution of any device, product or component which is primarily designed, produced, or adapted for the purpose of enabling or facilitating the circumvention of effective technological measures. When this is for non-commercial purposes, it requires there to be a measurable effect on the rights holder's business.

its legal cause im not within any of these categories because it was not a complete copy of the manuscript i might not have the authors permission but is of no measurable impact on the author and since i did not say i wrote it and explained that the code was free to copy and redistibute anyway you want im not plagiarizing anything im not distributing ot selling or hiring these to anyone i just wanted to draw to your attention what the book s said.

0

Share this post


Link to post
Share on other sites

The point is not that you aren't making money. It's the fact that he is losing money from potential buyers.

0

Share this post


Link to post
Share on other sites

your profile says you're from san jose, california, but that is clearly british copyright law.

0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.