Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS126-8L: Computer Programming 1 (Laboratory)

Directions:

1. For each solution, you need to put on the following program comment indicating the
problem number, your name, today’s date, program, course/section and the purpose of
the program.
Example: /*
* Programmer: FUENTES, Gloren S.
* Date Created: 10/14/2020
* Program: BSCS/BMCS/BSIT/BMIT
* Course / Section: CS126-8L/OL160
* Purpose: This program will calculate the speed from distance over time.
(or copy and paste the given problem)
*/
2. Save your code in CPP format with the filename: FLNAME-PRAC02.cpp (e.g.
GFUENTES-PRAC02.cpp)
3. Once done, upload your file on Blackboard.
4. Failure to follow instructions will get a 5-point deduction. Please be guided accordingly.

Practical # 2 (100 points total)

1. Create C++ program for the following: (In implementing your program, use any function
declaration for each problem and combine them in one program)

MENU OPTIONS:
[1] Sum of Integer Numbers
[2] Ribbon
[3] Highest and Lowest Odd and Even Random Numbers
Enter your choice: _

[1] Create a UDF (with return /with passing parameter)


program to calculate the sum of integer numbers from a 1 to an.

𝑛(𝑎1 +𝑎𝑛 )
The formula for calculating the sum is: 𝑠𝑢𝑚 =
2

where: n is the number of integers to be added (an – a1) + 1


a1 is the first number to be added
an is the last number to be added

Sample Output 1:
Input the first number to be added (a1): 1
Input the last number to be added (an): 12
The sum of 1 to 12 = 78

Sample Output 2:
Input the first number to be added (a1): 88
Input the last number to be added (an): 95
The sum of 88 to 95 = 732

[2] Create a UDF (no return /no passing parameter) will prompt the user to input the
size of ribbon figure (5-15) odd numbers only and display the figure like this:

Sample Output:
Input size of Ribbon to generate (5-15) odd numbers only: 5
# #
# # # #
# # # # #
# # # #
# #

[3] Create a UDF (no return /with passing parameter) that prompts the user to input
how many random numbers to generate in the range of -100 to 100. Valid input is from
1-100. Output how many positive numbers generated and the highest and lowest among
the positive numbers. Output also how many negative numbers generated and the highest
and lowest among the negative numbers.

Sample Output:
Random numbers to generate (-100 to 100 only): 10

The 10 random numbers in the range of -100 to 100 are:


-1 10 8 -55 10 -78 6 -33 28 100

There is/are 6 POSITIVE numbers:


The HIGHEST POSITIVE number is 100
The LOWEST POSITIVE number is 6

There is/are 4 NEGATIVE numbers:


The HIGHEST NEGATIVE number is -1
The LOWEST NEGATIVE number is -78

You might also like