Docsity

C++ Math Programs: Circle & Rectangle Area, Multiplication, Power, Time Conversion, Assignments of Object Oriented Programming

Toggle sidebar
bg1
Code 1
#include<iostream>
#include<cstdlib>
using namespace std;
float area(float r)
{
return(3.14 * r * r);
}
float area(float l, float b)
{
return (l * b);
}
float area(int length)
{
return(4 * length);
}
int main()
{
float b, r, l ,length;
cout << "Radius of Circle : ";
cin >> r;
cout << "\n Area of Circle : " << area(r)<<endl<<endl;
cout << "Length : ";
cin >> l ;
cout << "Breath: ";
cin >> b;
cout << "\n Area of Rectangle : " << area(l, b)<<endl<<endl;
cout << "Length of square: ";
cin >> length;
cout << "\n Area of square : " << area(length)<<endl;
system("pause");
return 0;
}
Output
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download C++ Math Programs: Circle & Rectangle Area, Multiplication, Power, Time Conversion and more Assignments Object Oriented Programming in PDF only on Docsity!

Code 1

#include #include using namespace std; float area(float r) { return(3.14 * r * r); } float area(float l, float b) { return (l * b); } float area(int length) { return(4 * length); } int main() { float b, r, l ,length; cout << "Radius of Circle : "; cin >> r; cout << "\n Area of Circle : " << area(r)<<endl<<endl; cout << "Length : "; cin >> l ; cout << "Breath: "; cin >> b; cout << "\n Area of Rectangle : " << area(l, b)<<endl<<endl; cout << "Length of square: "; cin >> length; cout << "\n Area of square : " << area(length)<<endl; system("pause"); return 0; }

Output

Code 2

#include using namespace std; int multiplication(int n1, int n2) { int result = n1n2; return result; } float multiplication(float n1, float n2) { float result = n1n2; return result; } double multiplication(double n1, double n2) { double result = n1*n2; return result; } int main() { int a, b; float x, y; double n1, n2; cout << "enter two numbers of integer type \n"; cin >> a>>b; cout << "enter two number of float type\n"; cin >> x; cin >> y; cout << "enter two numbers of type double\n"; cin >> n1; cin >> n2; int result1 = multiplication(a,b); cout << "multiplication of two integer type numbers\n" << a << " * " << b << " = " << result1 << endl; float result2 = multiplication(x,y); cout << "multiplication of two float type numbers\n" << x << " * " << y << " = " << result2 << endl; double result3 = multiplication(n1,n2); cout << "multiplyication of two double type numbers\n" << n1 << " * " << n2 << " = " << result3 << endl; system("pause"); return 0; }

Code 3

#include #include using namespace std; double power(double number, int power) { double result = number; for (int i = 1; i < power; i++) { result = number*result; } return result; } int main() { int p; double num; cout << "NUMBER:"; cin >> num; cout << "POWER:"; cin >> p; double result = power(num, p); cout << num << " ^ " << p << " = " << result << endl; system("pause"); return 0; }

Output

Code 4

#include using namespace std; int power(int number, int power) { int result = number; for (int i = 1; i < power; i++) { result = numberresult; } return result; } float power(float number, int power) { float result = number; for (int i = 1; i < power; i++) { result = numberresult; } return result; } double power(double number, int power) { double result = number; for (int i = 1; i < power; i++) { result = numberresult; } return result; } char power(char number, int power) { int ch = char(number); for (int i = 1; i < power; i++) { ch = numberch; } char x = int(ch); return ch; } int main() { int number1,Power; float number2; double number3; char ch; cout << "Integer number:"; cin >> number1; cout << "Float number:"; cin >> number2; cout << "Double type number:"; cin >> number3; cout << "Character:"; cin >> ch; cout << "Power:"; cin >> Power;

int main() { int a, b; cout << "ENTER THE VALUE OF A:"; cin >> a; cout << "ENTER THE VALUE OF B:"; cin >> b; double res = zerosmaller(a, b); if(a>b) cout << "vaue of B: " << res << endl; else cout << "vaue of A: " << res << endl; system("pause"); return 0; }

Output

Code 6

#include #include using namespace std; double distance(int d1,int d2) { double result ; if (d1 > d2) { result = d1; } else result = d2; return result; } int main() { int x, y; cout << "Distance1: "; cin >> x; cout << "Distance2: "; cin >> y; double result = distance(x, y); cout << "LARGER DISTANCE IS " << result << endl; system("pause"); return 0; }

Output

Code 7