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

#Include #Define Using Namespace Int Int Double

The document contains code for a C++ program that acts as a geometry calculator. It presents the user with options to calculate the area of a circle, rectangle, or triangle by prompting the user for the necessary measurements for each shape. It also includes code examples demonstrating different ways to check if an integer is even or odd using an if/else statement, switch statement, and ternary operator.

Uploaded by

Jai Led Tan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

#Include #Define Using Namespace Int Int Double

The document contains code for a C++ program that acts as a geometry calculator. It presents the user with options to calculate the area of a circle, rectangle, or triangle by prompting the user for the necessary measurements for each shape. It also includes code examples demonstrating different ways to check if an integer is even or odd using an if/else statement, switch statement, and ternary operator.

Uploaded by

Jai Led Tan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

#define PI 3.14159
using namespace std;
int main()
{
int num;
double rad,area,length,width,height;
cout<<"Geometry Calculator \n";
cout<<"1.Calculate Area of a Circle. \n";
cout<<"2.Calculate Area of Rectangle. \n";
cout<<"3.Calculate Area of Triangle. \n";
cout<<"4.Quit. \n";
cout<<"Enter your choice (1-4):\n ";
cin>>num;
switch(num){
case 1:
cout<<"Enter the radius of the circle.\n";
cin>>rad;
area= PI*rad*rad;
cout<<"The area of the circle is "<< area<<endl;
break;
case 2:
cout<<"Enter the length of the rectangle .\n";
cin>>length;
cout<<"Enter the width of the rectangle .\n";
cin>> width;
area=length*width;
cout<<" The area of the rectangle is "<< area<<endl;
break;
case 3:
cout<<"Enter the length of the base of the triangle .\n";
cin>>length;
cout<<"Enter the height of the triangle .\n";
cin>>height;
area=(length*height)/2;
cout<<" The area of the triangle is "<< area<<endl;
break;
case 4:
cout<<"The program has ended.\n";
break;
default:
cout<< " Invalid choice.\n";

}
return 0;
}

#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a positive integer.\n";
cin>>num;
if(num%2==0)
cout<<"The number is even.\n";
else
cout<<"The number is odd.\n";
}

return 0;

#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a positive integer.\n";
cin>>num;
switch(num%2)
{
case 1:
cout<<"The number is odd.\n";
break;

default:
cout<<"The number is even.\n";
break;
}
return 0;

#include <iostream>

using namespace std;


int main()
{
int num;
cout<<"Enter a positive integer.\n";
cin>>num;
(num%2==0)?cout<<"The number is even.":cout<<"The number is odd.";
return 0;

}
#include <iostream>
using namespace std;
int main()
{
char alp;
cout<<"Enter a character.\n";
cin>>alp;
{if((alp>='a'||'A')&&(alp<='z'||'Z'))
cout<<"The character is an alphabet.\n";
else
cout<<"Other character.\n";
}

You might also like