0% found this document useful (0 votes)
10 views8 pages

Es 132 Module 4

The document contains a pretest and post-test for a learning module in programming, specifically focusing on C++. It includes questions on variable naming, expressions, and assignment statements, followed by programming tasks that require writing code for various operations such as displaying messages, performing calculations, and computing areas. The document provides example outputs for each programming task to illustrate the expected results.

Uploaded by

kram mark
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)
10 views8 pages

Es 132 Module 4

The document contains a pretest and post-test for a learning module in programming, specifically focusing on C++. It includes questions on variable naming, expressions, and assignment statements, followed by programming tasks that require writing code for various operations such as displaying messages, performing calculations, and computing areas. The document provides example outputs for each programming task to illustrate the expected results.

Uploaded by

kram mark
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/ 8

Name: MARK HARRY O.

ZERDA
Course & Year: BSEE 1A

LEARNING MODULE NO. 4 – PRETEST


1. Which one of the following is a reserved word?
-c. grandTotal
2. Which one of the following is NOT a correct variable name?
-a. 2bad
3. Which one of the following declarations is NOT correct?
-c. boolean value = 12;
4. Which of the declaration is invalid?
-c. char name;
5. Which of the following shows the syntax of an assignment statement?
-a. variableName = expression;
6. What are the two steps that take place when an assignment statement is executed?
-a. (i) Evaluate the Expression, and (ii) Store the value in the variable.
7. What is an expression?
-c. An expression is a combination of literals, operators, variables, and parentheses used to
calculate a value.
8. Which one of the following expressions is NOT correct?
-d. -12 + (13 + 7)/2 ) * 4
9. Which of the following expressions is incorrect?
-c. 34 - 86) / (23 - 3 )
10. What is the value of the following expression:
(2 - 6) / 2 + 9
-a. 7
Learning Module No. 4– Post Test

1. Write a program to display “Hello World” on screen at exactly five times

#include <iostream>
using namespace std;
int main()
{
cout << "Hello World"<< endl;
cout << "Hello World"<< endl;
cout << "Hello World"<< endl;
cout << "Hello World"<< endl;
cout << "Hello World"<< endl;
return 0;
}

Result
Hello World
Hello World
Hello World
Hello World
Hello World

2. Create a program file calculator.cpp that accepts two users’ input and calculate
the ff: A. sum, B. difference, C. product, D. quotient.

#include <iostream>
using namespace std;
int main()
{
char op;
float num1,num2;

cout << "Enter the operator (+, -, *, / ) : ";


cin >> op;

cout << "Enter two numbers one by one : ";


cin >> num1 >> num2;

switch( op )
{
case '+':
cout << num1 << " + " << num2 << " = " << (num1 + num2);
break;

case '-':
cout << num1 << " - " << num2 << " = " << (num1 - num2);
break;

case '*':
cout << num1 << " * " << num2 << " = " << (num1 * num2);
break;

case '/':
if ( num2 != 0.0 )
cout << num1 << " / " << num2 << " = "<<(num1 / num2);
else
cout << "Divide by zero situation";

break;

default:
cout << op << "is an invalid operator";

return 0;
}
Result ;
A. Sum,
Enter the operator (+, -, *, / ) : +
Enter two numbers one by one : 2 5
2+5=7
B. Difference
Enter the operator (+, -, *, / ) : -
Enter two numbers one by one : 10 5
10 - 5 = 5
C. Product
Enter the operator (+, -, *, / ) : *
Enter two numbers one by one : 10 5
10 * 5 = 50
D. Quotient
Enter the operator (+, -, *, / ) : /
Enter two numbers one by one : 40 20 10
40 / 10 = 4

3. Create a program that exchanges the value of the two variables: x and y.

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x,y;
cout<<"Enter x:";
cin>>x;
cout<<"Enter y:";
cin>>y;
cout<<"Before Exchange:x= "<<x<<"y="<<y<<"nn";
"exchange(&x,&y)"; // Calling Exchange function to swap
cout<<"After exchange:x = "<<x<<"y="<<y<<"nn";
getch();
}
Result;
Enter x:10
Enter y:30
Before Exchange:x= 10y=30nnAfter exchange:x = 10y=30nn

