Jump to content

Talk:C++/Introduction

Page contents not supported in other languages.
Add topic
From Wikiversity
Latest comment: 12 years ago by Gilbrilthor in topic Exercises

Good job

Suggestions

[edit source]

Someone familiar with Thinking In C (available for free online) might want to include some references to the material,. it provides very clear explanations for a great deal of C++ for people of all expireince levels.

Additionally, the definitions of what constitutes a line of code might be moved to above the code itself. Some description about directives vrs code or how code is compiled might be appropriate there as well. I know partial descriptions of all of these are scattered about, I'm just suggesting collecting it in one place and clarifying ^.^

Perhaps namespaces should be abbreviated? A lesson explaining the use of namespaces and the creation of them could exist further in the course, allowing a great deal of expansion on the subject. Thoughts about body text:

One of the biggest fundamental problems in old programming languages was the use of identifiers (needs explanation of what consitututes an identifier). With only global variables available, programmers often found themselves having to use cryptic names for any stored data. Even something as simple as a loop counter could be accedently mistaken with other variables.

Two main approaches have been developed to solve this problem. First, in object oriented languages, the members (def) of any class could only be accessed via an instance (def) of that class, preventing naming collisions. Second, groups of identifiers can be lumped into a category called a "namespace". When accessing a member of a namespace (how to)... This prevents collisions of like-named identifiers.

Namespaces were terribly confusing for me initially before anyone explained why and how they were created. I think that we need to avoid the use of them in the code until they are explained. Perhaps a section briefly explaining identifiers and datatypes should be before this lesson?

Food for everyone's thought! feel free to do what you will with it.


I think that a thorough discussion and list of compilers should be included before the first section of code. That way, readers will not sit there wondering what to do. Also, a description of and IDE, and mention of Xcode (and its free-ness with the OS) should be included.

just my thoughts.

A note to myself and others: I'm going to add links to other wiki articles as soon as I can. I'm new to how wikis work, so I'll figure this out as soon as possible (aka when I have some free time tonight between studying for midterms). I want to also give kudos to the original author of this page, and I hope I didn't undermine your teaching. I just wanted to add some explanations as to how to code worked. Cheers! Next lesson: Variables and user input

A note about changes to this work: I came across this lesson and hopefully you don't mind some minor changes and additions I am making to this article to make it more coherent. Thanks in advance.

Line 36 - mispelled word

[edit source]

Hello,

   I noticed "namesapce" in line 36 was not spelled correctly. Just thought I would report it.

Thanks for all of your hard work,

   Russell

Concepts

[edit source]

I don't think some concepts were introduced clearly to begginers, if I'm allowed to I'd like to rewrite part of it.

- Vitor 14:11, 18 August 2007 (UTC)Reply

A question regarding Identifiers

[edit source]
I'm currently taking an Introduction to Programming course and thought I'd look here for additional information. Many of the identifiers we use in class are used here differently (such as using cout<<Text<<endl rather than printf("text")). And so I am wondering, which would be better to use if any and why? Zulu Inuoe 22:36, 3 October 2007 (UTC)Reply

Answer

[edit source]

printf, scanf, etc are all part of the stdio. They are C code, and not C++ code. For this article to be on C++ the authors chose the use the C++ equivalents of printf, scanf, etc.

Namespace

[edit source]

I'm a beginner and the concept of namespace is a little confusing to me. This lesson introduces the idea, shows how to use the using namespace std;, but then includes a comment in the code example saying that it's not a good practice. ???? --12.150.181.20 17:40, 12 December 2007 (UTC)Reply

Yeah, me too. I'm three paragraphs deep reading about "namespaces" and "identifiers" and since I still haven't been informed as to what these things are (or what their purposes are), all that I read is just words on a page. None of it means anything to me.

Answer

[edit source]

A namespace is an container wrapping identifiers. using namespace std; makes everything in namespace std available without typing std:: every time. Miklcct 12:28, 10 April 2009 (UTC)Reply

About Namespaces

[edit source]

You can think of namespaces as packages that contain code that you may find useful. Lots of people have written lots of code over the years. Now imagine if someone wrote a piece of code called FFT, which returned some sort of data. Then another person wrote another piece of code called FFT, which returned some different data. You've run into a problem of there being two methods called FFT that do different things. This is bad news, because the compiler doesn't know which to use. It can also be confusing to the programmer because they aren't sure which one the compiler is going to pick, or the compiler may just throw an error.

To fix this problem (and to organize code a bit better) programmers can put all of their code into a package. In C++ this package is called a namespace. The namespace called std contains many useful functions, containers, etc that programmers use often. cout, cin, etc are all part of the std namespace. So are strings, vectors and other containers. To use all of this code in the std namespace you could call them with std::indentifier, where identifier is the name of the method, object, or whatever you want to use. It can become tiresome, however, to use std:: over and over again. For example:

std::cout << "Hello" << std::endl;

So you can tell the compiler to look in a particular namespace if it can't find the method or objects in your own code. The same code above with the 'using namespace std'

using namespace std;

cout << "Hello" << endl;

Color Coding

[edit source]

Wikipedia Provides c++ color coding through the <syntaxhighlight lang="cpp"></syntaxhighlight> tag. That shoud be used instead of the pre tag all over the book. There is also a need to define the guidelines or standards for the usage of material over the book so that constancy is maintained.Atishay811 18:57, 13 July 2009 (UTC)Reply

Exercises

[edit source]

I think that adding a section of exercises at the end of the lessons would help cement the ideas more firmly. In this lesson, I don't know if there are a lot of things we could ask, but I know that writing and changing code is the best way for me to learn. So, if I'm not going to rain on anybody's parade, I would like to help with that. I would also welcome exercise ideas. It's looking great, and I want to help make it better! Gilbrilthor (talk) 12:43, 6 October 2012 (UTC)Reply

Exercises

[edit source]

I am a rank beginner to all this. In Exercise 1 it says to copy the following, but it doesn't say to what it should be copied. Then it says to edit it so it compiles. Where? Maybe some instructions like the making toast example used elsewhere would help, because I'm lost and can't go any further than where I'm at now, which so far is click-drag copy.