C++ - an introduction:
C++ was developed by Bjarne Stroustrup. It is an object-oriented programming language. It is an extension of C.
Features:
- Cross-platform language: It can be executed in multiple platforms.
- High performance: code execution is efficient.
- Standard Template Library: it has a rich set of library functions.
- Compatibility: it is compatible in C.
- Extensibility: the user can create new data types which makes the language extensible.
- Exception handling: the exceptions are handled robustly.
- Memory management: it supports both static and dynamic memory allocation.
- Multi paradigm development:It supports procedural, object oriented and generic programming.
let us create a simple c++ program to display a message.
C++ program to display a message:
First, include a built -in header file
#include<iostream.h>
Next, include a namespace std. it includes the standard
input and output functionalities.
Using namespace std;
Create a main() function with return type as int.
‘int main()’
{
}
Include the code between the { }
‘cout<<” Welcome to C++ world”;’
Finally, compile and run the program to get the output.
Here, is the program and output.
Program:
#include
<iostream>
using
namespace std;
int main()
{
cout<<" Hi, welcome to C++
world";
return 0;
}
Output:
Hi, welcome
to C++ world
Yes. The first c++ program to display a message is done.
Let us get the username and display a hi message to the
user.
Try it in c++.
Steps:
- Use the above code and modify it as follows.
- Declare a string variable name.
- Create an output statement for getting the user’s name.
- Read the name from the user.
- Display the name with hi message.
Have you tried?????
Please check with the below program…
#include
<iostream>
using
namespace std;
int main()
{
string name;
cout << "Enter your
name"<<endl;
cin >> name;
cout <<"Hi,"<< name <<",Have
a nice day!";
return 0;
}
Output:
Enter your
name
Rajeeva
Hi,Rajeeva,Have
a nice day!
Hope, you understood the program flow. Keep coding!!!!!
Comments
Post a Comment