Computer Programing Fundamental
BSCE - 106 ( Group #3 )
FOR PLANE FIGURES
● TRIANGLE (Kenshin)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'd':
{
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============TRIANGLE===============" << endl;
cout << endl;
int choice;
float base, height, side1, side2, side3;
cout << "Triangle Area Calculator\n";
cout << "1. Calculate area using base and height\n";
cout << "2. Calculate area using three sides\n";
cout << "Enter your choice: ";
cin >> choice;
if ( choice == 1 ) {
float calculateArea, base, height;
calculateArea = (base * height) / 2;
cout << "Enter the base length: ";
cin >> base;
cin >> Unit1;
cout << "Enter the height: ";
cin >> height;
cin >> Unit2;
if (Unit1 == Unit2) {
cout << "The area of the triangle is: " << calculateArea << Unit1 << endl;}
else {
cout << "Error. Please check your Unit.";
}
break;
}
else if ( choice == 2) {
int calculateArea, side1, side2, side3, s;
s = (side1 + side2 + side3) / 2;
calculateArea = sqrt(s * (s - side1) * (s - side2) * (s - side3));
cout << "Enter the length of side 1: ";
cin >> side1;
cin >> Unit1;
cout << "Enter the length of side 2: ";
cin >> side2;
cin >> Unit2;
cout << "Enter the length of side 3: ";
cin >> side3;
cin >> Unit3;
if (Unit1 == Unit2 && Unit2 == Unit3 && Unit3 == Unit1 ) {
cout << "The area of the triangle is: " << calculateArea << Unit1 << endl;}
else {
cout << "Error. Please check your Unit.";
}
}
break;
}
● TRAPEZOID (kenshin)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'e': {
float calculateArea, base1, base2, height;
calculateArea = 0.5 * (base1 + base2) * height;
cout << "Trapezoid Area Calculator\n";
cout << "Enter the length of the first base: ";
cin >> base1;
cin >> Unit1;
cout << "Enter the length of the second base: ";
cin >> base2;
cin >> Unit2;
cout << "Enter the height: ";
cin >> height;
cin >> Unit3;
if (Unit1 == Unit2 && Unit2 == Unit3 && Unit3 == Unit1 ) {
cout << "The area of the trapezoid is: " << calculateArea << Unit1 << endl;}
else {
cout << "Error. Please check your Unit.";
}
break;
}
● RHOMBUS ( sharmaine )
A=d1 x d2/2
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'R':
float diagonal1, diagonal2, area;
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============Rhombus===============" << endl;
cout << endl;
cout << "Enter the length of the first diagonal: ";
cin >> diagonal1;
cout << "Enter the length of the second diagonal: ";
cin >> diagonal2;
area = (diagonal1 * diagonal2) / 2;
cout << "The area of the Rhombus is: " << area << endl;
break;
}
return 0;
A= base × height
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'R':
float base, height, area;
cout << endl;
cout << "===============Rhombus===============" << endl;
cout << endl;
cout << "Enter the length of the base: ";
cin >> base;
cout << "Enter the height of the rhombus: ";
cin >> height;
area = base * height;
cout << "The area of the Rhombus is: " << area << endl;
break;
}
return 0;
A= side^2 × sin(A)
A= side^2 × sin(B)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'R':
float side, angle, area;
cout << endl;
cout << "===============Rhombus===============" << endl;
cout << endl;
cout << "Enter the length of a side: ";
cin >> side;
cout << "Enter the measure of an angle in degrees: ";
cin >> angle;
angle = angle * M_PI / 180.0;
area = side * side * sin(angle);
cout << "The area of the rhombus is: " << area << endl;
break;
}
return 0;
}
● PARALLELOGRAM ( Joseph )
- A = base x height
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'g': {
float Base, Height, area;
cout << endl;
cout << "===============PARALLELOGRAM===============" << endl;
cout << endl;
cout << "Enter the length of the Base: ";
cin >> Base;
cout << "Enter the length of the Height: ";
cin >> Height;
area = (Base * Height);
cout << "The area of the Parallelogram is: " << area << endl;
break;
}
return 0;
}
● POLYGON (Rowena)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
char figure;
cin >> figure;
switch (figure) {
case 'h':
{
int numSides;
double sideLength, apothem;
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============(POLYGON)===============" << endl;
cout << endl;
cout << "Enter the number of sides of the polygon: ";
cin >> numSides;
cout << "Enter the length of one side of the polygon: ";
cin >> sideLength;
cout << "Enter the apothem of the polygon: ";
cin >> apothem;
double area = (numSides * sideLength * apothem) / 2.0;
cout << "Area of the polygon: " << area << endl;
break;
}
}
FOR SOLID FIGURES
● SPHERE (ghelbern)
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case 'i':
{
float radius, radius_cube, volume ;
cout << endl;
cout << "Please enter the radius : " << endl;
cin >> radius_cube;
cout << endl;
cout << "===============Sphere===============" << endl;
cout << endl;
radius_cube == radius * radius * radius;
volume == (4.0/3.0) * 3.1416 * radius_cube;
cout << "The volume of sphere is : " << volume << endl;
break;
}
}
return 0;
}
● CUBE (karl)
V = s³
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case 'j':
{cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
float side_length,volume;
cout << endl;
cout << "===============CUBE===============" << endl;
cout << endl;
cout << "Enter the side length of the cube: ";
cin >> side_length;
volume = side_length * side_length * side_length;
cout << "Volume of the cube: " << volume << endl;
break;
}
}
return 0;
}
● PYRAMID (ericka)
TRIANGULAR- ⅓ (base area) (height)
RECTANGULAR- ⅓ (length) (width) (height)
HEXAGONAL- √3/2 (base²) (height)
SQUARE- ⅓ (base²) (height)
PENTAGONAL- ⅚ (apothem) (base) (height)
CODE
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case 'k':
{
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============PYRAMID===============" << endl;
cout << endl;
char shape;
float apothem, base, width, base_length, height, base_area, volume;
cout << "Choose a shape base pyramid: " << endl;
cout << "[a] Triangular [d] Square " << endl;
cout << "[b] Rectangular [e] Pentagonal" << endl;
cout << "[c] Hexagonal" << endl;
cout << "Enter your Shape Base of the Pyramid below " << endl;
cout << "Shape: ";
cin >> shape;
if (shape == 'a') {
cout << "Enter the base area and height of the given problem " << endl;
cout << "Base area: ";
cin >> base_area;
cout << "Height: ";
cin >> height;
volume = (1.0 / 3) * base_area * height;
} else if (shape == 'b') {
cout << "Enter base length, width, and height: " << endl;
cout << "Base Length: ";
cin >> base_length;
cout << "Width: ";
cin >> width;
cout << "Height: ";
cin >> height;
volume = (base_length * width * height)/3;
} else if (shape == 'c') {
cout << "Enter the base length and height of the given problem " << endl ;
cout << "Base length: ";
cin >> base_length;
cout << "Height: ";
cin >> height;
volume = (sqrt(3.0) / 2) * (base_length, 2) * height;
} else if (shape == 'd') {
cout << "Enter the base length and height of the given problem " << endl;
cout << "Base Length: ";
cin >> base_length;
cout << "Height: ";
cin >> height;
volume = (1.0 / 3) * (base_length, 2) * height;
} else if (shape == 'e') {
cout << "Enter apothem, base, and height of the given problem" << endl;
cout << "Apothem: ";
cin >> apothem;
cout << "Base: ";
cin >> base;
cout << "Height: ";
cin >> height;
volume = (5.0 / 6) * apothem * base * height;
} else {
cout << endl;
cout << "Error!" << endl;
cout << "Please check your input before submitting, Thank you" << endl;
return 1;
}
cout << "Volume of the Shape Base Pyramid is: " << volume << endl;
break;
}
}
return 0;
}
● PRISM (De Guia)
Rectangular Prism- length x width x height
Heptagonal Prism- 7/4 (apothem ²) (π/7) height
Hexagonal Prism- 3 x apothem x base edge x height
Square Prism- base edge² x length
Triangular Prism- 1/2 base edge x height x length
Octagonal Prism- 2(1+√2) base edge² x height
Pentagonal Prism- 5/2 apothem x base edge x height
CODING:
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case 'j':
{
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============PRISM===============" << endl;
cout << endl;
char shape;
float apothem, base,width, height, length, base_edge, volume;
cout << "Choose a shape base prism: " << endl;
cout << "[a] Square [e] Rectangular " << endl;
cout << "[b] Triangular [f] Pentagonal" << endl;
cout << "[c] Hexagonal [g] Heptagonal" << endl;
cout << "[d] Octagonal " << endl;
cout << "Enter your shape base of the Prism" << endl;
cout << "Shape: ";
cin >> shape;
if (shape == 'a') {
cout << "Enter the base edge and length " << endl;
cout << "Base edge: ";
cin >> base_edge;
cout << "length: ";
cin >> length;
volume = base_edge*base_edge*length;
} else if (shape == 'b') {
cout << "Enter base edge, height, and length: " << endl;
cout << "Base Edge: ";
cin >> base_edge;
cout << "Height: ";
cin >> height;
cout << "Length: ";
cin >> length;
volume = 0.5*base_edge*height*length;
} else if (shape == 'c') {
cout << "Enter the apothem,base edge and height " << endl ;
cout << "Apothem:";
cin >> apothem;
cout << "Base edge: ";
cin >> base_edge;
cout << "Height: ";
cin >> height;
volume = 3*apothem*base_edge*height;
} else if (shape == 'd') {
cout << "Enter the base edge and height " << endl;
cout << "Base edge: ";
cin >> base_edge;
cout << "Height: ";
cin >> height;
volume = 2*2.414213562*base_edge*height;
} else if (shape == 'e') {
cout << "Enter length, width and height " << endl;
cout << "Length: ";
cin >> length;
cout << "Width: ";
cin >> width;
cout << "Height: ";
cin >> height;
volume = length*width*height;
} else if (shape == 'f') {
cout << "Enter length, width and height " << endl;
cout << "Length: ";
cin >> length;
cout << "Width: ";
cin >> width;
cout << "Height: ";
cin >> height;
volume = 2.5*apothem*base_edge*height;
} else if (shape == 'g') {
cout << "Enter base edge, height" << endl;
cout << "Base edge: ";
cin >> base_edge;
cout << "height: ";
cin >> height;
volume = 1.75*base_edge*base_edge*2.07652*height;
} else {
cout << endl;
cout << "Error!" << endl;
cout << "Check your input and try again!"<< endl;
return 1;
}
cout << "Volume of the shape base prism is: " << volume << endl;
break;
}
}
return 0;
}
● CONE (junrex)
case 'l':
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============(CONE)===============" << endl;
cout << endl;
float cn_Radius, cn_Height, cn_Volume;
cout << endl;
cout << "\nPlease Enter the Radius of a Cone = ";
cin >> cn_Radius;
cout << "\nPlease Enter the Height of a Cone = ";
cin >> cn_Height;
cn_Volume = (1.0 / 3.0) * M_PI * pow(cn_Radius, 2) * cn_Height;
cout << "\nThe Volume of a Cone = " << cn_Volume;
break;
}
● CYLINDER ( karl )
V = π r²
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case 'n':
{
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
float radius,height,volume;
cout << endl;
cout << "===============CYLINDER===============" << endl;
cout << endl;
cout << "Enter the radius of the cylinder: ";
cin >> radius;
cout << "Enter the height of the cylinder: ";
cin >> height;
if (radius==0 || height==0)
{
cout<<"invalid operation"<<endl;
}
if(radius!=0 && height!=0)
{
volume = (3.1416*radius*radius*height);
cout << "Volume of the cylinder: " << volume << endl;
break;
}
}
}
return 0;
}
GUIDE:
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
char figure;
cin >> figure;
switch (figure) {
case '(Letter of the Given Figure)':
{
int (for whole number)
float (With decimals)
char (per letter)
string (word)
cout << endl;
cout << "Please enter the Dimension needed." << endl;
cout << "For example: 123<space>inch" << endl;
cout << endl;
cout << "===============(GIVEN FIGURE)===============" << endl;
cout << endl;
(kayo na bahala mag dugtong dito) ( Formula code)
break;
}
}
return 0;
}