CPP Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 73

Mahatma Gandhi Mission’s

College of Engineering and Technology


(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

LABORATORY MANUAL

COURSE: Computer programming Paradigms Lab


COURSE CODE: ITL303

Semester-III

INDEX

Sr. No. Topic Page No.

1 Program Educational Objectives (PEOs) iv

2 Program Outcomes (POs) v

3 Program Specific Outcomes (PSOs) vi

4 Syllabus vii

5 Course Objectives and Course Outcomes ix

6 List of Experiments x

7 CO-PO Mapping Matrix and CO-PSO Mapping Matrix xii


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Program Educational Objectives (PEOs)

The following are the envisaged as Educational Objectives of IT Engineering Program:

1. To embed a strong foundation of Information Technology Engineering fundamentals to


identify, solve, analyze & design real time Engineering problems as a professional or an
entrepreneur for the lifelong learning & research benefit of society.
2. To motivate & prepare students for lifelong learning & research to manifest global
competitiveness.
3. To equip students with communication, teamwork & leadership skills to accept challenges
in all facets of life ethically.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Program Outcomes (POs)


At the end of the course Students will be able to:

1. Apply the knowledge of Mathematics, Science, Engineering fundamentals to solve


complex Information Technology Engineering Problems.
2. Identify, formulate and analyze Information Technology Engineering problems to derive
conclusions using first principles of mathematics and Computer Science.
3. Investigate complex Information Technology engineering problems and find appropriate
solutions leading to valid conclusions.
4. Design IT systems, components or processes to meet specified needs with appropriate
attention to health, safety, standards, environmental and societal consideration.
5. To create, select & apply appropriate techniques, resources advance engineering &
software tools necessary to analyze & design Information Technology Problems.
6. Understand the impact of IT Solutions on society and environment for sustainable
development.
7. Understand social, safety, culture and legal issues and responsibilities relevant to the
engineering profession.
8. Apply professional ethics, accountability and equity in the engineering profession.
9. Work effectively as a member and leader in multidisciplinary team for a common goal.
10. Communicate effectively within a profession and with society at large.
11. Appropriately incorporate principles of Management & Finance to one’s own work.
12. To identify Educational needs & engage in lifelong learning in a changing world of
technology.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Program Specific Outcomes (PSOs)

1. Identify, understand, formulate and analyze complex engineering problems in the field of
Network system, Database management, Web communication, Computer programming
and software development.

2. Plan, design, develop and manage software in the field of artificial intelligence , data
mining, network management and security, cloud based services and Internet of Things
applications through use of secure, reliable and cost effective state of art IT tools
efficiently.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

University Syllabus for ITL303 Computer programming


Paradigms Lab
Module Detailed Contents Hours

I.Imperative At least two Programming Implementations Preferably in 5


Paradigm: Data C++ to demonstrate concepts like - Encapsulation,
Abstraction in Object Inheritance, Initialization and Finalization, Dynamic
Orientation Binding.
II.Declarative Installation and starting Haskell compiler.  Try the simple 6
Programming exercise on operators, types etc.  Consider a function
Paradigm: Functional safetail that behaves in the same way as tail, except that
Programming safetail maps the empty list to the empty list, whereas tail
gives an error in this case. Define safetail using: (a) a
conditional expression; (b) guarded equations; (c) pattern
matching. Hint: the library function null :: [a]-> Bool can be
used to test if a list is empty.  Simple List Comprehension
 Recursion Function  Higher-Order Functions  Using
recursion and the function add, define a function that
multiplies two natural numbers.  Implement the game of
nim in Haskell, where the rules of the game are as follows:
The board comprises five rows of stars: 1:***** 2:****
3:*** 4:** 5:* Two players take it turn about to remove
one or more stars from the end of a single row. The
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

winner is the player who removes the last star or stars


from the board. Hint: Represent the board as a list of five
integers that give the number of stars remaining on each
row. For example, the initial board is [5,4,3,2,1].
21, 34, …starts with 0 and 1, with each further number
being the sum of the previous two. Using a list
comprehension, define an expression fibs :: [Integer] that
generates this infinite sequence. Students should
implement tic-tac-toe or simple calculator to clearly
understand the syntax and the execution of the Functional
Implementation using Haskell language.
III.Declarative Tutorial Introduction to SWI Prolog  Implement at least 5
Programming five Prolog programs to understand declarative
Paradigm: Logic programming concepts. Students should clearly
Programming understand the syntax and the execution of the Prolog
code Implementation.
IV.Alternative At least two Programs preferably in c++ and java to 2
Paradigms: demonstrate Thread management and synchronization
Concurrency
V.Run Time Program A Program to understand Exception handling and Garbage 2
Managemen collection, preferably in C++ and JAVA Students should
underline the syntactic differences in the solutions in both
Object Oriented Languages.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

VI.Programming At Least two implementations each implemented on 4


Assignment For multiple paradigms like procedural, object oriented,
comparative study of functional, logic. The implementations should be done in a
Different Paradigms group of two/three students with appropriate difficulty
level. Student should present the solution code and
demonstrate execution for alternative solutions they
build.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Course Objectives

1. understand and apply different loops in c++

2. Apply knowledge of Object Oriented concepts in C++ program

3. Understand the multithreaded programs in Java and C++ and implement solution for
concurrency as solution

4. Apply knowledge use of exception handling and garbage collection in C++ and JAVA

5. Design solution based on declarative programming paradigm using functional and


logic programming using Haskell.
6. Compare the implementations in multiple paradigms at coding and execution level
teams
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Course Outcomes
After completing this course, the learners should be able to:

1. understand and apply different loops in C++

2. Apply knowledge of Object Oriented concepts in C++ program

3. Understand the multithreaded programs in Java and C++ and implement solution for
concurrency as solution

4. Apply knowledge use of exception handling and garbage collection in C++ and JAVA

5. Design solution based on declarative programming paradigm using functional and


logic programming using Haskell.
6. Compare the implementations in multiple paradigms at coding and execution level
teams
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

LIST OF EXPERIMENT'S
Expt. Page No. COs
Name of the Experiment
No.
1. Implementation of basic data types in C++ 1 CO1
• Write a program to find swapping without using
third variable using C++
• Write a program to find sum and avg of three
numbers using C++

2. Implementation of loops in C++ 7 CO1


• Write a program to find fibonacci series using
for loop
• Write a program to find even or odd number
using if else (Virtual Lab Experiment)

3. Implementation of loops in C++ 13 CO1


• Write a program to perform arithmetic
operation using switchcase
• Write a program to print 1 to 5 number
using while loop
4. program for arithmetic operation using function overloading 18 CO1
in C++
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

5. A) Write a program to concatenate list and store in another 21 CO5


