0% found this document useful (0 votes)
47 views24 pages

Lab Manual Programming Fundamentals: Submitted To: XYZ Submitted By: XYZ Section: A/B Roll Number: 123

The document provides information about three lab sessions on programming fundamentals in C++. The first lab session covers installing Dev C++, printing "Hello World", comments, escape sequences, and taking user input. The second lab session covers basic data types in C++, declaring and using variables, arithmetic operators, and power functions. The third lab session objective and tasks are not described.

Uploaded by

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

Lab Manual Programming Fundamentals: Submitted To: XYZ Submitted By: XYZ Section: A/B Roll Number: 123

The document provides information about three lab sessions on programming fundamentals in C++. The first lab session covers installing Dev C++, printing "Hello World", comments, escape sequences, and taking user input. The second lab session covers basic data types in C++, declaring and using variables, arithmetic operators, and power functions. The third lab session objective and tasks are not described.

Uploaded by

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

Lab Manual

Programming Fundamentals

Submitted to:

XYZ

Submitted by:

XYZ

Section:

A/B

Roll Number:

123

Department of Computer Science

MNS University of Engineering and Technology, Multan


Table of Contents

Lab Session 01.................................................................................................................................2

Lab Session 02...............................................................................................................................10

Lab Session 03...............................................................................................................................19

Page | 2
Lab Session 01
Objective:

Getting Started – Familiarization with Environment

In this lab session, we shall cover the following objectives:

 Installation of DEV C++


 Syntax of C++
 Printing the Hello World on screen
 Comments in C++
 Use of Escape Sequences
 Taking inputs from user

Hardware used:

Intel(R) Core (TM) i5-5200U CPU @ 2.20GHz

Software used:

DEV C++

Theory:

What is C++:

C++ is a powerful, high-performance programming language that combines procedural, object-


oriented, and low-level features. It supports efficient memory manipulation, object-oriented
programming, and generic programming through its Standard Template Library (STL). C++ is
widely used in software development, game development, system software, and embedded
systems due to its speed, versatility, and efficiency.

Installation of DEV 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 5: return 0 ends the main function.

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

User Input and output

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++.

Sequence Purpose Purpose


\n Next line
\r Carriage return
\t Horizontal tab
\b Backspace
\a Alert (beep)
\\ Print \
\’ Print’
\” Print “

Procedure:

Program 1: Printing the Hello World on screen

Step 1: Launch Dev-C++

 Firstly, open the Dev-C++ from the desktop or start up menu.

Step 2: Create a New Source File

 Click on "File" in the menu bar.

Page | 6
 Select "New" and then click on "Source File...". A new editor window will open.

Step 3: Write the Hello World Program

Then I Type the following C++ code into the editor window:

#include <iostream>

int main() {

std::cout << "Hello, World!" << std::endl;

return 0;

Step 4: Save the File

 Then I click on "File" in the menu bar.


 Select "Save As...".
 Choose a location on computer to save the file.

Step 5: Compile and Run the Program

 Then I click on "Execute" in the menu bar.


 Select "Compile & Run" from the dropdown menu.
 Dev-C++ will compile your program and execute it.
 Output "Hello, World!" printed on the Dev-C++ window.

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

Program 5: Taking Inputs from user:

Lab Task:

Task 1:

Write a program to print text in following pattern,

Hello World

Hello World

Hello World
______________________________________________________________________________

Page | 9
______________________________________________________________________________

Task 2:

How to add multiline comments in C++ code.

______________________________________________________________________________

______________________________________________________________________________

Conclusion:

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

Page | 10
Lab Session 02
Objective:

C++ Building Blocks

In this lab session, we shall cover the following objectives:

 Basic data types in C++


 Declaring and using variables
 Arithmetic Operators
 Use of Power Functions

Hardware used:

Intel(R) Core (TM) i5-5200U CPU @ 2.20GHz

Software used:

DEV C++

Theory:

Basic Data Types in C++:

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:

Integer: Represents integer values. Typically, 4 bytes.

Boolean: Represents Boolean values. Usually 1 byte (true or false).

float: Represents single-precision floating-point numbers.

double: Represents double-precision floating-point numbers.

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:

Arrays: Represents a collection of elements of the same data type.

Declaring and using Variables:

 Variables are named objects with a specific type.


 Variables can be used to store data of a certain type which can later be used, processed
and/or updated in the program.
 A variable must be declared using appropriate keyword.

Page | 12
 There are some rules with variable naming.

Type Keyword Memory


Boolean bool 1 Byte
Character char 1 Byte
Integer int 4 Bytes
Floating Point float 4 Bytes
Double Floating Point double 8 Bytes

Variable Naming Rules:

Following rules must be taken care while assigning a name to any variable:

 Variable name must start with a letter or _ (underscore).


 May contains letter, numbers and the underscore character only.
 Uppercase and lower case are distinct.

 Name should not be a reserved keyword.

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 (++, --).

Operator Symbol Operation


Prefix increment (pre-increment) ++a Increment a, then evaluate a
Prefix decrement (pre-decrement) --a Decrement a, then evaluate a
Postfix increment (post-increment) a++ Evaluate a, then increment a
Postfix decrement (post-decrement) a-- Evaluate a, then decrement a

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:

Number 1 Number 2 Operation Result


2 2 + 4
2 2 - 0
2 2 * 4
2 2 / 1
2 2 % 0

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

Program 3: Make a program on the use of Unary operator.

Page | 15
Program 4: Make a program on the use of binary operators.

Program 5: Find the Square root of any number in C++.

Program 6: Find the square of any number in C++.

Page | 16
Program 7: Find the hypotenuse of the triangle.

Program 8: Print the table of any number.

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:

C++ Decision Making Operators

In this lab session, we shall cover the Operators used in Decision making:

 Relation Operator
 Logical Operator

Hardware used:

Intel(R) Core (TM) i5-5200U CPU @ 2.20GHz

Page | 19
Software used:

DEV C++

Theory:

General Idea of Decision Making in the Programming:

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).

Operators used in Decision Making:

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.

Operator Decision Example


> Greater than 5 > 4 is TRUE

< Less than 4 < 5 is TRUE

>= Greater than or equal 4 >= 4 is TRUE

<= Less than or equal 3 <= 4 is TRUE

== 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.

Operator C++ Symbol


AND &&
OR ||
NOT !

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:

Program 1: Write a C++ Program to verify the use of relational operator

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

You might also like