Lab Manual Programming Fundamentals: Submitted To: XYZ Submitted By: XYZ Section: A/B Roll Number: 123
Lab Manual Programming Fundamentals: Submitted To: XYZ Submitted By: XYZ Section: A/B Roll Number: 123
Programming Fundamentals
Submitted to:
XYZ
Submitted by:
XYZ
Section:
A/B
Roll Number:
123
Page | 2
Lab Session 01
Objective:
Hardware used:
Software used:
DEV C++
Theory:
What is C++:
Page | 3
Download Dev-C++: Go to the official Dev-C++ website or a trusted source to download the
latest version of the software. Visit: https://www.bloodshed.net/devcpp.html
Run the Installer: Once the download is complete, run the installer file you downloaded. The
installer will guide you through the installation process.
Accept License Agreement: During the installation process, you might be asked to accept the
license agreement. Make sure to read it and, if you agree, proceed with the installation.
Choose Components: You may be prompted to select components you want to install, such as
compilers and development tools. Ensure that the necessary components for C and C++
development are selected.
Choose Installation Location: Choose the directory where you want to install Dev-C++. The
default location is usually in the C: drive.
Complete the Installation: Click "Install" or a similar button to begin the installation process.
Once the installation is complete, you can choose to launch Dev-C++ immediately.
Configuration (Optional): After installation, you might want to configure the IDE according to
your preferences. This can include setting up the editor theme, compiler options, and other
settings.
Verify the Installation: To verify that Dev-C++ is installed correctly, open the IDE and create a
new C++ file. Write a simple program (such as "Hello World") and try compiling and running it
to ensure everything is working as expected.
Syntax of C++:
Line 1: #include <iostream> is a header file library that lets us work with input and output
objects. Header files add functionality to C++ programs.
Line 2: using namespace std means that we can use names for objects and variables from the
standard library.
Line 3: A blank line. C++ ignores white space. But we use it to make the code more readable.
Page | 4
Line 4: Another thing that always appear in a C++ program, is int main (). This is called
a function. Any code inside its curly brackets {} will be executed.
Line 6: Add the closing curly bracket } to actually end the main function.
Comments in C++
Program comments are explanatory statements that you can include in the C++ code. These
comments help anyone reading the source code. All programming languages allow for some
form of comments. C++ supports single-line and multi-line comments. All characters available
inside any comment are ignored by C++ compiler.
For example −
// This is a comment
The two instances cout in C++ and cin in C++ of iostream class are used very often for printing
outputs and taking inputs respectively.
Standard output stream (cout): Usually the standard output device is the display screen. The
C++ cout statement is the instance of the ostream class. It is used to produce output on the
Page | 5
standard output device which is usually the display screen. The insertion operator (<<) inserts the
value.
Standard input stream (cin): Usually the input device in a computer is the keyboard. C++ cin
statement is the instance of the class iostream and is used to read input from the standard input
device which is usually a keyboard. The extraction operator (>>) is used along with the object
cin for reading inputs.
Escape Sequences:
Escape sequences are used to represent certain special characters within string literals and
character literals. Following escape sequences are commonly used in C++.
Procedure:
Page | 6
Select "New" and then click on "Source File...". A new editor window will open.
Then I Type the following C++ code into the editor window:
#include <iostream>
int main() {
return 0;
Page | 7
Program 2: Adding comments in Hello World Program
Program 3: Write Hello and World in two separate lines using endl command
Page | 8
Program 4: Adding tab between Hello and World
Lab Task:
Task 1:
Hello World
Hello World
Hello World
______________________________________________________________________________
Page | 9
______________________________________________________________________________
Task 2:
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page | 10
Lab Session 02
Objective:
Hardware used:
Software used:
DEV C++
Theory:
Fundamental to any computer program is the data associated with its use. Based on the nature of
data it can be classified into various categories. Data types are important to understand, they
Page | 11
define proper use of an identifier and expression. In C++ data types can be categorized as
following:
1. Primitive Type:
void: Represents the absence of type. It is often used as the return type for functions that do not
return a value.
2. Derived Type:
Page | 12
There are some rules with variable naming.
Following rules must be taken care while assigning a name to any variable:
Arithmetic Operators:
Used for mathematical operations. There are two types of arithmetic operators:
Unary Operator: Operator that operates or works with a single operand are unary operators. For
example (++, --).
Page | 13
Binary Operator: Operators that operates or works with two operands are binary operators. For
example: (+, -, *, /, %). Suppose my roll number is two and binary operators that can be
performed on my roll number are:
Procedure:
Program 1: Write the basic C++ Programs for initializing and declaring the
integer, Boolean and character datatypes-based variables.
Page | 14
Program 2: Write a C++ that can be used to check the memory requirements
of various data types
Page | 15
Program 4: Make a program on the use of binary operators.
Page | 16
Program 7: Find the hypotenuse of the triangle.
Lab Tasks:
Page | 17
Task 1: Find the area of the tringle and take the height and base from user.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Task 2: Find the circumference of the circle. Take the radius from user
according to your roll number.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Task 3: Find the Area of circle. Take the radius from user according to your
roll number.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
Page | 18
______________________________________________________________________________
______________________________________________________________________________
Lab Session 03
Objective:
In this lab session, we shall cover the Operators used in Decision making:
Relation Operator
Logical Operator
Hardware used:
Page | 19
Software used:
DEV C++
Theory:
The idea of decision making allows to control the flow of the program. So far, every program
that we have discussed was executed from start to end. Often it is required to control the flow of
a program so that a certain piece of code is only executed if a certain condition is met. Decision
making in programming is done in terms of testing an expression (logical or relational).
Arithmetic operators are incapable of generating TRUE or FALSE. For this we need operators
that can result in YES and NO. In other words, operators that can produce Boolean output. There
are two such operators in C++.
1. Relation Operator
2. Logical Operator
1. Relational Operator:
Used for the comparison of the values of two operands.
For example, checking for equality of operands, whether an operand is greater than the other
operand or not etc.
== Equal to 5 == 5 is TRUE
Page | 20
!= Not equal to 5! = 4 is TRUE
2. Logical Operator:
Used to combine two or more conditions/constraints.
Result of the operation of a logical operator is a Boolean value either true or false.
A B A&&B A||B
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
A A!
0 1
1 0
Procedure:
Page | 21
Program 2: Write a C++ program to verify the use of logical operator
Program 3: Write a C++ program to combine the use of relational and logical
operator
Page | 22
Lab Task:
Consider two students who got marks in their midterm exam of Programing Fundamentals.
Check how their marks relatable to each other’s. Write a C++ program to:
Check if the first student marks are equal to the second student.
Check if the first student marks are not equal to the second student.
Check if the first student marks are greater than the second student.
Check if the first student marks are less than the second student.
Check if the first student marks are greater than or equal to the second number.
Check if the first student marks are less than or equal to the second number.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
Page | 23
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page | 24