0% found this document useful (0 votes)
14 views5 pages

Lab 2

Uploaded by

Aisha Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Lab 2

Uploaded by

Aisha Shabbir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab No :01

C++ is a powerful general-purpose programming language. It can be used to develop operating


systems, browsers, games, and so on. C++ supports different ways of programming like procedural,
object-oriented, functional, and so on.
Use of C++
1. C++ is used by hundreds of thousands of programmers in essentially every application
domain.
2. C++ is being highly used to write device drivers and other software that rely on direct
manipulation of hardware under real-time constraints.
3. C++ is widely used for teaching and research because it is clean enough for successful
teaching of basic concepts.
4. Anyone who has used either an Apple Macintosh or a PC running Windows has indirectly
used C++ because the primary user interfaces of these systems are written in C++.

Software’s Used for C++


1. Microsoft Visual Studio
2. Eclipse CDT (C/C++ Development Tooling)
3. Code::Blocks
4. Dev-C++
5. Bloodshed Dev-C++
6. NetBeans C/C++ Pack
7. C-Free

How to install IDE:


An IDE (Integrated Development Environment) is used to edit AND compile the code.

Popular IDE's include Code: Blocks, Eclipse, and Visual Studio. These are all free, and they
can be used to both edit and debug C++ code.

1. Installation of Dev C++


2. Download the DevC++ from the below mentioned
link:https://sourceforge.net/projects/orwelldevcpp/

C++ Variables
In programming, a variable is a container (storage area) to hold data.

To indicate the storage area, each variable should be given a unique name (identifier)

C++ Fundamental Data Types


The table below shows the fundamental data types, their meaning, and their sizes (in bytes):
Data Type Meaning Size (in Bytes)

int Integer 2 or 4

float Floating-point 4

double Double Floating-point 8

char Character 1

Code Snippet 1:
Execute the following to print the statement :

#include <iostream> Output:


using namespace std;

int main() {
// prints the string enclosed in double quotes
cout << "This is C++ Programming";
return 0;
}

Code Snippet 2:

Numbers and Characters Output


#include <iostream> Output:
using namespace std;

int main() {
int num1 = 70;
double num2 = 256.783;
char ch = 'A';

cout << num1 << endl; // print integer


cout << num2 << endl; // print double
cout << "character: " << ch << endl; // print
char
return 0;
}
Code Snippet 3:

C++ Input

In C++, cin takes formatted input from standard input devices such as the keyboard. We use
the cin object along with the >> operator for taking input.

#include <iostream> Output:


using namespace std;

int main() {
int num;
cout << "Enter an integer: ";
cin >> num; // Taking input
cout << "The number is: " << num;
return 0;
}

Code Snippet 4:

C++ Taking Multiple Inputs

#include <iostream> Output:


using namespace std;

int main() {
char a;
int num;

cout << "Enter a character and an integer: ";


cin >> a >> num;

cout << "Character: " << a << endl;


cout << "Number: " << num;

return 0;
}

Lab Tasks:
1. Store two integers in two variables x and y. Print the sum of the two.
2. Write a C++ program to take two integer inputs from user and print sum and product of
them.
3. Write a program to take input of length and breadth of a rectangle from the user and
print its area. (Area of rectangle=length× breadth)
4. Write a C++ program to calculate the area of a circle given its radius by using the
formulae:(Area=π×radius2)

You might also like