0% found this document useful (0 votes)
72 views

BERNARDO CompilationCPF PDF

The document contains a compilation of activities in computer programming submitted by Matthew Glenn L. Bernardo. It includes 13 machine exercises demonstrating basic programming concepts like input/output, calculations, conditional statements, loops, and functions. It also contains 8 laboratory exercises and a case study with input, output, flowchart and explanation sections.

Uploaded by

FerrolinoLouie
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)
72 views

BERNARDO CompilationCPF PDF

The document contains a compilation of activities in computer programming submitted by Matthew Glenn L. Bernardo. It includes 13 machine exercises demonstrating basic programming concepts like input/output, calculations, conditional statements, loops, and functions. It also contains 8 laboratory exercises and a case study with input, output, flowchart and explanation sections.

Uploaded by

FerrolinoLouie
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/ 39

COMPILATON OF ACYIVIES

IN
COMPUTER PROGRAMMING

Submitted by; Matthew Glenn L. Bernardo


Submitted to: Professor. Louielito Ferrolino
Student Number: 201913554
TABLE OF CONTENT
I. Machine Exercises

1.1 MEX ……………………………………………………………………… 1


1.2 MEX ……………………………………………………………………… 2
1.3 MEX ……………………………………………………………………… 3
2.1 MEX ……………………………………………………………………… 4
2.2 MEX ……………………………………………………………………… 5
3.1 MEX ……………………………………………………………………… 7
3.2 MEX ……………………………………………………………………… 9
4.1 MEX ……………………………………………………………………… 11
4.2 MEX ……………………………………………………………………… 12
5.1 MEX ……………………………………………………………………… 13
5.2 MEX ……………………………………………………………………… 14
6.1 MEX ……………………………………………………………………… 16
6.2 MEX ……………………………………………………………………… 17

II. Laboratory Exercise

Exercise 1 ……………………………………………………………………… 18
Exercise 2 ……………………………………………………………………… 20
Exercise 3 ……………………………………………………………………… 21
Exercise 4 ……………………………………………………………………… 23
Exercise 5 ……………………………………………………………………… 25
Exercise 6 ……………………………………………………………………… 26
Exercise 7 ……………………………………………………………………… 27
Exercise 8 ……………………………………………………………………… 28

III. Case Study

Input ……………………………………………………………………… 30
Output ……………………………………………………………………… 33
Flowchart ……………………………………………………………………… 34
Explanation ……………………………………………………………………… 37
1.MACHINE EXERCISE 1
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
float x, y, z;
cout<<"Enter the length of first side (X): ";
cin>>x;
cout<<"Enter the length if the second side (Y): ";
cin>>y;
z=sqrt((x*x)+(y*y));
cout<<"The length of the triangle's hypotenuse is "<<z;
getch();
return 0;
}

OUTPUT
2.MACHINE EXERCISE 1.2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x, y;
cout<<"Please enter first number: ";
cin>>x;
cout<<"Please enter second number: ";
cin>>y;
cout<<"Sum: "<<(x+y)<<"\n";
cout<<"Difference: "<<(x-y)<<"\n";
cout<<"Product: "<<(x*y)<<"\n";
cout<<"Quotient: "<<(x/y);
getch();
return 0;
}

OUTPUT:
3.MECHINE EXERCISE 1.3
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x, y;
cout<<"Enter Fahrenheit value: ";
cin>>x;
y=(((x-32)*5)/9);
cout<<"For a Fahrenheit temperature of "<<x;
cout<<" degrees, the equivalent Celsius temperature is "<<y<<" degrees";
getch();
return 0;
}

