Sunteți pe pagina 1din 2

CT025-3-2: Programming Concepts in C++

Page 1 of 2

Functions
Part A:
For each of the following problems, code the solution, using functions, in C++.
1.
2.

Write an application using function that returns the smallest of three floating-point
numbers
An integer is said to be prime if it is divisible only by 1 and itself. For example, 2,
3, 5 and 7 are prime but 4, 6, 8 and 9 are not. Write an application with a function
that determines if a number is prime.

3.

Write an application with a function that takes an integer value and returns the
number with its digits reversed. For example, given number 7631, the function
should return 1367.

4.

The greatest common divisor (GCD) of two integers is the largest integer that
evenly divides each of the numbers. Write an application using the function gcd
that returns the greatest common divisor of two integers.
Write an application with the function qualityPoints that inputs a students
average and returns 4 if a students average is 90 100, 3 if the average is 80
89, 2 if the average us 70 79, 1 if the average is 60 69 and 0 if the average is
lower than 60.

5.

Part B:
For each of the following situations, write an application in C++ using appropriate
built-in functions where necessary
1. Write an application using appropriate built-in functions that will remove embedded
blanks in a given string.
2. Write an application using appropriate built-in functions that replaces all occurrences
of the character x with X in a given string.
3. Write an application using appropriate built-in functions that reverses a given string.
3.1 check It is para or not
4. An application of function floor is rounding a value to the nearest integer. The
statement
y = floor (x + .5);
will round the number x to the nearest integer and assign the result to y. Write a
program that reads several numbers and uses the preceding statement to round
each of these numbers to the nearest integer. For each number processed, print
both the original number and the rounded number.
Develop an interactive program that reads a low value, a high value, and an increment value, ensures that the low value is less than or
equal to the high value, and computes and prints a table of square and cube values from low to high at increments of increment.
Sample input-output :
Low value
:
1

LAB 2

CT025-3-2: Programming Concepts in C++


High value
Increment
Value
1
2
3
4
5

LAB 2

:
Square
1
4
9
16
25

5
:
Cube
1
8
27
64
125

Page 1 of 2

S-ar putea să vă placă și