list in prolog.
B) Write a program to calculate length of list
6. 27 CO1, CO2
Implementation of Call by value and call by reference in C++

7. write a program to perform arithmetic operator in 30 CO5


prolog

8. Write a program to read and display employee details 33 CO2


using class and objects.

9. Implementation of constructor in C++ 37 CO2,CO1


a. Implementation of default constructor to display

values in C++
b. Implementation of parameterized constructor to

display student info(rollnum,name,marks) in C++


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

10. Implementation of program in Haskell 42 CO5


(1) Write a program to read input from user.
(2) Write a program to find addition, subtraction,
multiplication, division of numbers in Haskell.
(3) Write a program to display series of number 1 to 10.

11. Case study on Python programming paradigms(Beyond 48 CO1

syllabus)
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CO-PO Co-relation Matrix

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

CO1 2 1 1 1 1 1 1

CO2 2 1 1 1 1 1 1

CO3 2 1 1 1 1 1 1

CO4 2 1 1 1 1 1 1

CO5 2 1 1 1 1 1

CO6 2 1 1 1 1 1 1

CO-PSO Co-relation Matrix

PSO1 PSO2

CO1 2 1

CO2 2 1

CO3 2 1

CO4 2 1

CO5 2 1

CO6 2 1
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 1

AIM: Implementation of basic data types in C++


• write a program to find swapping without using third variable using C++
• write a program to find sum and average of three numbers using C++

RESOURCES REQUIRED:: Turbo C++, Pentium IV, Printer


THEORY: The basic data types are integer-based and floating-point based. C++ language
supports both signed and unsigned literals.

The memory size of basic data types may change according to 32 or 64 bit operating
system.
All variables use data-type during declaration to restrict the type of data to be
stored. Therefore, we can say that data types are used to tell the variables the type of data
it can store. Whenever a variable is defined in C++, the compiler allocates some memory
for that variable based on the data-type with which it is declared. Every data type requires
a different amount of memory.
Data types in C++ are mainly divided into three types:
Primitive Data Types: These data types are built-in or predefined data types and can be
used directly by the user to declare variables.
example: int, char , float, bool etc. Primitive data types available
in C++ are:
• Integer
• Character
• Boolean
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

• Floating Point
• Double Floating Point
• Valueless or Void
• Wide Character
Derived Data Types: The data-types that are derived from the primitive or built-in
datatypes are referred to as Derived Data Types. These can be of four types namely:
• Function
• Array
• Pointer
• Reference

Abstract or User-Defined data types: These data types are defined by user itself. Like,
defining a class in C++ or a structure. C++ provides the following user-defined datatypes:

• Class
• Structure
• Union
• Enumeration
• Typedef defined Datatype
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Datatype Modifiers
As the name implies, datatype modifiers are used with the built-in data types to modify the
length of data that a particular data type can hold.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

PROGRAM CODE-
1.Write a program to find swapping without using third variable using C++
#include <iostream>
using namespace std;
int main()
{
int a=5, b=10;
cout<<"Before swap a = "<<a<<" b =
"<<b<<endl; a=a+b; b=a-b; a=a-
b;
cout<<"After swap a = "<<a<<" b = "<<b<<endl;
return 0;
}

OUTPUT-

PROGRAM CODE-
2.Write a program to find sum and average of two numbers using C++
#include <iostream>
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

using namespace std;


int main() {
int x,y,sum;
float aveg; x
= 10;
y = 20; sum
= x+y;
aveg = sum/2;
cout<<"Sum of Two Numbers : "<< sum;
cout<<"\nAverage of Two Numbers : "<<
aveg; return 0;
}

OUTPUT :
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION:
Successfully Implemented Basic data types in C++ and implements a Two program. one is
swap a two values without using Third variable. second one is find a sum and average of
two numbers.

MCQS/ VIVA QUESTIONS :

1. What are the different data types present in C++?

2. What are the advantages of C++?

3. What is correct syntax of if-else loop?

4. What is size of void in C++?

5. What is size of integer:


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

REFERENCES :
1. https://www.programiz.com/cpp-programming/examples/swapping
2. https://www.youtube.com/watch?v=HrAbV_MyWXM
3. https://www.youtube.com/watch?v=9dMJOTT9TYc
4. https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 2

AIM: Implementation of loops in C++


• write a program to find Fibonacci series using for loop
• write a program to find even or odd number using if else

RESOURCES REQUIRED: Turbo C++, Pentium IV, Printer


THEORY:

In C++ programming, if statement is used to test the condition. There are various types of
if statements in C++.
• if statement
• if-else statement
• nested if statement
• if-else-if ladder

The C++ if statement tests the condition. It is executed if condition is true.


if(condition){

//code to be executed
}
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

C++ For Loop


The C++ for loop is used to iterate a part of the program several times. If the number of
iteration is fixed, it is recommended to use for loop than while or do-while loops.
The C++ for loop is same as C/C#. We can initialize variable, check condition and
increment/decrement value.
for(initialization; condition; incr/decr){
//code to be executed
}
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

PROGRAM CODE-
1.To find fibonacci series using for loop.

#include <iostream> using