OUTPUT:
4.MACHINE EXERCISE 2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a;
cout<<"Please enter this week's gross sales: ";
cin>>a;
if(a>=0)
{
cout<<"Your commsion this week is ₱"<<(a*0.09);
cout<<"\nYour total earnings this week is ₱"<<((a*0.09)+200);
}
Else
{
cout<<"Program must terminate, no output";
}
getch();
return 0;
}
OUTPUTS:
5.MACHINE EXERCISE 2.2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a, b, c ,d;
cout<<"Please enter your Prelim Grade: ";
cin>>a;
cout<<"Please enter your Midterm Grade: ";
cin>>b;
cout<<"Please enter your Final Grade: ";
cin>>c;
d=((a*0.3)+(b*0.3)+(c*0.4));
cout<<"Your semestral grade is "<<d<<"\n";
if(d==100)
{
cout<<"Equivalent letter is A";
}
else if(d<=99&&d>=90)
{
cout<<"Equivalent letter is B";
}
else if(d<=89&&d>=80)
{
cout<<"Equivalent letter is C";
}
else if(d<=79&&d>=75)
{
cout<<"Equivalent letter is D";
}
else if(d<75)
{
cout<<"Equivalent letter is F";
}
getch();
return 0;
}
OUTPUTS:
6.MACHINE EXERCISE 3
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
char a;
int x, y;
cout<<"Please enter the first number: ";
cin>>x;
cout<<"Please enter the second number: ";
cin>>y;
cout<<"Choose an operation:\n";
cout<<" a=addition\n s=subtraction\n m=multiplication\n d=division\n";
cout<<"Please enter your desired operation: ";
cin>>a;
switch(a)
{
case 'a':
cout<<”The sum of the two numbers you entered is “<<(x+y);
break;
case 's':
cout<<”The difference of the two numbers you entered is “<<(x-y);
break;
case 'm':
cout<<”The product of the two numbers you entered is “<<(x*y);
break;
case 'd':
cout<<”The quotient of the two numbers you entered is “<<(x/y);
break;
default:
cout<<”No match for chosen operation";
}
getch();
return 0;
}
OUTPUTS:
7.MACHINE EXERCISE 3.2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a, b, c, d;
cout<<"Please enter your Prelim grade: ";
cin>>a;
cout<<"Please enter your Midterm grade: ";
cin>>b;
cout<<"Please enter your Final grade: ";
cin>>c;
d=((a*0.3)+(b*0.3)+(c*0.4));
cout<<"Your semestral grade is "<<d<<"\n";
switch(d){
case (100):
cout<<"Your equivalent letter is A";
break;
case (99):
case (98):
case (97):
case (96):
case (95):
case (94):
case (93):
case (92):
case (91):
case (90):
cout<<"Your equivalent letter is B";
break;
case (89):
case (88):
case (87):
case (86):
case (85):
case (84):
case (83):
case (82):
case (81):
case (80):
cout<<"Your equivalent letter is C";
break;
case (79):
case (78):
case (77):
case (76):
case (75):
cout<<"Your equivalent letter is D";
break;
default:
cout<<"Your equivalent letter is F";
}
getch();
return 0;
}

OUTPUTS:
8.MACHINE EXERCISE 4
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x=1, n=5;
cout<<"(N)\t(N2)\t(N3)\t(N4)\n";
while(x<=n)
{
cout<<x<<"\t"<<x*x<<"\t"<<x*x*x<<"\t"<<x*x*x*x<<endl;x++;
}
getch();
return 0;
}

OUTPUT:
9.MACHINE EXERCISE 4.2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
float a,b,c=1;
cout<<"Please enter 10 numbers: "<<endl;
while (c<=10)
{
cin>>a;
b=b+a;c++;
}
cout<<"The average of the 10 numbers you have entered is "<<(b/10);
getch();
return 0;
}

OUTPUT:
10.MACHINE EXERCISE 5
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a,b=1,c=1;
cout<<"Please enter any non-negative integer: ";
cin>>a;
do
{
b=b*c;c++;
}while (c<=a);
cout<<a<<" factorial is "<<b;
getch ();
return 0;
}

OUTPUT:
11.MACHINE EXERCISE 5.2
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
float a=0,pi=3.14;
cout<<"Angle\t sin x\t cos x\t tan x\n";
do
{
cout<<a<<"\t"<<sin((a*pi)/180)<<"\t"<<cos((a*pi)/180)<<"\t"<<tan((a*pi)/180)<<endl;a++;
}
while (a<=20);
getch ();
return 0;
}
OUTPUT:
12. MACHINE EXERCISE 6
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x;
float c,f;
for(x=1;x<=6;x++)
{
cout<<"Enter a fahrenheit temperature value: ";
cin>>f; c=(f-32)*5/9;
cout<<c<< " degrees celcius" <<endl;
}
getch();
return(0);
}

OUTPUT:
13. MACHINE EXERCISE 6.2
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x;
cout<<"X\t"<<"1\t"<<"2\t"<<"3\t"<<"4\t" <<"5\t"<<"6\t"<<"7\t"<<"8\t"<<"9\t";
for(x=1;x<=10;x++)
{
cout<<x<<'\t'<<x<<'\t' <<x*2<<'\t'<<x*3<<'\t'<<x*4 <<"\t"<<x*5<<"\t"<<x*6<<"\t"<<x*7
<<"\t"<<x*8<<'\t'<<x*9<<endl;
}
getch();
return(0);
}

