Professional Documents
Culture Documents
Introduction to C++
Name of Student: ABU BAKAR
Section: BE-MTS-F-19-A
Date: 11/02/2020
The line using namespace std; tells the compiler to use the std namespace. Namespaces
are a relatively recent addition to C++.
Part 3:
Single-line comments begin with // and stop at the end of the line. The line intmain() is the main
function where program execution begins.
Functions:
• The line cout<< "Hello World"; causes the message "Hello World" to be displayed on the
screen.
• The next line return 0; terminates main( )function and causes it to return the value 0 to the
calling process.
Some rules for printing,
Description Command Output
Printing double quotes (“) cout<<”Hello \”World\””;
Hello “World”
Printing back slash ( \ ) cout<<”Hello \\World”;
Hello \ World
Printing tab space cout<<”Hello \t World”;
Hello World
jump to new line cout<<”Hello \nWorld”; Hello
World
jump to new line cout<<”Hello” Hello
cout<<endl<<”World”; World
Arithmetic Operations:
Description Operator Answer
Addition cout<<5+2 7
Subtraction cout<<5-2 3
Multiplication cout<<5*2 10
Integer Division cout<<5/2 2
Modulus ( remainder ) cout<<5%2 ; 1
Division including float cout<<5.0/2 2.5
Variables:
Variables are used to store data inside them.The name of a variable can be composed
of letters, digits, and the underscore character. It must begin with either a letter or an underscore.
Upper and lowercase letters are distinct because C++ is case-sensitive Variable type (Data type)
How do define in C++ Integer int w; Decimal float x; A Single Character char y; Boolean bool z;
Assignment operator:
Solve expression on right side and assign the result in variable of left side. For example.
#include<iostream>
using namespace std;
void main () {
int x, y;
cout<<”Enter a number: ” <<endl;
cin>>x; y = x*x;
cout<<“The square of “ << x << “ is: “ << y; }
LAB TASKS:
1. Write a program that displays the following output on screen Danny asked, “Are you alright?”
Harry replied.”I’m fine”
Task:-
2. Write a program in C++ that takes input from user and display message on screen?
Task:-
Output:
THINK:
1. What is the role of header file iostream.h?
Ans.
It is used in C++ in order to include the header file “iostream” in the program. Iostream is
used for calling the commonly used functions like cout,cin in a C++ program. It is used to include
the header file “conio” in a program
2. If we print “Enter an Integer” but cin in a variable of float data type, will it cause any
error?
Ans.
It doesnt causes any error . However it simply displays the integer value entered.