Found 26504 Articles for Server Side Programming

C++ program to overload extraction operator

Arnab Chakraborty
Updated on 07-Oct-2021 08:45:04

464 Views

Suppose we have a Person class with two attributes first_name and the last_name. It also has two methods called get_first_name() and get_last_name() to retrieve or set first name and last name respectively. We shall have to overload the extraction operator (

Program to find minimum time to finish all jobs in Python

Arnab Chakraborty
Updated on 07-Oct-2021 08:49:16

851 Views

Suppose we have an array called jobs, where jobs[i] indicates the amount of time needed to complete the ith job. We also have another value k, to them we can assign jobs. Each job should be assigned to exactly one worker. And the working time of a worker is the total time it takes to complete all jobs assigned to them. We have to find the minimum possible maximum working time of any assignment.So, if the input is like jobs = [2, 1, 3, 8, 5], k = 2, then the output will be 10 because, we can assign jobs ... Read More

C++ program to find maximum of each k sized contiguous subarray

Arnab Chakraborty
Updated on 07-Oct-2021 08:42:37

449 Views

Suppose we have an array with n elements and a value k. We shall have to find maximum value for each of the contiguous subarray of size k.So, if the input is like arr = [3, 4, 6, 2, 8], k = 3, then the output will be The contiguous subarrays of size 3 are [3, 4, 6], [4, 6, 2], [6, 2, 8], so the maximum elements are 6, 6 and 8.To solve this, we will follow these steps −Define one deque Qi of size kfor initialize i := 0, when i < k, update (increase i by 1), ... Read More

C++ program to define exception for small username, and validate username

Arnab Chakraborty
Updated on 07-Oct-2021 08:40:06

825 Views

Suppose we have a string of usernames and we shall have to check whether username is valid or not based on few conditions. So we shall have to define an exception that is thrown when the length of username is less than 5 characters long. We shall have to return "Valid" for valid username, "Invalid" for invalid username and throw exception for smaller usernames. The valid username conditions are −Username must be five-character longThere should not two consecutive 'w' in the usernameSo, if the input is like unames = ["amit", "to", "paul_tim", "greg_harry", "towwer"], then the output will be [Too ... Read More

C++ program to overload addition operator to add two complex numbers

Arnab Chakraborty
Updated on 31-Oct-2023 02:59:44

36K+ Views

Suppose we have a complex number class with real and imaginary part. We shall have to overload the addition (+) operator to add two complex number. We also have to define a function to return complex number in proper representation.So, if the input is like c1 = 8 - 5i, c2 = 2 + 3i, then the output will be 10 - 2i.To solve this, we will follow these steps −Overload the + operator and take another complex number c2 as argumentdefine a complex number called ret whose real and imag are 0real of ret := own real + real ... Read More

C++ program to add different items with class templates

Arnab Chakraborty
Updated on 07-Oct-2021 08:34:01

700 Views

Suppose we want to make a class that can add two integers, two floats and two strings (string addition is basically concatenating strings). As input at first we take a number n represents there are n different operations. In each operation the first item is the type [int, float, string] and second and third are two operands. So each line will contain three elements. We shall have to read them and do the operations as mentioned.So, if the input is like5 int 5 7 int 6 9 float 5.25 9.63 string hello world string love C++then the output will be12 ... Read More

C++ program to create one rectangle class and calculate its area

Arnab Chakraborty
Updated on 07-Oct-2021 08:32:01

31K+ Views

Suppose we have taken length and breadth of two rectangles, and we want to calculate their area using class. So we can make a class called Rectangle with two attributes l and b for length and breadth respectively. And define another function called area() to calculate area of that rectangle.So, if the input is like (10, 9), (8, 6), then the output will be 90 and 48 as the length and breadth of first rectangle is 10 and 9, so area is 10 * 9 = 90, and for the second one, the length and breadth is 8 and 6, ... Read More

C++ program to test inheritance through triangle class

Arnab Chakraborty
Updated on 07-Oct-2021 08:29:55

485 Views

Suppose we want to make one Triangle class and another child class called Isosceles. The triangle class has a function that prints that the object is of type triangle, and Isosceles has two functions to show that it is an isosceles triangle and one description. We also need to call the parent class function through Isosceles class object. There is no such proper input, we just call functions in proper way.So, if the input is like define an object called trg, then call trg.isosceles(), trg.description(), trg.triangle()., then the output will beThis is an isosceles triangleThere are two sides are equal ... Read More

C++ program to store student roll and name using map STL

Arnab Chakraborty
Updated on 07-Oct-2021 08:27:18

1K+ Views

Suppose we have a map data structure for students roll and name the roll is an integer data and name is string type data. In our standard input we provide n queries. In each query (in each line) there must be two elements and for type 1 query there are three elements. First one is the operator, second one is the roll and third one is the name, for two elements query the second item is the roll number. The operations are like below−Insert. This will insert the name into the map at corresponding rollDelete. This will delete the against ... Read More

Program to find number of distinct subsequences in Python

Arnab Chakraborty
Updated on 07-Oct-2021 08:45:11

828 Views

Suppose we have a string s, we have to count the number of distinct subsequences of the string s. If the answer is too large then return result modulo 10^9 + 7.So, if the input is like s = "bab", then the output will be 6 because there are 6 different sequences, these are "a", "b, "ba", "ab", "bb", "abb".To solve this, we will follow these steps −dp := an array whose size is same of s and filled with 0m := 10^9 + 7for each index i and item char in s, doind := index of i-th char in ... Read More

Advertisements