4. Accept three numbers and print the sum and the inputted numbers.

#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Please enter an integer value for variable a ";

cin >> a;

cout << "Please enter an integer value for variable b ";

cin >> b;

cout << "Please enter an integer value for variable c ";


cin >> c;
cout <<a<<" + "<<b<<" + "<< c << "= "<<a+b+c;

return 0;
}
Result
Please enter an integer value for variable a 7
Please enter an integer value for variable b 7
Please enter an integer value for variable c 6
7 + 7 + 6= 20

5. Accept three numbers and print the product of the numbers

#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Please enter an integer value for variable a ";

cin >> a;

cout << "Please enter an integer value for variable b ";

cin >> b;

cout << "Please enter an integer value for variable c ";


cin >> c;
cout <<a<<" * "<<b<<" * "<< c << "= "<<a*b*c;

return 0;
}
Result;
Please enter an integer value for variable a 7
Please enter an integer value for variable b 7
Please enter an integer value for variable c 6
7 * 7 * 6= 294
6. Input three numbers and print the sum, product and average of the numbers.

#include <iostream>
using namespace std;
int main()
{
int x, y, z;
float sum, average, product;
cout<< "Enter first number: ";
cin>>x;
cout<< "Enter second number: ";
cin>>y;
cout<< "Enter third number: ";
cin>>z;
cout<<"Sum="<<x+y+z;

cout<<" Product="<<x*y*z;

cout<<" Average="<<(x+y+z)/3<<endl;

return 0;
}
Result;
Enter first number: 10
Enter second number: 20
Enter third number: 30
Sum=60 Product=6000 Average=20
7. Compute for a grade of student given the formula Grade=10% Assign +20%
Seatwork+30% Quiz+40% Exam.

#include <iostream>
using namespace std;
int main()
{
float A, S, Q, E;
float Final_Grade;

cout << "Enter assignment: ";


cin >> A;
cout << "Enter seatwork: ";
cin >> S;
cout << "Enter quiz: ";
cin >> Q;
cout << "Enter exam: ";
cin >> E;

Final_Grade = (A*0.10) + (S*0.2) + (Q*0.3) + (E*0.4);


cout << "Final_Grade: " << Final_Grade;
return 0;
}
Result;
Enter assignment: 95
Enter seatwork: 85
Enter quiz: 82
Enter exam: 89
Final_Grade: 86.7

8. Accept a dollar value and print the equivalent peso value. The program will
convert dollar to peso having the exchange rate of 1 is to 50.00

#include <iostream>
using namespace std;
int main()
{
int dollars;
float P;

cout<<"Enter American Dollar:"<<endl;


cin>>dollars;

P=dollars*50.00;

cout << dollars << " American dollars are equal to " << P << "Pesos" <<endl;

return 0;
}
Result;
Enter American Dollar:
70
70 American dollars are equal to 3500Pesos

9. Develop a program that computes the area of the triangle.

#include <iostream>
using namespace std;
int main()
{
int height, base;
float result;

cout<< "Enter height: ";


cin>> height;
cout<< "Enter base: ";
cin>> base;

result = (0.5)*height*base;
cout<< "Area of triangle is: " <<result;
return 0;
}
Result;
Enter height: 69
Enter base: 99
Area of triangle is: 3415.5

10. Develop a program that computes the area and perimeter of the rectangle.

#include <iostream>
using namespace std;
int main()
{
float width, length, area, perimeter;
cout << "\n\n Find the Area and Perimeter of a Rectangle :\n";
cout<<"______________________________________________\n";
cout<< "Input the length of the rectangle: ";
cin>>length;
cout<< "Input the width of the rectangle: ";
cin>>width;

area=(length*width);
perimeter=2*(length+width);

cout<<"The area of the rectangle is : "<< area << endl;


cout<<"The perimeter of the rectangle is : "<< perimeter << endl;
return 0;
}
Result;
Find the Area and Perimeter of a Rectangle :
_____________________________________
Input the length of the rectangle : 45
Input the width of the rectangle : 54
The area of the rectangle is : 2430
The perimeter of the rectangle is : 198

You might also like