namespace std;
int main()
{
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

int n, t1 = 0, t2 = 1, nextTerm
=;
cout <<"\nEnter the number of terms: ";
cin >> n;
cout <<"Fibonacci Series: ";
for (int i = 1; i <= n; ++i)
{
if(i == 1)
{
cout << t1 <<", ";
continue;

}
if(i == 2)
{
cout << t2 <<",
";
continue;
}
nextTerm = t1+ t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm <<", ";
} return 0;
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

OUTPUT

PROGRAM CODE-
2.To find even or odd number using if else

#include <iostream>
using namespace std;
int
main()
{
int n;
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

cout <<"Enter an integer: ";


cin >> n;
if ( n % 2 == 0)
cout << n <<" is even.";
else
cout << n <<" is odd.";
return 0;
}

OUTPUT
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION :
Successfully Implemented Loops in C++ and implements a Two program one is fibonacci
series using for loop. second one is find even or odd number using if else.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

MCQS/ VIVA QUESTIONS :

1. Difference between equal to (==) and assignment operator(=)?

2. When is void() return type used?

3. correct extension of the user-defined header file in C++

4. What is is “address of operator”?

5. What is the correct default return value of function.

REFERENCES :
1. https://www.javatpoint.com/cpp-for-loop
2. https://www.javatpoint.com/cpp-while-loop
3. https://www.w3schools.com/cpp/cpp_for_loop.asp
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 3

AIM: Implementation of loops in C++


• Write a Program to perform arithmetic operation using switch case
• Write a Program to print 1 to 5 number using while loop

RESOURCES REQUIRED: Turbo C++ , Pentium IV, Printer


THEORY: The C++ switch statement executes one statement from multiple conditions. It is like
if else-if ladder statement in C++.

The expression is evaluated once and compared with the values of each case label.
• If there is a match, the corresponding code after the matching label is executed.
For example, if the value of the variable is equal to constant2, the code after
case constant2: is executed until the break statementis encountered. If
there is no match, the code after default: is executed. switch(expression){
case value1:
//code to be executed;
break;
case
value2:
//code to be executed;
break;
......
default:
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

//code to be executed if all cases are not matched;


break;
}
In C++, while loop is used to iterate a part of the program several times. If the number of
iteration is not fixed, it is recommended to use while loop than for loop. The while loop in
C/C++ is used in situations where we do not know the exact number of iterations of loop
beforehand. The loop execution is terminated on the basis of the test condition. ... If the
condition evaluates to true then we will execute the body of the loop and go to update
expression.
while(condition){
//code to be executed
}

PROGRAM CODE-
1. Write a program to perform arithmetic operation using switch case
#include <iostream>
using namespace std;
int main()
{
int a,b,result;
cout<<"* Enter two values whose sum is 10 or 50 or 100 *";
cout<<"\n\nEnter a value for A = ";
cin >> a;
cout<<"Enter a value for B = ";
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

cin >> b;
result = a+b;
switch(result){ case 10 :
cout<<"The value of A + B is : "<<result; break;
case 50 :
cout<<"The value of A + B is : "<<result; break;
case 100 :
cout<<"The value of A + B is : "<<result; break;
default :
cout <<"The Given Choice is not Match"; break;
} return
0; }

OUTPUT
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

PROGRAM CODE-
2. Write a program to print 1 to 5 number using while loop

#include
<iostream> using
namespace std;
int main() {
cout<<"\nThe value is 1 to 5 :\n";
int i = 1;
while( i <= 5){
cout<<"\t"<<i<<"\n";
++i; } return 0;
}

OUTPUT
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION :
Successfully Implemented Loops in C++ and implements a Two program one is to
perform arithmetic operation using switch case. and second one is to print 1 to 5
number using while loop.

MCQS/ VIVA QUESTIONS :


1. How many loops are there in C
2. which is mandatory in a function
3. The constants in C++ are also known as?
4. What is types is the language C++?
5. What is the ASCII value of ‘\0’ character?
REFERENCES :
1.https://www.youtube.com/watch?v=_CelY_ZBXb4
2.https://www.youtube.com/watch?v=uvODOG3_hQk
3. https://www.geeksforgeeks.org/switch-statement-cc/
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 4

AIM: Write a program for arithmetic operation using function overloading in C++
RESOURCES REQUIRED: Turbo C++, Pentium IV, Printer
THEORY: Types of overloading in C++ are:

• Function overloading
• Operator overloading
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

C++ Function Overloading


Function Overloading is defined as the process of having two or more function with the
same name, but different in parameters is known as function overloading in C++. In
function overloading, the function is redefined by using either different types of arguments
or a different number of arguments. It is only through these differences compiler can
differentiate between the functions.
Function overloading is a feature of object oriented programming where two or more
functions can have the same name but different parameters.
When a function name is overloaded with different jobs it is called Function Overloading.
In Function Overloading “Function” name should be the same and the arguments should
be different. Function overloading is a feature of object oriented programming where two
or more functions can have the same name but different parameters.
When a function name is overloaded with different jobs it is called Function Overloading.
In Function Overloading “Function” name should be the same and the arguments should
be different.

PROGRAM CODE-
#include <iostream>
using namespace std;
class Cal { public:
static int add(int a,int b)
{
return a + b;
}
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

static int multi(int a, int b, int c)


{
return a * b * c;
}
static int divi(int a, int b)
{
return a / b;
} }; int
main(void) {
Cal C; // class object declaration.
cout<<"\nAddition : "<<C.add(10, 20)<<endl; cout<<"Multiplication
: "<<C.multi(12, 20 , 23 )<<endl;
cout<<"Division : "<<C.divi(60, 20)<<endl;

return 0;

OUTPUT :-
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION : -Successfully Write a program for arithmetic operation using function


overloading in C++.

MCQS/ VIVA QUESTIONS :

1.Why is function overloading in C++ is used?

2.what are two types of function overloading in c++

3.loop which is guaranteed to execute

4.Total types of errors in C++?

5.Data members and member functions of a class are private by.default. True or False?

REFERENCES :

1. https://www.programiz.com/cpp-programming/function-overloading

2. https://www.javatpoint.com/cpp-overloading

3. https://www.youtube.com/watch?v=dh0mKAPFzlQ
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 5

AIM: Implementation of Call by value and call by reference in C++


RESOURCES REQUIRED: Turbo C++ , Pentium IV, Printer
THEORY:

There are two ways to pass value or data to function in C language: call by value and call by
reference. Original value is not modified in call by value but it is modified in call by
reference.

Let's understand call by value and call by reference in C++ language one by one.

Call by value in C++


In call by value, original value is not modified.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

In call by value, value being passed to the function is locally stored by the function
parameter in stack memory location. If you change the value of function parameter, it is
changed for the current function only. It will not change the value of variable inside the
caller method such as main().

Let's try to understand the concept of call by value in C++ language by the example given
below:
#include <iostream>
using namespace std;
void change(int data);
int main()
{
int data = 3;
change(data);
cout <<"Value of the data is: "<< data<< endl;
return 0;
}
void change(int data)
{
data = 5;
}

OUTPUT:
Value of the data is: 3
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Call by reference in C++


In call by reference, original value is modified because we pass reference (address).
Here, address of the value is passed in the function, so actual and formal arguments
share the same address space. Hence, value changed inside the function, is reflected
inside as well as outside the function.
#include<iostream>
using namespace std;
void swap(int *x, int *y)
{
int swap;
swap=*x;
*x=*y;
*y=swap;
}
int main()
{
int x=500, y=100;
swap(&x, &y); // passing value to function
cout<<"Value of x is: "<<x<<endl;
cout<<"Value of y is: "<<y<<endl;
return 0;
}
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

OUTPUT:
Value of x is: 100
Value of y is: 500

PROGRAM CODE-
1.Call By Value program in C++.
#include<iostream> using
namespace std; void
change(int data); int
main()
{
int data = 10;
change(data);
cout <<"\nCall By Value Program :"<<endl;
cout <<"\nValue of the data is: "<< data<< endl; return 0; }
void change(int data)
{ data
= 5;
}

OUTPUT :
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

2.Call By reference program in C++.


#include<iostrea
m> using
namespace std;
void swap(int *x,
int *y)
{
int swap;
swap=*x;
*x=*y;
*y=swap;
}
int main()
{
int x=500, y=100; swap(&x,
&y); // passing value to function
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

cout<<"Value of x is: "<<x<<endl;


cout<<"Value of y is: "<<y<<endl;
return 0;
}

OUTPUT :-

CONCLUSION: - Successfully Implemented of Call by value and call by reference in C++.


MCQS/ VIVA QUESTIONS :
1. What is the difference between call by value and call by reference C++?
2. What Are Parameters?
3. Which of the following concept is used by pre-increment?
I. call by value
II. call by reference
III. queue call by name
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

REFERENCES :

1. www.codewithharry.com › cpp-tutorials-in-hindi-16

2. https://www.scaler.com/topics/difference-between-call-by-value-and-call-by-reference/

3. https://www.javatpoint.com/call-by-value-and-call-by-reference-in-cpp
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 6

AIM:A ) write a program to concatenate a list and store in another list in prolog.
B) Write a program to calculate length of list

RESOURCES REQUIRED: PROLOG compiler , Pentium IV, Printer


THEORY

The list is a simple data structure that is widely used in non-numeric programming. List
consists of any number of items, for example, red, green, blue, white, dark. It will be
represented as, [red, green, blue, white, dark]. The list of elements will be enclosed with
square brackets. A list can be either empty or non-empty. In the first case, the list is simply
written as a Prolog atom, []. In the second case, the list consists of two things as given
below −
• The first item, called the head of the list;
• The remaining part of the list, called the tail.
Suppose we have a list like: [red, green, blue, white, dark]. Here the head is red and tail is
[green, blue, white, dark]. So the tail is another list.
Now, let us consider we have a list, L = [a, b, c]. If we write Tail = [b, c] then we can also
write the list L as L = [ a | Tail]. Here the vertical bar (|) separates the head and tail parts.
So the following list representations are also valid −
• [a, b, c] = [x | [b, c] ]
• [a, b, c] = [a, b | [c] ]
• [a, b, c] = [a, b, c | [ ] ]
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

A data structure that is either empty or consists of two parts − a head and a tail. The tail
itself has to be a list.

Length Calculation
This is used to find the length of list L. We will define one predicate to do this task. Suppose
the predicate name is list_length(L,N). This takes L and N as input argument. This will count
the elements in a list L and instantiate N to their number. As was the case with our previous
relations involving lists, it is useful to consider two cases − If list is empty, then length is
0.
• If the list is not empty, then L = [Head|Tail], then its length is 1 + length of Tail.
Concatenation
Concatenation of two lists means adding the list items of the second list after the first one.
So if two lists are [a,b,c] and [1,2], then the final list will be [a,b,c,1,2]. So to do this task we
will create one predicate called list_concat(), that will take first list L1, second list L2, and
the L3 as resultant list. There are two observations here.
• If the first list is empty, and second list is L, then the resultant list will be L.
• If the first list is not empty, then write this as [Head|Tail], concatenate Tail with L2
recursively, and store into new list in the form, [Head|New List].

CODE & OUTPUT:-


1. WRITE A PROGRAM to concatenate list and store in another list in
prolog.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

2. WRITE A PROGRAM to calculate length of list.

CONCLUSION :-
Successfully Run a Program Concatenate List and Calculate length of List.

MCQS/ VIVA QUESTIONS :


1. what are the Sector Where Prolog Programming Language Is Used?
2. Are prolog query can be made up of only two subgoals.
3. what is the use of '=' in prolog programming?
4. what is the use of 'is' in prolog programming?
5. What is a declarative language?

REFERENCES :
1. https://swish.swi-prolog.org/
2. https://www.tutorialspoint.com/execute_prolog_online.php
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

3. https://www.tutorialspoint.com/prolog/prolog_introduction.htm
4. https://www.javatpoint.com/prolog

EXPERIMENT NO- 7

AIM: write a program to perform arithmetic operator in prolog


RESOURCES REQUIRED: Prolog Compiler, Pentium IV, Printer
THEORY:

In Prolog, operators are used as predicates but here operators are functions and these
operators return a numerical value. Arithmetic expressions can include variables, numbers,
operators, and arithmetic functions. These will be written in parentheses with their
arguments. Arithmetic operators are used to perform arithmetic operations. There are few
different types of arithmetic operators as follows –

Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
// Integer Division
mod Modulus
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Comparison operators are used to compare two equations or states. Following are
different comparison operators –

Operator Meaning
X>Y X is greater than Y
X<Y X is less than Y
X >= Y X is greater than or equal to Y
X =< Y X is less than or equal to Y
X =:= Y the X and Y values are equal
X =\= Y the X and Y values are not equal

CODE & OUTPUT :-


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION:-
Successfully Run the Program to perform arithmetic Operation.

MCQS/ VIVA QUESTIONS :


1. What Are The Features Of Prolog Language?
2. What is the full form of PROLOG?
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

3. What Is List Structures In Prolog?


4. Explain Where You Use + Operator In Prolog?
5. What Is the Difference Between = And = = In Prolog?

REFERENCES:
1. https://www.tutorialspoint.com/prolog/prolog_operators.htm
2. https://www.javatpoint.com/arithmetic-in-prolog
3. http://projog.org/prolog-arithmetic.html
4. https://www.youtube.com/watch?v=AXuhIFciI0c
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 8

AIM: write a program to read and display employee details using class and objects.
RESOURCES REQUIRED: Turbo C++/Java , Pentium IV, Printer
THEORY:

C++ is an object-oriented language, program is designed using objects and classes in C++.

C++ Object
In C++, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc.
In other words, object is an entity that has state and behavior. Here, state means data and
behavior means functionality.
Object is a runtime entity, it is created at runtime.
Object is an instance of a class. All the members of the class can be accessed through
object.
Let's see an example to create object of student class using s1 as the reference variable.
Student s1; //creating an object of Student
C++, class is a group of similar objects. It is a template from which objects are created. It
can have fields, methods, constructors etc.
Let's see an example of C++ class that has three fields only.
class Student
{ public:
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

int id; //field or data member


float salary; //field or data member
String name;//field or data member
}

PROGRAME CODE-
#include <iostream>
using namespace std;
class employee
{
int emp_number;
char emp_name[20];
char emp_addr[30];
float emp_sal;
char emp_dep[30];
public:
void get_emp_details();
float find_net_salary(float basic);
void show_emp_details();
};
void employee :: get_emp_details()
{
cout<<"\n Enter employee number : ";
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

cin>>emp_number;
cout<<"\n Enter employee name : ";
cin>>emp_name;
cout<<"\n Enter employee Address : ";
cin>>emp_addr;
cout<<"\n Enter employee Salary: ";
cin>>emp_sal;
cout<<"\n Enter employee Department Name : ";
cin>>emp_dep;
}
void employee :: show_emp_details()
{
cout<<"\n\n** Details of Employee **";
cout<<"\nEmployee Name : "<<emp_name;
cout<<"\nEmployee number : "<<emp_number;
cout<<"\nBasic salary : "<<emp_sal;
cout<<"\nEmployee Department : "<<emp_dep;
cout<<"\nEmployee Address : "<<emp_addr;
cout<<"\n-------------------------------\n\n";
}
int main()
{
employee emp;
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

emp.get_emp_details();
emp.show_emp_details();
return 0;
}

OUTPUT : -

CONCLUSION-
Successfully Write a Programmed to read and display employee details using class
and objects.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

MCQS/ VIVA QUESTIONS :

1. What is the difference between struct and class in C++?


2. Why are comments used?
3. What is class
4. What is object

REFERENCES :
1. https://www.youtube.com/watch?v=wlXCFNuVjBY
2. https://www.programiz.com/cpp-programming/object-class
3. https://www.javatpoint.com/cpp-object-and-class
4. https://www.includehelp.com/cpp-programs/cpp-programs-classes-and-objects-solved-
programs.aspx
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 9

AIM: Implementation of constructor in C++


1. Implementation of default constructor to display values in C++
2. Implementation of parameterized constructor to display student
info(rollnum,name,marks) in C++

RESOURCES REQUIRED: Turbo C++ , Pentium IV, Printer


THEORY:

A constructor is a special type of member function of a class which initializes objects of a


class. In C++, Constructor is automatically called when object(instance of class) create. It
is special member function of the class because it does not have any return type.
Constructor is a special method which is invoked automatically at the time of object
creation. It is used to initialize the data members of new object generally. The constructor
in C++ has the same name as class or structure. Constructor has same name as
the class itself
• Constructors don’t have return type
• A constructor is automatically called when an object is created.
• It must be placed in public section of class.
• If we do not specify a constructor, C++ compiler generates a default constructor for
object (expects no parameters and has an empty body).
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

1. Default Constructors:Default constructor is the constructor which doesn’t take any

argument. It has no parameters.

2. Parameterized Constructors: It is possible to pass arguments to constructors.

Typically, these arguments help initialize an object when it is created. To create a


parameterized constructor, simply add parameters to it the way you would to any other
function. When you define the constructor’s body, use the parameters to initialize the
object.
PROGRAM CODE :
#include <iostream>
using namespace std;
class construct
{
public:
int a, b,res,x,y,res1;
construct()
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

{
a = 15;
b = 25;
res = a+b;
x = 10;
y = 20;
res1 = x*y;
}
};
int main()
{ construct c;
cout <<"\n* Default Constructor *"<<endl;
cout <<"a: "<< c.a << endl
<<"b: "<< c.b <<endl
<<"Addition : "<< c.res;

cout <<"\n\nx = "<< c.x <<endl


<<"y = "<< c.y <<endl
<<"Multiplication : "<< c.res1;
return 1;
}
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

OUTPUT:

PROGRAM CODE :

#include <iostream>

using namespace std;


class Professor { public: int id; string name; float salary;
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Professor (int i, string n, float s){ id = i; name = n; salary = s; }

void display (){ cout<<"Roll Number : "<<id<<", Name : "<<name<<", Marks : "<<salary<<endl; }
};
int main(void) {
cout<<"\n*: Student Details :*"<<endl<<endl;
Professor p1=Professor(101, "Sammer Ansari ", 90);
Professor p2=Professor(102, "Rohon Moriya ", 88);

Professor p3=Professor(103, "Irbazz Shaikh ", 80);


Professor p4=Professor(104, "Manish Patel ", 70);
p1.display();p2.display();p3.display();p4.display();
return 0;
}

OUTPUT :
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION : Successfully Implementation of constructor in C++.

MCQS/ VIVA QUESTIONS :


1. What is the ASCII value of ‘\0’ character?
2. What are types of constructors in C++ are?
3. What is the number of parameters that a default constructor requires?
4. What is destructor?
5. What is the role of a constructor in classes?
REFERENCES:
1. www.codewithharry.com › cpp-tutorials
2. https://www.geeksforgeeks.org/constructors-c/

3. https://www.javatpoint.com/cpp-constructor
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 10

AIM: Implementation of program in Haskell


(1) Write a program to read input from user.

(2) Write a program to find addition, subtraction, multiplication, division of numbers in Haskell.
(3) Write a program to display series of number 1 to 10.

RESOURCES REQUIRED: Haskell Compiler, Pentium IV, Printer


THEORY:
Haskell is a purely functional programming language. Inimperative languages you get things done
by giving the computer a sequence of tasks and then it executes them. While executing them, it
can change state. For instance, you set variable a to 5 and then do some stuff and
then set it to something else. You have control flowstructures for doing some action several
times. In purely functional programming you don’t tell the computer what to do as such but
rather you tell it what stuff is. The factorial of a number is the product of all the numbers from 1
to that
number, the sum of a list of numbers is the first number plus the sum of all the other numbers,
and so on. You express that in the form of functions. You also can’t set a variable tosomething
and then set it to something else later. If you say that a is 5, you can’t say it’s something else later
because you just said it was 5. What are you, some kind of liar? So in purely functional languages,
a function has no side-effects. The only thing a function can do is calculate something and return
it as a result. At first, this seems kind of limiting but itactually has some very nice consequences:
if a function is called twice with the same parameters, it’s guaranteed toreturn the same result.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

That’s called referential transparency and not only does it allow the compiler to reason about
theprogram’s behavior , but it also allows you to easily deduce (and even prove) that a function
is correct and then build more complex functions by gluing simple functions together.
Haskell is lazy. That means that unless specifically told otherwise, Haskell won’t execute functions
and calculate things until it’s really forced to show you a result. That goes well with referential
transparency and it allows you to think of programs as a series of transformations on data. It also
allows cool things such as infinite data structures. Say you
have an immutable list of numbers xs = [1,2,3,4,5,6,7,8] and a function doubleMe which
multiplies every element by 2 andthen returns a new list. If we wanted to multiply our list by 8 in
an imperative language and did doubleMe(doubleMe(doubleMe(xs))), it would probably pass
through the list once and make a copy and then return it. Then it would pass through the list
another two times and return the result. In a lazy language, calling doubleMe on a list without
forcing it to show you the result ends up in the program sort of telling you “Yeah yeah, I’ll do it
later!”. But once you want to see the result, the first doubleMe tells the second one it wants the
result, now! The second one saysthat to the third one and the third one reluctantly gives back a
doubled 1, which is a 2. The second one receives that andgives back 4 to the first one. The first
one sees that and tells you the first element is 8. So it only does one pass throughthe list and only
when you really need it. That way when you
want something from a lazy language you can just take some initial data and efficiently transform
and mend it so it resembles what you want at the end.
Haskell is statically typed. When you compile your program, the compiler knows which piece of
code is a number, which is a string andso on. That means that a lot of possible errors are caught
at compile time. If you try to add together a number and a string, the compiler will whine at you.
Haskell uses a very good type system that has type inference. That means that you don’t have to
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

explicitly label every piece of code with a type because the type system can intelligently figure
out a lot about it. If you say a = 5 + 4, you don’t have to tell Haskell that a is a number, it can
figure that out by itself. Type inference also allows your code to be more general. If a function
you make takes two parameters and adds them together and you don’t explicitly state their type,
the function will work on any two parameters that act like
numbers.
Haskell is elegant and concise. Because it uses a lot of high level concepts, Haskell programs are
usually Lshorter than their imperative equivalents. And shorter programs are easier to maintain
than longer ones and have less bugs.
Haskell was made by some really smart guys (with PhDs). Work on Haskell began in 1987 when a
committee of researchers got together to design a kick-asslanguage. In 2003 the Haskell Report
was published, which defines a stable version of the language.

PROGRAM : TO READ INPUT FROM USER


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

PROGRAM :ADDITION ,SUBTRACTION, MULTIPLICATION ,DIVISION OF NUMBERS IN HASKELL

PROGRAM : DISPLAY SERIES OF NUMBER 1 TO 10


Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

CONCLUSION : Programs run successfully in Haskell

MCQS/ VIVA QUESTIONS :


1. what are the benefits of Haskell
2. What do you understand by the type system for Haskell?
3. What is a in Haskell?
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

4. What is tail in Haskell?


5. How does ++ work in Haskell?

REFERENCES :
1. https://www.haskell.org/
2. https://www.tutorialspoint.com/haskell/index.htm
3. https://www.youtube.com/watch?v=Qa8IfEeBJqk
4. https://www.geeksforgeeks.org/what-is-haskell-programming-language/
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

EXPERIMENT NO- 11

AIM: Case study on Python programming paradigms


RESOURCES REQUIRED: Printer, internet

THEORY: Python supports imperative, functional, procedural, and object-oriented


programming; here are tips on choosing the right one for a specific use case.

Python supports three types of Programming paradigms


● Object Oriented programming paradigms
● Procedure Oriented programming paradigms
● Functional programming paradigms
● Python is an interpreted, dynamically-typed, object-oriented scripting language with a
host of built-in data types. See Programming Language Exploration for an overview of the
language. It is implemented in C, but in a very object-oriented fashion. The design is a
good model for language implementation.

● The Python interpreter works by loading a source file or reading a line typed at the
keyboard, parsing it into an abstract syntax tree, compiling the tree into bytecode, and
executing the bytecode. We will concentrate mainly on how the bytecode is executed,
such as how inheritance and environments are implemented.
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

Figure : Python programming paradigms

CONCLUSION: Studied Python programming paradigms

MCQS/ VIVA QUESTIONS :

1. What are the 3 types of programming in Python?

2. How is a code block indicated in Python?

3. What is the maximum length of a Python identifier?

4. Is Python case sensitive when dealing with identifiers?

5. Is Python code compiled or interpreted?

REFERENCES :
Mahatma Gandhi Mission’s
College of Engineering and Technology
(Affiliated to University of Mumbai and Approved by, AICTE, New Delhi.)
Plot No. 1, 2, Sion - Panvel Expressway, Sector 18, Kamothe, Navi Mumbai,
Maharashtra 410209 Website : www.mgmmumbai.ac.in

Department of Information Technology

1. https://www.ijcaonline.org/archives/volume177/number31/thaker-2020-ijca-
919775.pdf
2 https://www.geeksforgeeks.org/programming-paradigms-in-python/

3. https://opensource.com/article/19/10/python-programming-paradigms

4. https://www.educative.io/courses/learn-functional-programming-in-python/N732Z6APX46

You might also like