Monday, February 1, 2016

Hello World Program

Hello World,

Today I will show you how to do some of the simple features of C++. In particular I will be doing a program involving print statements and possibly implementing a scanner to get user input in the program. This should not difficult to implement even for a beginner. I found this program fun and interesting. 

For this program to work successfully, you will need a working compiler. As I mentioned last week, the compilers that I found are free and require no installation. The compiler that I will be using is called C++ Shell. There is also another compiler on Code Chef’s website which is free and requires no installation as well.

In many ways, from the research I have been doing on the language so far, C++ is similar to the languages I have previously worked with. However, there are minor syntax differences. In order to get a working program, you must have a main method or somewhere to call upon your previous work. You can make a main method by stating: int main() {….// this is where your work is and then finish with }. Just like Java, two slashes marks a comment.


The 1st line is the comment “Example program.” You can tell it’s a comment by the two slashes. The 2nd and 3rd lines include iostream and string is there because you have to tell the program all the components that you will be using to write out your program. This is just like how Java makes the user import rectangles or ellipses if you are making graphics. Iostream is basically the input for telling the program that you will be including declarations of the basic input and outputs your program will have. In other words you will be stating if you are printing out text. The 5th line is just making the main method. Line 7 is how to make a print statement. It starts with std::cout << “…” includes \n and ends with a semicolon. Std stands for standard and cout means character output. \n is just like Java because it allows for your previous text to be on its own line. Line 8 defines the string you will be using and it is called name. Line 9 prompts the user to enter their name and then line 10 retrieves the input you just typed in and prints a line in 11 saying “Hello, (insert name)! Thank you for experiencing this memorable occasion with me!

Lastly, I included a short video of how the program may function. Hope you enjoy it!




The information I got pertaining to this introduction to the language was obtained at www.CPlusPlus.com

2 comments:

  1. Hello, i'm from cs 270 and I wanted to share with you something I found. On my android tablet I searched up visual studios (a C++ compiler) and I came across an app where the picture was C++ programming. The app had close to if not all of the code we need for the blogs. I thought it may be a good resource for you if you were interested.

    ReplyDelete
  2. The change in syntax is definitely notable, but easy to follow. I think it's neat to see code look differently like C++.

    ReplyDelete