You are on page 1of 5

PANGASINAN STATE UNIVERSITY

URDANETA CITY CAMPUS


COLLEGE OF ENGINEERING AND ARCHITECTURE
DEPARTMENT OF MECHANICAL ENGINEERING
ACADEMIC YEAR 2023-2024, FIRST SEMESTER

Submitted by: Submitted to:


Mabanta Brian R. Engr. Miguel Albert D. Calizar
2 LABORATORY REPORT BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING

LABORATORY ACTIVITY NO. 13.1


Conditional Statements Programming Activity
(If…Else)

OBJECTIVE: To design a program that will ask the user for numbers and will perform selected
arithmetic operation using If..Else Condition.

PROCEDURE: Using If…Else Conditional Statements, design a program that will ask the user
for two numbers and which operation they would like to choose – addition, subtraction,
multiplication, division, or average.

Sample Output:

PROGRAM: (Paste here your line of codes)

#include <iostream>

int main() {

// Declare variables

double num1, num2;

char operation;

// Ask the user for input

std::cout << "Enter two numbers separated by space: ";

std::cin >> num1 >> num2;

PANGASINAN STATE UNIVERSITY REGION’S PREMIER UNIVERSITY OF CHOICE


3 LABORATORY REPORT BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING

// Display a blank space

std::cout << " " << std::endl;

// Display operations menu

std::cout << "OPERATIONS\n";

std::cout << "a. Addition\n";

std::cout << "b. Subtraction\n";

std::cout << "c. Multiplication\n";

std::cout << "d. Division\n";

std::cout << "e. Average\n";

// Ask the user to choose an operation

std::cout << "Which operation do you want? ";

std::cin >> operation;

// Display a blank space

std::cout << " " << std::endl;

// Perform the selected operation and display the result

if (operation == 'a') {

std::cout << "The sum of " << num1 << " and " << num2 << " is " << num1 + num2 << "."
<< std::endl;

} else if (operation == 'b') {

std::cout << "The difference of " << num1 << " and " << num2 << " is " << num1 - num2
<< "." << std::endl;

} else if (operation == 'c') {

std::cout << "The product of " << num1 << " and " << num2 << " is " << num1 * num2 <<
"." << std::endl;

} else if (operation == 'd') {

if (num2 != 0) {

std::cout << "The quotient of " << num1 << " and " << num2 << " is " << num1 / num2
<< "." << std::endl;

} else {

PANGASINAN STATE UNIVERSITY REGION’S PREMIER UNIVERSITY OF CHOICE


4 LABORATORY REPORT BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING

std::cout << "Cannot divide by zero." << std::endl;

} else if (operation == 'e') {

std::cout << "The average of " << num1 << " and " << num2 << " is " << (num1 + num2) / 2
<< "." << std::endl;

} else {

std::cout << "Invalid operation selected." << std::endl;

return 0;

OUTPUT: (Screenshot your final output)

CONCLUSION:

PANGASINAN STATE UNIVERSITY REGION’S PREMIER UNIVERSITY OF CHOICE


5 LABORATORY REPORT BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING

LABORATORY ACTIVITY NO. 13.2


Conditional Statements Programming Activity
(Switch…Case)

OBJECTIVE: To design a program that will ask the user for numbers and will perform selected
arithmetic operation using Switch…Case Condition.

PROCEDURE: Using Switch…Case Conditional Statements, design a program that will ask the
user for two numbers and which operation they would like to choose – addition, subtraction,
multiplication, division, or average.

Sample Output:

PROGRAM: (Paste here your line of codes)

OUTPUT: (Screenshot your final output)

CONCLUSION:

PANGASINAN STATE UNIVERSITY REGION’S PREMIER UNIVERSITY OF CHOICE

You might also like