OUTPUT:
Laboratory Exercise 1
COMMUNICATION THROUGH CONSOLE

Direction: Demonstrate the corresponding output for each program in the boxes below.
Give your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. This is a basic program it used


(#include<iostream.h>
#include<conio.h>) both preprocessor
statement that has header file that consoles
input output stream. It also used
(cout<<”Hello World!”>>) that shows the
output stream of Hello World. Then finishing
the program with the (return 0) or the ending
point of this program
2. Another basic program, it used int age to
determine the value of the variable is an
integer and the given age was 16. It also used
the (cout<< “My age is”<<age; )to show the
output stream of My age is and the integer of
the age that is 16.

3. It used the (char ch) that means the character


of the program and ch as scripting
language.Used the (ch=’A’; ch=’B’;) as the
scripting language of A and B. And (getch();)
Directly reading character from the output.
4. It used int to determine the value of the
variable are integer.(cout<<”Enter dividend
and divisor”;) command that enable to show
the output stream of “Enter dividend and
divisor”. For the quotient it uses the ( / ) a
command to divide to integer and ( % ) a
command to find the remainder of the given
integers.

5. It used float command is used to determine


that the given value has a decimal.It also used
the command cin that enables to input data in
the screen. And(cout<<”Enter a number in
feet”;) this command that enable to show the
output stream of “Enter a number in feet”.
The output also shows converting feet to
meters, by doing that multiply the given feet
by (0.3048) in order to get the value of feet to
meter.
6. It used the command int to detemine the value
of the variable are integer. Used
(cout<<”Enter two number:”:) to show the
output stream “Enter two number:”. The (==)
means equal or equas to, (!=) that means not
equal or not equal to, (<=) that means less
than or equal to, (>=) that means greater than
or equal to, (<) that means less than and lastly,
(>) that means greater than.

7.
It used the command (int a, b;) that
determines the value of the variable a and b
are integer. It also used (--) to subtract the
integer by 1.
Laboratory Exercise 2
2D GRAPHICS

Direction: Demonstrate the corresponding output for each program in the boxes
below. Give your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. For the header this program uses the


(#include<stdio.h>) that means standard
input and output function without this header
file one cannot display or input the values
through the keyboard and the
(#include<dos.h>) it is use to handle
interruption, produce sounds, etc. Uses gotoxy
function to move the cursor to a specified
location on screen. It also uses (textcolor) to
change the color of the drawing text. Also
used the (cprintf) a function that write output
directly to the console under control of the
argument format.
2. For this program, they have in common with
the first program it used (textcolor) to
change the color of the drawing text. but the
thing in this program it uses the command
(#define) a macro name replacement string
that causes the compiler to go through the file
and replace every occurrence of macro name
with replacing string.
Laboratory Exercise 3
CONDITIONAL if STATEMENT

Direction: Demonstrate the corresponding output for each program in the boxes
below. Give your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. In this program it commonly uses the (if )


statement which allows the user to control if a
program enters a section of code or not based
whether a given condition is true or false. It
used (if(a<0)) and (cout<<”The number is
negative”;) that means if a is less than zero so
the output will be “The number is negative”.
And used the(else) and (cout<<”The number
is positive or zero”) else statement if the
condition is false the output will be “The
number is positive ir zero”.
2.
In this program it also uses the (if ) statement
which allows the user to control if a program
enters a section of code or not based whether
a given condition is true or false. And (else)
statement of tje condition is false. But the
thing in this program it uses the (else if)
statement this expression is use to specify a
new condition to test if the first condition is
false.
3. This program used (cout<<”Do you
consider yourself a hot-tempered
individual(y=Yes/n=No)?”) and
(cin>>Answer) the first command is cout
this command that enable to show the output
stream of the question “Do you consider
yourself hot-tempered
individual(y=Yes/n=No)?”, while the second
one is cin to receive a stream of characters. It
also used the (if ) statement which allows the
user to control if a program enters a section of
code or not based whether a given condition
is true or false. And (else) statement of tje
condition is false. But the thing in this
program it uses the (else if) statement this
expression is use to specify a new condition
to test if the first condition is false.
Laboratory Exercise 4
CONDITIONAL switch STATEMENT

Direction: Demonstrate the corresponding output for each program in the boxes
below. Give your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. In this program it uses the (switch)statement that


allows a variable to be tested for equality against a
list of values, for each value is called a case which the
variable being switched on is checked for each
case.It uses (case) is a test value equality for a list of
values, where each values is a case in this program
the case are 1-5 only. It also uses the (break)
statement is a loop control statement this is use to
terminate the loop. And it also uses (default) a
declaration that is automatically assigned by the
compiler if the caller of the function doesn’t provide
a value for the argument with a default value in this
case the value 6 doesn’t match any cases from 1-5.

2 This program has a common in the first program it


. also used the (switch) statement that allows a variable
to be tested for equality against a list of values, for
each value is called a case which the variable being
switched on is checked for each case.It uses (case) is
a test value equality for a list of values, where each
values is a case in this program the case are a-e only.
It also uses the (break) statement is a loop control
statement this is use to terminate the loop. And it also
uses (default) a declaration that is automatically
assigned by the compiler if the caller of the function
doesn’t provide a value for the argument with a
default value in this case the value f doesn’t match
any cases from a-e. One thing that makes it different
from the first program that it uses (char) a character
pointer is used to make strings of single character.
3. This program has a common with the two other
programs it also used the (switch) statement that
allows a variable to be tested for equality against a
list of values, for each value is called a case which the
variable being switched on is checked for each
case.It uses (case) is a test value equality for a list of
values, where each values is a case in this program
the case are 1-3. And it also uses (default) a
declaration that is automatically assigned by the
compiler if the caller of the function doesn’t provide
a value for the argument with a default value. I used 4
because it doesn’t match any case from 1-3. It makes
it different from other programs that it doesn’t use
(break) statement.
Laboratory Exercise 5
LOOPING while STATEMENT

Direction: Demonstrate the corresponding output for each program in the boxes below. Give
your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. In this program it uses int to determine the value of


the variable are integer. It used (while) is a loop
statement this allows to repeatedly run the same block
of code until the condition is met and (if ) statement
which allows the user to control if a program enters a
section of code or not based whether a given
condition is true or false. Used the (break) statement
is a loop control statement this is use so the user can
leave a loop even if the condition for its end is not
fulfilled. It also uses x++ an increment operator that
is in postfix form it will increment the value of x, but
return the original value that x held before being
incremented.

2. In this program alike with the first program it also


uses (while) loop statement that allows repeatedly run
the same block of codes until the condition is met in
this program the while loop is x<=10
and the given values in this program are (y, x=1, and
total=0) are code that are given. there are also
commands like (y=x*x and total=total+y) that means
the command y=x*x will become y=1*1, because
x=1 after solving you will have an outcome of 1 since
the total given is zero it will make the total=1. It also
uses ++x an increment operator that is in prefix form
it returns the value of the variable after it has been
incremented.
Laboratory Exercise 6
LOOPING do...while STATEMENT

Direction: Demonstrate the corresponding output for each program in the boxes below. Give
your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. This is a (do while) loop, a variant of the


while loop. This loop will execute the code
block once, before checking if the condition is
true, then it will repeat the loop as long as the
condition is true. In this program , user is
asked to enter a positive integer which is
stored in variable num, Inititally
while(num>0) the num is greater than zero
the user entered 23. Then the while loop start
to execute the codes , the codes inside the
body of loop is executed at least once. Then,
only the test expression is checked. The user
used (num--) this is a post decrement where
the current value of num in the expression in
which num resides , then decrement num by
1.
2. This is like the first program it is also a (do
while) loop, a variant of the while loop. This
loop will execute the code block once, before
checking if the condition is true, then it will
repeat the loop as long as the condition is
true. The difference is it uses (x++) an
increment operator that is in postfix form it
will increment the value of x, but return the
original value that x held before being
incremented.
Laboratory Exercise 7
LOOPING for STATEMENT

Direction: Demonstrate the corresponding output for each program in the boxes below. Give
your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. This program used (for) statement a loop that is used


for executing a block of statement repeatedly until a
particular condition is satisfied. It also used (x++) an
increment operator that is in postfix form it will
increment the value of x, but return the original value
that x held before being incremented. So this program
is loop for 100 times starting from 1 to 100 it increase
due to the use of the increment operator (x++). This
program is created to solve the sum of integer from 1
to 100.

2. The code used in this program is the same as the


same as the first program. It also used (for) statement
a loop that is used for executing a block of statement
repeatedly until a particular condition is satisfied.
And (x++) an increment operator that is in postfix
form it will increment the value of x, but return the
original value that x held before being incremented.
This program is created to solve the given numbers
starting from 1 up to 6 by getting the square and the
cube value of each number.
Laboratory Exercise 8
FUNCTIONS

Direction: Demonstrate the corresponding output for each program in the boxes below. Give
your analysis and observation for each output.

PROGRAM OUTPUT ANALYSIS / OBSERVATION

1. It is said that this program demonstrates the


use of parameter. The purpose of parameter is
to allow passing arguments to the function from
the location where it is called from. It used
(void) that specified the function takes no
parameter and does not return a value. It also
used (PassByValue) arguments are passed by
value, the argument’s value is copied into the
value of the corresponding parameter.
2. This program is said to be demonstrating the
use of reference parameter. This is used when
you need to change the value of an actual
parameter variable in the call that enables you
to pass large structure efficiently. It used (void)
like in the first program that specified the
function takes no parameter and does not return
a value.It also used (PassByReference) a
function that can modify rhe value of rhe
argument by using its reference passed in.
3. In this program demonstrates the use of
reference parameter versus value parameter,
reference parameter is a reference to a memory
location of a variable. The reference parameters
represent the same memory location as the
actual parameters that are supplied to the
method. When you pass parameters by
reference, unlike value parameters, a new
storage location is not created for these
parameters. It used (void) like in the first
program that specified the function takes no
parameter and does not return a value.
4. In this program it demonstrates function
prototyping it is a declaration that tells the
program about the type of the value returned by
the function and the number and type of
arguments. It used (iomanip) a predefined
function in the program that formats the output
weather writing to console or to a file you can
use. It also used (define) is a identifier
replacement,when the preprocessor encounters
this directive, it replaces any occurrence of
identifier in the rest of the code by replacement
This program is created to find the
circumference of the circle and its area in any
given radius.
CASE STUDY
 INPUT:
#include<conio.h>
#include<iostream.h>

int main()
{
clrscr();
float a,e,f=0,g=1,y;
char order;

textbackground(GREEN);
cout << "=====================" << endl;
cprintf (" Ayabells Menu ");
cout << "\n=====================" << endl;
cout << endl;
cout << "Student Meal:" << endl;
cout << "(A) Siomai and Rice for Php 25.00" << endl;
cout << "(B) Sisig and Rice for Php 35.00" << endl;
cout<< "(C) Chicken skin and Rice for Php 35.00"<<endl;
cout<< "(D) Fishballs 8 pieces for Php 5.00"<<endl;
cout << "How many order?" << endl;
cin >> y;
if(y<1000&&y>0){
while (g<=y) {
cout << "What do you want to order? " << endl;
cin >> order;
switch (order) {
case 'a':
case 'A':
cout << "You ordered siomai and rice."<<endl;
a=25;
break;
case 'b':
case 'B':
cout << "You ordered sisig and rice."<<endl;
a=35;
break;
case 'c':
case 'C':
cout<<"You ordered chicken skin and rice."<<endl;
a=35;
break;
case 'd':
case 'D':
cout<<"You ordered fishballs."<<endl;
a=5;
break;
default:
cout << "Invalid entry please try again. ";
break;
}
f= a+f;
cout << "Your total bill is " <<f<< endl;
g++;
}

}
else{
cout<<"Invalid Input\n";}
cout << "Thank You for coming!" <<endl;
getch();
return 0;
}
 OUTPUT:
 FLOWCHART:

NO

YES
NO

YES

NO

YES
 EXPLANATION OF THE PROGRAM:

This program shows the student meal from the Ayabells menu which contains food like
siomai and rice, sisig and rice, chicken skin and rice, and fishballs. It is designed to take the
quantities of the order in the given menu and to compute for the total bill for every purchase. I
used iostream.h and conio.h that are both preprocessor statement that has header file that
consoles input and output stream. I used char a data type that is like the int command, it is an
integral type that means the underlying value is stored as an integer. I used float it's a
fundamental data type built into the compiler that's used to define numeric values with floating
decimal points. For me to get the green background color I used the textbackground and also
used the cprintf it will print out the given text that I made and will not be included in the color
of its background. I inputted while statements a looping statement this allows to repeatedly run
the same block of code until the condition is met and if statement which allows the user to
control if a program enters a section of code or not based whether a given condition is true or
false. Putting the switch allows a variable to be tested for equality against a list of values, for
each value is called a case which the variable being switched on is checked for each case and
break a looping control statement this is use so the I can leave a loop even if the condition for its
end is not fulfilled. I also inputted (f=a+f) a command that I used to get the total bill of the order.
And used else if the condition is false it will proceed as an invalid input that will end the
program instantly. You will know the transaction is completed when the output of the “Thank
You for coming!” appeared because that is the last part of the program .

You might also like