You are on page 1of 3

SEMINAR 4

ALGORITMIKE NE C++
Pyetje - Quiz
1.
2.
3.
4.
5.

A function itself is called the function d_________.


Write a function called foo() that displays the word foo.
A program statement that invokes a function is a function _________.
The first line of a function definition is referred to as the _________.
A function argument is
a. a variable in the function that receives a value from the calling program.
b. a way that functions resist accepting the calling programs values.
c. a value sent to the function by the calling program.
d. a value returned by the function to the calling program.
6. True or false: When arguments are passed by value, the function works with the
original
7. arguments in the calling program.
8. What is the purpose of using argument names in a function declaration?
9. Which of the following can legitimately be passed to a function?
a. A constant
b. A variable
c. A structure
d. A header file
10. How many values can be returned from a function?
11. Where is a functions return type specified?
12. A function that doesnt return anything has return type _________.
13. When an argument is passed by reference
a. a variable is created in the function to hold the arguments value.
b. the function cannot access the arguments value.
c. a temporary variable is created in the calling program to hold the arguments
value.
d. the function accesses the arguments original value in the calling program.
14. What is a principal reason for passing arguments by reference?
15. Overloaded functions
a. are a group of functions with the same name.
b. all have the same number and types of arguments.
c. make life simpler for programmers.
d. may fail unexpectedly due to stress.
16. In general, an inline function executes _________ than a normal function, but requires
_________ memory.
17. A default argument has a value that
a. may be supplied by the calling program.
b. may be supplied by the function.
c. must have a constant value.
d. must have a variable value.
18. What functions can access a global variable that appears in the same file with them?
19. What functions can access a local variable?
20. A static local variable is used to

a.
b.
c.
d.

make a variable visible to several functions.


make a variable visible to only one function.
conserve memory when a function is not executing.
retain a value when a function is not executing.

Ushtrim 1 konsideroni funksionin e meposhtem


int mystery(int x, double y, char ch)
{
int u;
if ('A' <= ch && ch <= 'R')
return(2 * x + static_cast<int>(y));
else
return(static_cast<int>(2 * y) - x);
}
Cili do te jete rezultati per strukturat e meposhtme:
a. cout << mystery(5, 4.3, 'B') << endl;
b. cout << mystery(4, 9.7, 'v') << endl;
c. cout << 2 * mystery(6, 3.9, 'D') << endl;
Ushtrim 2
Shkruani deklarimin e nje funksioni i cili merr si input 3 numra. Funksioni paraqet true nqs
numri i pare (a) ne fuqi numrin dyte (b) eshte i barabarte me numrin e trete (c); perndryshe
paraqet false. Numrat te jene te tipit double.
Ushtrim 3 - Cili do te jete rezultati per strukturat e meposhtme:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{

int counter;
for (counter = 1; counter <= 100; counter++)
if (pow(floor(sqrt(counter + 0.0)), 2) == counter)
cout << counter << " ";
cout << endl;
return 0;
}
Ushtrim 4
Krijoni nje funksion te quajtur EshteZanore, i cili paraqet true nqs karakteri i dhene eshte
zanore, perndryshme paraqet false.
Ushtrimi 5
Krijoni nje program qe i kerkon user-it te shkruaje nje sekuence karakteresh dhe paraqet
numrin e zanoreve, duke perdorur funksionin EshteZanore, ne ushtrimin 4.
Ushtrimi 6
Krijoni nje funksion rekursiv qe llogarit sekuencen Fibonnacci per nje numer n. Kete
funksion therriteni permes nje programi testues. [fib(n+2) = fib(n+1) + fib(n);
fib(0) = 0; fib(1) = 1]

Ushtrim 7
Krijoni nje program i cili i kerkon user-it te shkruaje dy numra dhe veprimin qe duhet te
kryhet ndermjet tyre (Makina Llogaritese). Secili prej veprimeve do realizohet per mes
therritjes se funksioneve Mblidh, Zbrit, Shumezo, Pjesto.
Ushtrim 8
Krijoni tabelen e shumezimit si me poshte:
1*1=1
1+2=2
.
1*9=9

2*1=2
2*2=4
.
2*8=18

3*1=3
9*1=1
3*2=6
9*2=18
.
.
3*9=27
9*9=81

You might also like