Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Teach yourself C++ Empty Teach yourself C++ Fri Apr 01, 2011 5:53 pm

mwambe

mwambe
Moderator
Moderator
Welcome to Teach Yourself C++ in 21 Days! Today you will get started on your way to becoming a
proficient C++ programmer. You'll learn
-Why C++ is the emerging standard in software development.
- The steps to develop a C++ program.
- How to enter, compile, and link your first working C++ program.


Here we go!!!!!!
As object-oriented analysis, design, and programming began to catch on, Bjarne Stroustrup took the
most popular language for commercial software development, C, and extended it to provide the
features needed to facilitate object-oriented programming. He created C++, and in less than a decade
it has gone from being used by only a handful of developers at AT&T to being the programming
language of choice for an estimated one million developers worldwide. It is expected that by the end
of the decade, C++ will be the predominant language for commercial software development.

The steps to create an executable file are
1. Create a source code file, with a .CPP extension.
2. Compile the source code into a file with the .OBJ extension.
3. Link your OBJ file with any needed libraries to produce an executable program.

The Development Cycle:

Type the first program directly into your editor, exactly as shown bellow. Once you are certain it is correct,save the file, compile it, link it, and run it. It will print the words Hello World to your screen.
Don't worry too much about how it works, this is really just to get you comfortable with the
development cycle.

1: #include
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }

Try running "file you created".EXE; it should write
Hello World!

Compile Errors
Compile-time errors can occur for any number of reasons. Usually they are a result of a typo or other
inadvertent minor error. Good compilers will not only tell you what you did wrong, they'll point you
to the exact place in your code where you made the mistake. The great ones will even suggest a
remedy!

You can see this by intentionally putting an error into your program. If HELLO.CPP ran smoothly,
edit it now and remove the closing brace on line 6.

Now your code will look like this:
1: #include
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;

Recompile your program and you should see an error that looks similar to the following:
Hello.cpp, line 5: Compound statement missing terminating } in function main().

Q&A
Q. What is the difference between a text editor and a word processor?
A. A text editor produces files with plain text in them. There are no formatting commands or
other special symbols required by a particular word processor. Text files do not have automatic
word wrap, bold print, italics, and so forth.
Q. If my compiler has a built-in editor, must I use it?
A. Almost all compilers will compile code produced by any text editor. The advantages of
using the built-in text editor, however, might include the ability to quickly move back and forth
between the edit and compile steps of the development cycle. Sophisticated compilers include
a fully integrated development environment, allowing the programmer to access help files,
edit, and compile the code in place, and to resolve compile and link errors without ever leaving
the environment.
Q. Can I ignore warning messages from my compiler?
A. Many books hedge on this one, but I'll stake myself to this position: No! Get into the habit,
from day one, of treating warning messages as errors. C++ uses the compiler to warn you when
you are doing something you may not intend. Heed those warnings, and do what is required to
make them go away.
Q. What is compile time?
A. Compile time is the time when you run your compiler, as opposed to link time (when you
run the linker) or run-time (when running the program). This is just programmer shorthand to
identify the three times when errors usually surface.

Quiz
1. What is the difference between an interpreter and a compiler?
2. How do you compile the source code with your compiler?
3. What does the linker do?
4. What are the steps in the normal development cycle?

Exercises
1. Look at the following program and try to guess what it does without running it.
1: #include
2: int main()
3: {
4: int x = 5;
5: int y = 7;
6: cout "\n";
7: cout << x + y << " " << x * y;
8: cout "\n";
9:return 0;
10: }
2. Type in the program from Exercise 1, and then compile and link it. What does it do? Does it
do what you guessed?
3. Type in the following program and compile it. What error do you receive?
1: include
2: int main()
3: {
4: cout << "Hello World\n";
5: return 0;
6:}

Bye for now..see u next time for "The Parts of a C++ Program".......Hope you enjoyed it!!!!!!!! Very Happy

http://demwambe.blogspot.com/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

 
ReedzSolution © 2011 | StaffList | Powered by: Forumotion

Forumotion's free forums | Art, Culture and Leisures | High-Tech and Multimedia | ©phpBB | Free forum support | Report an abuse | Forumotion.com