Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions RightTriangleChecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// C++ program to check validity of triplets
#include <bits/stdc++.h>
using namespace std;

// Function to check pythagorean triplets
bool Triplets(long long a, long long b, long long c)
{
if (a <= 0 || b <= 0 || c <= 0)
return false;

vector<long long> vec{ a, b, c };
sort(vec.begin(), vec.end());

// Re-initialize a, b, c in ascending order
a = vec[0], b = vec[1], c = vec[2];

// Check validation of sides of triangle
if (a + b <= c)
return false;

long long p1 = a, p2 = c - b;

// Reduce fraction to simplified form
long long div = __gcd(p1, p2);
p1 /= div, p2 /= div;

long long q1 = c + b, q2 = a;

// Reduce fraction to simplified form
div = __gcd(q1, q2);
q1 /= div, q2 /= div;

// If fraction are equal return
// 'true' else 'false'
return (p1 == q1 && p2 == q2);
}

// Function that will return 'Yes' or 'No'
// according to the correction of triplets
string checkTriplet(long long a, long long b, long long c)
{
if (Triplets(a, b, c))
return "Yes,its a right angled triangle";
else
return "No,its not a right triangle";
}

// Driver code
int main()
{
long long a,b,c;
cout<<"Enter three sides:";
cin>>a>>b>>c;
cout << checkTriplet(a, b, c) << endl;
return 0;
}
70 changes: 70 additions & 0 deletions cellphonecompany.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <iostream>
#include <iomanip>

using namespace std;
double cost;

double regularBill()
{
int minutes;

cout << "Enter the number of minutes used: ";
cin >> minutes;

if (minutes <= 50)
minutes = 0;
else
minutes -= 50;

cost = 10 + minutes * 0.20;
return cost;
}

double premiumBill()
{
int minDay, minNight;
double costDay, costNight;

cout << "Enter the number of minutes used at day and at night (separated by spaces): ";
cin >> minDay >> minNight;

if (minDay <= 75)
minDay = 0;
else
minDay -= 75;
costDay = 0.10 * minDay;

if (minNight <= 100)
minNight = 0;
else
minNight -= 100;
costNight = 0.05 * minNight ;

cost = 10 + costDay + costNight;

return cost;
}
int main()
{
char service;
int accnum;
cout << "Enter account number: ";
cin >> accnum;
cout << "Enter 'r' for regular service or 'p' for premium service: ";
cin >> service;
cout << fixed << showpoint << setprecision(2);

if (service == 'r' || service == 'R')
{
cout << "Cost: $" << regularBill();
}
else if (service == 'p' || service == 'P')
{
cout << "Cost: $" << premiumBill();
}
else
cout << "Incorrect input. Try again later.";


return 0;
}