Es 132 Module 4
Es 132 Module 4
ZERDA
Course & Year: BSEE 1A
#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;
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;
cin >> b;
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
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Please enter an integer value for variable a ";
cin >> a;
cin >> b;
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;
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;
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
#include <iostream>
using namespace std;
int main()
{
int height, base;
float result;
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);