16
C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM

C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM

Embed Size (px)

Citation preview

C++ Language Tutorial

C++ Language TutorialLesson 1 Writing your first programInstalling an integrated development environment (IDE)Before we can start writing a program we need an integrated development environment which is a software application that provides essential tools for computer programs assist in software development. Essentially it is the software you will use to write and compile your code.For these tutorials we will be using a program called CodeBlocks for such reasons as:Its freeCross platform support for windows, linux and macUses a simple design ideal for beginnersInstalling an integrated development environment (IDE)To install CodeBlocks follow the steps below:Download CodeBlocks from www.codeblocks.org/downloadsOpen the executional file downloaded to start the installationFollow the onscreen instructions to install CodeBlocksOpen code blocks

Installing an integrated development environment (IDE)If you have installed CodeBlocks correctly, when open you should see the same as the screenshot below:

Before we start any coding we need to setup a new project as follows:Select File -> New -> Project. (from the top left corner)Now select Empty Project and click go on the rightSelect a title such as Hello world Program and a destination and click next, then click finish on the second screen.Select File -> New -> Empty File. (from the top left corner)Choose a name such as program.cpp ensuring the extension .cpp is at the end of the file name.

Writing Your First ProgramWriting Your First Program - #includeNow that we have our project set up we can start.The first piece of code you need to write is #include . This allows us to link our file with the input/output stream. Meaning we dont need to rewrite everything our self.#include allows you to include header files so you can add functionality to your program that has already been written by others. is the file your are including. So far your program should look like this:

Writing Your First Program ending a statementSemi Colons ; are used in c++ to tell the compiler when a statement has ended. These are essential as missing one will cause your program to not build until you correct the error. All statements in c++ end with a semi colon.Writing Your First Program int main()So now we have allowed our self to be able to input and output date however we first need a main function in which to write our code (we will cover functions later) for now all you need to know is that int main() will house the main functionality of your program. Written as Int main(){}All code needs to be placed within the squiggly brackets. Think of them as BEGIN and END the brackets define a block of code. Im sure much of this may spark a lot of questions these will all be answered in later lessons.

So far you should have:

Writing Your First Program outputting text.

Writing Your First Program outputting text.So now we want to output some text so we write this as std::cout