Found 34489 Articles for Programming

How to “return an object” in C++?

Ankith Reddy
Updated on 26-Jun-2020 13:34:14

4K+ Views

An object is an instance of a class. Memory is only allocated when an object is created and not when a class is defined.An object can be returned by a function using the return keyword. A program that demonstrates this is given as follows −Example Live Demo#include using namespace std; class Point {    private:    int x;    int y;    public:    Point(int x1 = 0, int y1 = 0) {       x = x1;       y = y1;    }    Point addPoint(Point p) {       Point temp;       temp.x = x + p.x;       temp.y = y + p.y;       return temp;    }    void display() {       cout

What is the lifetime of a static variable in a C++ function?

Arjun Thakur
Updated on 26-Jun-2020 13:35:45

16K+ Views

A static variable is a variable that is declared using the keyword static. The space for the static variable is allocated only one time and this is used for the entirety of the program.Once this variable is declared, it exists till the program executes. So, the lifetime of a static variable is the lifetime of the program.A program that demonstrates a static variable is given as follows.Example Live Demo#include using namespace std; void func() {    static int num = 1;    cout

When should you use a class vs a struct in C++?

Chandu yadav
Updated on 26-Jun-2020 13:36:53

326 Views

Structures and classes are very similar in C++ except for some differences. So details about these differences are given below that help to decide when to use a class or structure in C++.Differences between Class and StructureAll the members of a class are private by default. This is different compared to structures as all the members of a structure are public by default.A program that demonstrates a class in C++ is given as follows −Example#include using namespace std; class Example {    int val; }; int main() {    Example obj;    obj.val = 20;    return 0; }This ... Read More

Thread-based parallelism in Python

Samual Sam
Updated on 26-Jun-2020 12:51:03

312 Views

A thread in computer science is a set of instructions that can be managed independently by a scheduler, which is a part of operating system.The main function of Threading is to run multiple threads at a time. Threads means different tasks, function calls in the program and multiple threads run at the same time that does not means that they are executed on different machines.Multi-threading is used in two cases.When the outputs of the sub-programs need to combined with main program.When main program contains piece of code that are relatively independent of each other.Threading modulePython provides Threading module which is ... Read More

Text Analysis in Python3

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

184 Views

In this assignment we work with files. Files are everywhere in this Universe. In computer system files are essential part. Operating system consists a lot of files. Python has two types of files-Text Files and Binary Files. Here we discuss about Text Files Here we focus some of the important functions on files. Number of words Number of characters Average word length Number of stop words Number of special characters Number of numeric Number of uppercase words We have a test file "css3.txt", we are working on that file Number of words When we count number of ... Read More

Morse Code Translator in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Morse Code Translator is used in Cryptography. It is named by Samuel F. B. Morse. By this technique we convert a message to a series of dots, commas, "-", "/". This technique is very simple. Every alphabet in English signifies a series of ".", ", ", "/", "-". We just encrypt the message from message to symbols and decrypt from symbols to English. The dictionary is given below 'A':'.-', 'B':'-...', 'C':'-.-.', 'D':'-..', 'E':'.', 'F':'..-.', 'G':'--.', 'H':'....', 'I':'..', 'J':'.---', 'K':'-.-', 'L':'.-..', 'M':'--', 'N':'-.', 'O':'---', 'P':'.--.', 'Q':'--.-', 'R':'.-.', 'S':'...', 'T':'-', 'U':'..-', 'V':'...-', 'W':'.--', 'X':'-..-', 'Y':'-.--', 'Z':'--..', '1':'.----', '2':'..---', '3':'...--', '4':'....-', '5':'.....', ... Read More

Using CX_Freeze in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

883 Views

Sometimes we feel to create something different which is very exciting, and according to human nature, we always love to share it. Python also fulfills those wishes. Using Python, if we want to share our Python program with our friends we can do that, only need to have the same version of Python installed with all the modules those are used in program of their machine. First we need to install CX_Freeze module using pip install CX_Frezze command in command prompt. First step is to solve this assignment, a python program conversion. We need standard library modules, here we ... Read More

Multiprocessing In Python

Samual Sam
Updated on 26-Jun-2020 12:43:27

4K+ Views

The multiprocessing package supports spawning processes. It refers to a function that loads and executes a new child processes. For the child to terminate or to continue executing concurrent computing, then the current process hasto wait using an API, which is similar to threading module.IntroductionWhen we work with Multiprocessing, at first we create process object. Then it calls a start() method.Example codefrom multiprocessing import Process    def display():       print ('Hi !! I am Python')       if __name__ == '__main__':       p = Process(target=display)       p.start()       p.join()In this example, ... Read More

Tweet using Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

132 Views

Before using Tweet in Python, we have to follow some steps. Step1 − at first we must have a tweeter profile and then it has to be added with our mobile number. First go to - Settings -> Add Phone -> Add number -> Confirm -> Save. We have to follow these steps. Then turn off all text notifications. Step2 − Set up a new app. Follow − Twitter Apps -> Create New App -> Leave Callback URL empty -> Create Twitter application. Then display message "Your application has been created. You review and adjust your application's settings". Step3 − ... Read More

Synchronization and Pooling of processes in Python

Samual Sam
Updated on 26-Jun-2020 12:44:50

587 Views

Synchronization between processesMultiprocessing is a package which supports spawning processes using an API. This package is used for both local and remote concurrencies. Using this module, programmer can use multiple processors on a given machine. It runs on Windows and UNIX os.All equivalent synchronization primitives are present in this package.Example codefrom multiprocessing import Process, Lock    def my_function(x, y):       x.acquire()       print ('hello world', y)       x.release()       if __name__ == '__main__':       lock = Lock()    for num in range(10): Process(target= my_function, args=(lock, num)).start()Here one instance can lock ... Read More

Advertisements