3. Demo - First Program
Category
ЁЯУЪ
LearningTranscript
00:00let us write our first program in C++ here I start Xcode create a new
00:06project in Xcode and select this option that is command line tool then you
00:14have to mention some project name that is first is the project name and the
00:18language selected is C++ there are other options also available select C++
00:24then next so where is supposed to create it so you can set the path here
00:30wherever you want to create your project say create here are the project files so
00:38click on main.cpp you can see that a ready-made code is given so it has
00:43already generated a piece of code that is executable code here are a few
00:48comments I'll remove them I'll remove these panels yeah see this command line
00:58arguments these are optional in C++ I'll just remove these command line
01:03arguments will study about these after some time so here is a readily available
01:09hello world program I'll run this let us see what I'll get here is an output
01:16window yeah hello world the output is given here here std scope resolution is
01:27used for accessing cout so instead of this we can also mention using namespace
01:36using namespace std now I don't have to use std for using cout object let us
01:45run this and check once again that's it so this is working the same program I'll
01:56just modify it for adding two numbers I'll remove these lines and I will write
02:01on the code here for adding two numbers I'll declare few variables integer a b
02:07and c see you can see that's a prompting here if there is any error in the
02:13statements see out enter two numbers then seen a and b then see a sign a plus
02:32B see out sum is then give a space and see so this is a program for taking two
02:46numbers from keyboard and adding them and displaying the result so these two
02:51lines are for taking input from the user these two lines are interactive as it is
02:55giving a message to the user informing him to enter two numbers then adding two
03:00numbers and finding sum and displaying sum here let us run this now here is a
03:08message enter two numbers I'll enter two numbers 10 and 30 now here the sum is 40
03:15I should get nl here so that the last message should come in next line nl
03:23let me run
03:29enter two numbers 10 and 30 so now this program ended with exit code 0 that is
03:36coming in the next line so sum is 40 that's it so let me modify the same
03:42program and make it as a program for taking the user name and displaying a
03:47welcome message so string is a built-in class available in C++ library that is
03:54stdio stream and we can access in the namespace std here I'll give a message
04:00see out may I know your name then seen name so str is a variable name then see
04:14out hello a space here so that space is there in between hello and name of a
04:26user I'll run the program may I know your name let us say name is John so
04:37hello John it's working I'll run it once more I'll give the name Sai Kumar
04:46let us see what happens it's giving just Sai here it's not giving the other name
04:54because the name is having two words here it's reading only one word if I
04:59want to read all the words entered in a string then the right method is there's
05:07a function available called get line get line takes input stream that is seen
05:13and next is string variable string object now let us read it using get line
05:21this is the method for reading an entire line from the keyboard may I know your
05:30name so Sai Kumar now I got a full name Sai Kumar that's it so this is a way you
05:40can access the strings whenever you require there's a built-in object
05:43available in C++ and it's a very useful object