Define procedure to input integers and returns the average, C/C++ Programming

Assignment Help:

The procedure +, * and list take arbitrary numbers of arguments. One way to define such a procedure is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates that, when the procedure is called, the initial parameters (if any) will have as values the initial arguments, as usual, but the final parameter's value will be a list of any remaining arguments. For instance, give the definition:

(define (f x y . z) )

the procedure f can be called with two or more arguments. If we evaluate

(f 1 2 3 4 5 6)

then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6).

Given the definition:

(define (g . w) )

the procedure g can be called with 0 or more arguments. If we evaluate

(g 1 2 3 4 5 6)

then in the body of g, w will be the list ( 1 2 3 4 5 6).

(a) Use this notation to write a procedure average that takes one or more integers and returns the average. For example:

(average 1 2 3 4 5 6 7) => 4
(average 2) => 2

(b) Write a procedure called pipeline that accepts a variable number of arguments that are procedures and returns the composition of those procedures. This is called pipeline processing. You may assume that all procedures in the pipeline accept a single argument. For example:
(define square-cubed (pipeline square square square))
; is equivalent to:
(define square-cubed (lambda (x) (square (square (square x)))))
(square-cubed 2) => 256

(c) Using your definition for pipeline from (b), write procedures for cdar, cddar and cdadr.


Related Discussions:- Define procedure to input integers and returns the average

Can you overload a function depend only on whether parameter, Can you overl...

Can you overload a function depend only on whether a parameter is a value or a reference? A: No. Passing by value and reference looks identical to the caller.

COMPILER DESIGN, aj is a newbie to the programming and while learning the p...

aj is a newbie to the programming and while learning the programming language he came to know the following rules: - Each program must start with ''{'' and end with ''}''.

Oop, what is oop?

what is oop?

Program for design and simulate a basic risc processor, Overall Program Obj...

Overall Program Objective: You will design and simulate a basic RISC processor.   You will create and encode an instruction set.  Your final task will be to "compile" a program

The use of the break and continue statements in a loop, Question: (a) ...

Question: (a) A bank has four types of accounts with annual interest rates as follows: Savings 8% Savings with Cheque Book 5% Current 4% Fixed deposits 10% Using

Looping, #questiStarting with a blank solution, write a program to prompt t...

#questiStarting with a blank solution, write a program to prompt the user for an employee number, hourly rate and hours worked. Compute and display the employee number, gross weekl

Example for external storage class - computer programming, Example for exte...

Example for external storage class - computer programming? extern double sin (double); In a function prototype, for the sin() function its function definition ~ we can write

How can i present printing for my class fred?, A: Use operator overloading ...

A: Use operator overloading to present a friend left-shift operator, operator #include class Fred { public: friend std::ostream& operator ... private: int i_; // onl

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd