Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 29 of 44

Ordered Set and GNU C++ PBDS

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we will be discussing a program to understand ordered set and GNU C++ PBDS.Ordered set is a policy based structure other than those in the STL library. The ordered set keeps all the elements in a sorted order and doesn’t allow duplicate values.Example#include using namespace std; #include #include using namespace __gnu_pbds; #define ordered_set tree int main(){    //declaring ordered set    ordered_set o_set;    o_set.insert(5);    o_set.insert(1);    o_set.insert(2);    cout

Read More

Using class to implement Vector Quantities in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 244 Views

In this tutorial, we will be discussing a program to understand how to use class to implement vector quantities in C++.Vector quantities are the ones which have both magnitude and direction. Here we will be implementing them using classes and then performing basic operations on them.Example#include #include using namespace std; class Vector {    private:    int x, y, z;    //components of the Vector    public:    Vector(int x, int y, int z){       this->x = x;       this->y = y;       this->z = z;    }    Vector operator+(Vector v); ...

Read More

partition_point in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 169 Views

In this tutorial, we will be discussing a program to understand partition_point in C++.Partition point is a method which returns an iterator pointing to the first value in a given range. The range is a partitioned one in which the predicate is not true.Example#include #include #include bool IsOdd(int i) { return (i % 2) == 1; } int main(){    std::vector data{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };    std::vector odd, even;    std::stable_partition(data.begin(), data.end(), IsOdd);    auto it = std::partition_point(data.begin(), data.end(),    IsOdd);    odd.assign(data.begin(), it);    even.assign(it, data.end());    std::cout

Read More

Virtual destruction using shared_ptr in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 229 Views

In this tutorial, we will be discussing a program to understand virtual destruction using shared_ptr in C++.To delete the instances of a class, we define the destructor of the base class to be virtual. So it deletes the various object instances inherited in the reverse order in which they were created.Example#include #include using namespace std; class Base {    public:    Base(){       cout

Read More

Program to find area of a Circular Segment in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 281 Views

In this tutorial, we will be discussing a program to find area of a circular segment.Making a chord in a given sphere divides it into two segments - major and minor. Given the radius of the circle and angle making the minor segment, we are required to find the areas of both segments.Example#include using namespace std; float pi = 3.14159; //finding area of segment float area_of_segment(float radius, float angle){    float area_of_sector = pi * (radius * radius)*(angle / 360);    float area_of_triangle = (float)1 / 2 *(radius * radius) *     sin((angle * pi) / ...

Read More

Program to find century for a year in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 722 Views

In this tutorial, we will be discussing a program to find the century for a year.For this we will be provided with a year. Our task is to find the century in which the given year falls.Example#include using namespace std; void find_century(int year){    //year values can only be positive    if (year

Read More

Program to find Circumcenter of a Triangle in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 662 Views

In this tutorial, we will be discussing a program to find the circumcenter of a triangle.For this we will be provided with three noncollinear points. Our task is to find the circumcenter of the triangle formed by those points.Example#include #include using namespace std; //storing X and Y values #define pdd pair void lineFromPoints(pdd P, pdd Q, double &a, double &b, double &c){    a = Q.second - P.second;    b = P.first - Q.first;    c = a*(P.first)+ b*(P.second); } void perpendicularBisectorFromLine(pdd P, pdd Q, double &a, double &b, double &c){    pdd mid_point = make_pair((P.first + Q.first)/2, ...

Read More

Copy set bits in a range in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 492 Views

In this tutorial, we will be discussing a program to copy set bits of one number to another in the given range.For this we will be provided with two integers. Our task is to see the bits in the first number and set those bits in the second number as well if they are in the given range. Finally returning the digit produced.Example#include using namespace std; //copying set bits from y to x void copySetBits(unsigned &x, unsigned y, unsigned l, unsigned r){    //l and r should be between 1 and 32    if (l < 1 || r ...

Read More

Convex Hull Monotone chain algorithm in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 305 Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.Example#include #define llu long long int using namespace std; //structure for the given point struct Point {    llu x, y;    bool operator= t && calc_crossproduct(ans[k - 2],       ans[k - 1], A[i - 1])

Read More

Convex Hull using Divide and Conquer Algorithm in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.In this program, we will use brute force to divide the given points into smaller segments and then finally merging the ones that follow on to construct the convex hull.Example#include using namespace std; //storing the center point of polygon pair mid; //calculating the quadrant of //a particular point int quad(pair p){    if (p.first >= 0 && p.second >= 0)   ...

Read More
Showing 281–290 of 433 articles
« Prev 1 27 28 29 30 31 44 Next »
Advertisements