Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COMP 1 4 1 : Introduction to Programming Languages Instructions: In this lab, we are going to try functional programming in C + + .

COMP 141: Introduction to Programming Languages
Instructions: In this lab, we are going to try functional programming in C++. Rewrite the following C++
code fragments. Your modified code should obey the following rules:
No global variables
No pass-by-reference and pass-by-pointer parameters (except arrays)
No iteration
1 Fibonacci
int fib (int n){
if (n <=1) return 1;
int x =1;
int y =1;
int t;
for (int i =2; i < n; i++){
t = x;
x = x + y;
y = t;
}
return x;
}
2 Min and max in an array
void minmaxFromArray(long _array[], short _array_length, long& _min, long& _max){
short i;
long min =_array[0];
long max =_array[1];
for (i=1; i<_array_length; i++){
if (_array[i]< min) min =_array[i];
if (_array[i]> max) max =_array[i];
}
_min = min;
_max = max;
}
3 Inserting an entry to a dictionary
vector > dictionary;
void setDictionaryEntry(string _key, string _value){
unsigned short i;
for (i=0; i(_key, _value));
}
1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions