SlideShare a Scribd company logo
19CS3056S Functional and Concurrent Programming
6
LAB SESSION 01: Introduction to Scala
Date of the Session: _ / / Time of the Session: _ to
Prerequisite:
• Basics of Scala – data types
• Statements and expressions
• Declarations
Pre-Lab:
Answer the following questions:
1. As we stepped into a new programming language, first of all we need to know how
functional programming is differ from object oriented programming language.so draft
some differences
A:
functional programming:-
* This programming paradigm emphasizes on the use of functions where each function
performs a specific task.
* Importance is not given to data but to functions.
* It uses recursion for iteration.
object oriented programming:-
* This programming paradigm is based on object oriented concept. Classes are used
where instance of objects are created
*
Importance is given to data rather than procedures.
* The statements in this programming paradigm need to follow a order i.e., bottom up
approach while execution.
2. Below is a programwhich illustrates thedata types. Executethecode and understand the output.
19CS3056S Functional and Concurrent Programming
7
// Scala programto illustrate Data types object Test
{
def main(args: Array[String])
{
var a: Boolean = true var
a1: Byte = 126
var a2: Float = 2.45673f
var a3: Int = 3
19CS3056S Functional and Concurrent Programming
8
var a4: Short = 45
var a5: Double = 2.93846523
var a6: Char = 'A'
if (a == true)
{
println("boolean: welcome to functional programming!!")
}
println("byte:" + a1)
println("float:" + a2)
println("integer:" +
a3) println("short:" +
a4) println("double:"
+ a5) println("char:"
+ a6)
}
}
A:
3. As Harry is in charge for Scala laboratory. He wants to check the basics for his students and
asked them to print the sum, difference and product of two numbers by taking input from
console.
Input format:
The first line contains n(first no) and m(second number)
Constraints:
n < 1000
m < 1000
A:
object harry {
def main(args: Array[String]) {
19CS3056S Functional and Concurrent Programming
9
var n=20;
var m=10;
println("The sum is : "+(n+m));
println("The product is : "+(n*m));
println("The difference is : "+(n-m));
}
}
19CS3056S Functional and Concurrent Programming
10
19CS3056S Functional and Concurrent Programming
11
In-Lab:
1. Grace is new to programming and she wants to learn Scala programming. You need to help her
to initialize variables of all the data types and print the values on console.
Example: An example is shown for single variable. This has to be applied for all the data types
var a3: Int = 3
println("integer:" + a3)   
A:
Code:-
object MyClass {
def main(args: Array[String])
{
var a: Boolean = true
var a1: Byte = 126
var a2: Float = 2.45673f
var a3: Int = 3
var a4: Short = 45
var a5: Double = 2.93846523
var a6: Char = 'A'
if (a == true)
{
println("boolean: welcome to functional programming!!")
}
println("byte:" + a1)
println("float:" + a2)
println("integer:" +a3)
println("short:" +a4)
println("double:"+ a5)
println("char:"+ a6)
}
}
19CS3056S Functional and Concurrent Programming
12
19CS3056S Functional and Concurrent Programming
13
2. Rohit wants to find the maximum and minimum of salaries that his firm pays which are
inputted in the form an array. Can you help him by writing a Scala program that completes
the task for him.
A:code:-
object MyClass {
val array = Array(3,4,62,8,9,2,1)
if(array.isEmpty) throw new IllegalArgumentException
val (minimum, maximum) = array.foldLeft((array.head, array.head)) {
case ((min, max), next) =>
if(next > max) (min, next)
else if(next < min) (next, max)
else (min, max)
}
println(minimum, maximum);
}
19CS3056S Functional and Concurrent Programming
14
3. Dora wants to remember week days with the help of numbers. She wants your help to make
a program that prints numbers according to week days.
Example: 0-Sunday 1-Monday 2-Tuesday so on
A:
19CS3056S Functional and Concurrent Programming
15
Post-Lab:
1. Your friend gave you a String "Vanilla Donut 10 2.25", where the literal Vanilla Donut is a
particular donut, the 10 literal is the quantity purchased, and 2.25 is the unit price of each Vanilla
Donut. You further need to cast each token from the input String to their corresponding types, such
as, an Int, Double or String. Parse the corresponding values usingScala.
A:
only)
Signature of the Evaluator Date of Evaluation:
19CS3056S Functional and Concurrent Programming
Viva – voice:
1. WhichScala libraryis used for functional programming?
A:
2. What is a ‘Scala set’?What are methods throughwhichoperationsets are
expressed?
A:
3. HowisScala aprogramming languagewitha combinationof bothfunctionaland object-
orientedprogramming?
A:
4. Explainthe functionalityof
Yield? A:
5. What is the advantageofusingScala overotherfunctional programming
languages?Define the features of ImmutableVariables?
A:
(For Evaluator’s use
Comment of the Evaluator (if Any) Evaluator’s Observation
Marks Secured: out of
Full Name of the Evaluator:

More Related Content

What's hot

Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
Megha V
 
Templates2
Templates2Templates2
Templates2
zindadili
 
Scilab - Piecewise Functions
Scilab - Piecewise FunctionsScilab - Piecewise Functions
Scilab - Piecewise Functions
Jorge Jasso
 
123
123123
123
htmrk
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
Shweta Bhatia
 
Logical vectors
Logical vectorsLogical vectors
Logical vectors
Ketan Paithankar
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
Megha V
 
Introduction to FreeMat
Introduction to FreeMatIntroduction to FreeMat
Introduction to FreeMat
Ahmad AlMowaffak
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
One97 Communications Limited
 
Java assgnmt2.
Java assgnmt2.Java assgnmt2.
Java assgnmt2.
Moses Mwebaze
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Muhammad Fayyaz
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
Megha V
 
Piecewise Functions in Matlab
Piecewise Functions in MatlabPiecewise Functions in Matlab
Piecewise Functions in Matlab
Jorge Jasso
 
Dimension reduction techniques[Feature Selection]
Dimension reduction techniques[Feature Selection]Dimension reduction techniques[Feature Selection]
Dimension reduction techniques[Feature Selection]
AAKANKSHA JAIN
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics Tutorial
Cheng-An Yang
 
14method in c#
14method in c#14method in c#
14method in c#
Sireesh K
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oop
Justin Chen
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
Michael Heron
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
Megha V
 
Lecture 3.1 to 3.2 bt
Lecture 3.1 to 3.2 btLecture 3.1 to 3.2 bt
Lecture 3.1 to 3.2 bt
btmathematics
 

What's hot (20)

Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Templates2
Templates2Templates2
Templates2
 
Scilab - Piecewise Functions
Scilab - Piecewise FunctionsScilab - Piecewise Functions
Scilab - Piecewise Functions
 
123
123123
123
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Logical vectors
Logical vectorsLogical vectors
Logical vectors
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
 
Introduction to FreeMat
Introduction to FreeMatIntroduction to FreeMat
Introduction to FreeMat
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 
Java assgnmt2.
Java assgnmt2.Java assgnmt2.
Java assgnmt2.
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
 
Piecewise Functions in Matlab
Piecewise Functions in MatlabPiecewise Functions in Matlab
Piecewise Functions in Matlab
 
Dimension reduction techniques[Feature Selection]
Dimension reduction techniques[Feature Selection]Dimension reduction techniques[Feature Selection]
Dimension reduction techniques[Feature Selection]
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics Tutorial
 
14method in c#
14method in c#14method in c#
14method in c#
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oop
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
Lecture 3.1 to 3.2 bt
Lecture 3.1 to 3.2 btLecture 3.1 to 3.2 bt
Lecture 3.1 to 3.2 bt
 

Similar to 190030341 fcp lab 1

JavaProgrammingManual
JavaProgrammingManualJavaProgrammingManual
JavaProgrammingManual
Naveen Sagayaselvaraj
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
Naveen Sagayaselvaraj
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
dunhamadell
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
Andrey Skripnikov
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
vikrammutneja1
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
vannagoforth
 
cp05.pptx
cp05.pptxcp05.pptx
cp05.pptx
RehmanRasheed3
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
Revathiparamanathan
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
Sergii Maliarov
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
Kaela Johnson
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
ArthyR3
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
reddyprasad reddyvari
 
05-stack_queue.ppt
05-stack_queue.ppt05-stack_queue.ppt
05-stack_queue.ppt
Sarojkumari55
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
Mukesh Tekwani
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
Sandip Kumar
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
Max Kleiner
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
Chandan Kumar
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learning
my6305874
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
Ratnala Charan kumar
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
auswhit
 

Similar to 190030341 fcp lab 1 (20)

JavaProgrammingManual
JavaProgrammingManualJavaProgrammingManual
JavaProgrammingManual
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
 
cp05.pptx
cp05.pptxcp05.pptx
cp05.pptx
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
05-stack_queue.ppt
05-stack_queue.ppt05-stack_queue.ppt
05-stack_queue.ppt
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learning
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 

Recently uploaded

A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 

Recently uploaded (20)

A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 

190030341 fcp lab 1

  • 1. 19CS3056S Functional and Concurrent Programming 6 LAB SESSION 01: Introduction to Scala Date of the Session: _ / / Time of the Session: _ to Prerequisite: • Basics of Scala – data types • Statements and expressions • Declarations Pre-Lab: Answer the following questions: 1. As we stepped into a new programming language, first of all we need to know how functional programming is differ from object oriented programming language.so draft some differences A: functional programming:- * This programming paradigm emphasizes on the use of functions where each function performs a specific task. * Importance is not given to data but to functions. * It uses recursion for iteration. object oriented programming:- * This programming paradigm is based on object oriented concept. Classes are used where instance of objects are created * Importance is given to data rather than procedures. * The statements in this programming paradigm need to follow a order i.e., bottom up approach while execution. 2. Below is a programwhich illustrates thedata types. Executethecode and understand the output.
  • 2. 19CS3056S Functional and Concurrent Programming 7 // Scala programto illustrate Data types object Test { def main(args: Array[String]) { var a: Boolean = true var a1: Byte = 126 var a2: Float = 2.45673f var a3: Int = 3
  • 3. 19CS3056S Functional and Concurrent Programming 8 var a4: Short = 45 var a5: Double = 2.93846523 var a6: Char = 'A' if (a == true) { println("boolean: welcome to functional programming!!") } println("byte:" + a1) println("float:" + a2) println("integer:" + a3) println("short:" + a4) println("double:" + a5) println("char:" + a6) } } A: 3. As Harry is in charge for Scala laboratory. He wants to check the basics for his students and asked them to print the sum, difference and product of two numbers by taking input from console. Input format: The first line contains n(first no) and m(second number) Constraints: n < 1000 m < 1000 A: object harry { def main(args: Array[String]) {
  • 4. 19CS3056S Functional and Concurrent Programming 9 var n=20; var m=10; println("The sum is : "+(n+m)); println("The product is : "+(n*m)); println("The difference is : "+(n-m)); } }
  • 5. 19CS3056S Functional and Concurrent Programming 10
  • 6. 19CS3056S Functional and Concurrent Programming 11 In-Lab: 1. Grace is new to programming and she wants to learn Scala programming. You need to help her to initialize variables of all the data types and print the values on console. Example: An example is shown for single variable. This has to be applied for all the data types var a3: Int = 3 println("integer:" + a3)    A: Code:- object MyClass { def main(args: Array[String]) { var a: Boolean = true var a1: Byte = 126 var a2: Float = 2.45673f var a3: Int = 3 var a4: Short = 45 var a5: Double = 2.93846523 var a6: Char = 'A' if (a == true) { println("boolean: welcome to functional programming!!") } println("byte:" + a1) println("float:" + a2) println("integer:" +a3) println("short:" +a4) println("double:"+ a5) println("char:"+ a6) } }
  • 7. 19CS3056S Functional and Concurrent Programming 12
  • 8. 19CS3056S Functional and Concurrent Programming 13 2. Rohit wants to find the maximum and minimum of salaries that his firm pays which are inputted in the form an array. Can you help him by writing a Scala program that completes the task for him. A:code:- object MyClass { val array = Array(3,4,62,8,9,2,1) if(array.isEmpty) throw new IllegalArgumentException val (minimum, maximum) = array.foldLeft((array.head, array.head)) { case ((min, max), next) => if(next > max) (min, next) else if(next < min) (next, max) else (min, max) } println(minimum, maximum); }
  • 9. 19CS3056S Functional and Concurrent Programming 14 3. Dora wants to remember week days with the help of numbers. She wants your help to make a program that prints numbers according to week days. Example: 0-Sunday 1-Monday 2-Tuesday so on A:
  • 10. 19CS3056S Functional and Concurrent Programming 15 Post-Lab: 1. Your friend gave you a String "Vanilla Donut 10 2.25", where the literal Vanilla Donut is a particular donut, the 10 literal is the quantity purchased, and 2.25 is the unit price of each Vanilla Donut. You further need to cast each token from the input String to their corresponding types, such as, an Int, Double or String. Parse the corresponding values usingScala. A:
  • 11. only) Signature of the Evaluator Date of Evaluation: 19CS3056S Functional and Concurrent Programming Viva – voice: 1. WhichScala libraryis used for functional programming? A: 2. What is a ‘Scala set’?What are methods throughwhichoperationsets are expressed? A: 3. HowisScala aprogramming languagewitha combinationof bothfunctionaland object- orientedprogramming? A: 4. Explainthe functionalityof Yield? A: 5. What is the advantageofusingScala overotherfunctional programming languages?Define the features of ImmutableVariables? A: (For Evaluator’s use Comment of the Evaluator (if Any) Evaluator’s Observation Marks Secured: out of Full Name of the Evaluator: