0% found this document useful (0 votes)
11 views7 pages

ةيندرلأا ةعماجلا / ةبقعلا Computer Skills Science Faculties ةداملا: لا جاحلا وبا نيدلارون: بلاط 3221499 بلاطلا: دئار دمحا 3221544 Exercises

Uploaded by

jsksvoey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

ةيندرلأا ةعماجلا / ةبقعلا Computer Skills Science Faculties ةداملا: لا جاحلا وبا نيدلارون: بلاط 3221499 بلاطلا: دئار دمحا 3221544 Exercises

Uploaded by

jsksvoey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

‫الجامعة األردنية \العقبة‬

COMPUTER SKILLS SCIENCE FACULTIES : ‫المادة‬


3221499‫نورالدين ابو الحاج‬: ‫الطالب‬
3221544 ‫ احمد رائد‬: ‫الطالب‬
EXERCISES (1) Mark the following statements as true or false:

a. To use a predefined function in a program, you need to know only the name of the function
and how to use it

True

b. A value-returning function returns only one value

False.

EXERCISES)2(. Determine the value of each of the following expressions


c. static_cast<char>(toupper('3'))

output=3

e. static_cast<char>(tolower('T'))

output=t

EXERCISES (3). Determine the value of each of the following expressions. (For
decimal numbers, round your answer to two decimal places.)

h. sqrt(38.44)* pow(2.4, 2) / fabs(-3.2)

output=11.16

i. floor(27.37)

output=27

EXERCISES( 5). Consider the following function definition.


double funcTest(string name, char u, int num, double y)

Which of the following are correct function prototypes of the function funcTest?

a. double funcTest(string, char, int, double);


b. double funcTest(string n, char ch, int x, double t);

c. double funcTest(name, u, num, y);

d. int funcTest(string, char, int, double)

****************************************************
The answer

a. double funcTest(string, char, int, double);

This function prototype is correct

****************************************** *
b. double funcTest(string n, char ch, int x, double t);

This function prototype is also correct.

EXERCISES (11). Write the definition of a function that takes as input a char
value, and returns true if the character is a whitespace character; otherwise
it returns false.

#include <iostream>

using namespace std;

bool whitespce (char c)

if(c == ' ')

return true;

else

return false;

int main(){

char num;

cout << "Enter a character: ";

cin.get(num);

if (whitespce(num))

cout << " is a whitespace ." << endl;

else
cout << " is not a whitespace." <<endl;

EXERCISES (20). Identify the following items in the programming code shown
below:

a. Function prototype, function heading, function body, and function definitions.

Function prototype:- (void func(int, int, double&, char&);)

Function heading:- (void func(int speed, int time, double& distance, char& c))

Function body:- ({ ... })

Function definition:- (void func(int speed, int time, double& distance, char& c) { ... })

**************

b. Function call statements, formal parameters, and actual parameters.

Function call statements:- (func(s, t, d, ch);)

Formal parameters:- speed, time, distance, and c.

Actual parameters:- s, t, d, and ch.

*****************

c. Value parameters and reference parameters.

Value parameters:- speed and time in the function definition.

Reference parameters:- distance and c in the function definition.

*********************

d. Local variables and global variables.

Local variables:- num .

Global variables:- RATE , STAR, and temp .

**********************

e. Named constants.

Named constants:- RATE and STAR.

***********************

#include <iostream>//Line 1

using namespace std; //Line 2

const double RATE = 15.50; //Line 3


const char STAR = '*'; //Line 4

double temp; //Line 5

void func(int, int, double&, char&); //Line 6

int main() //Line 7

{ //Line 8

int s = 50; //Line 9

int t = 6; //Line 10

double d; //Line 11

char ch = STAR; //Line 12

func(s, t, d, ch); //Line 13

cout << "d = " << d << ", ch = " << ch << endl; //Line 14

func(75, 8, d, ch); //Line 15

cout << "d = " << d << ", ch = " << ch << endl; //Line 16

return 0; //Line 17

} //Line 18

void func(int speed, int time, //Line 19

double& distance, char& c) //Line 20

{ //Line 21

double num; //Line 22

distance = speed * time; //Line 23

num = static_cast (c); //Line 24

c = static_cast(num + 1); //Line 25

}
EXERCISES (26).. Write the definition of a void function that takes as input two
integer values, say n and m. The function returns the sum and average of all
the numbers between n and m (inclusive) .

#include <iostream>

using namespace std;

void Sum_Avg(int n, int m, int& sum, double& avg)

if(m>n){

for (int i = n; i <= m; ++i)

sum += i;

avg = static_cast<double>(sum) / (m - n + 1);

if(m<n){

for (int i = m; i <= n; ++i)

sum += i;

avg = static_cast<double>(sum) / (n - m + 1);

int main() {

int n, m;

cout << "Enter two integer values (n and m): ";

cin >> n >> m;

int sum;

double avg;

Sum_Avg(n, m, sum, avg);

cout << "Sum of numbers between " << n << " and " << m << ": " << sum <<endl;

cout << "Average of numbers between " << n << " and " << m << ": " << avg <<endl;

return 0;

}
EXERCISES (29). In the following program, number the marked statements to
show the order in which they will execute (the logical order of execution).
Also what is the output if the input is 10?

#include <iostream>

using namespace std;

int secret (int, int);

void func(int x, int& y);

int main()

int num1, num2;

num1 = 6;

cout << "Enter a positive integer: ";

cin >> num2;

cout << endl;

cout << secret(num1, num2) << endl;

num2 = num2 - num1;

cout << num1 << " " << num2 << endl;

func(num2, num1);

cout << num1 << " " << num2 << endl;

return 0;

int secret(int a, int b)

{ int d;

d = a + b;

b = a * d;

return b;

void func (int x, int& y)

{ int val1, val2;


val1 = x + y;

val2 = x * y;

y = val1 + val2;

cout << val1 << " " << val2 << endl;

Output=

96

64

10 24

34 4

You might also like