Found 34494 Articles for Programming

Can main function call itself in C++?

Chandu yadav
Updated on 26-Jun-2020 13:24:19

1K+ Views

The main() function can call itself in C++. This is an example of recursion as that means a function calling itself. A program that demonstrates this is given as follows.Example Live Demo#include using namespace std; int main() {    static int x = 1;    cout

What is the meaning of prepended double colon “::” in C++?

George John
Updated on 26-Jun-2020 13:26:44

6K+ Views

The prepended double colon is also known as the scope resolution operator. Some of the uses of this operator are given as follows.Define a function outside a classThe scope resolution operator can be used to define a function outside a class. A program that demonstrates this is given as follows.Example Live Demo#include using namespace std; class Example {    int num;    public:    Example() {       num = 10;    }    void display(); }; void Example::display() {    cout

Private and Protected Members in C++

Arjun Thakur
Updated on 26-Jun-2020 13:29:23

8K+ Views

A class in C++ has public, private and protected sections which contain the corresponding class members.The private data members cannot be accessed from outside the class. They can only be accessed by class or friend functions. All the class members are private by default.The protected members in a class are similar to private members but they can be accessed by derived classes or child classes while private members cannot.A program that demonstrates private and protected members in a class is given as follows −Example Live Demo#include using namespace std; class Base {    public :    int a = 8; ... Read More

Accessing protected members in a C++ derived class

Chandu yadav
Updated on 26-Jun-2020 13:30:35

17K+ Views

A class in C++ has public, private and protected sections which contain the corresponding class members. Protected members in a class are similar to private members as they cannot be accessed from outside the class. But they can be accessed by derived classes or child classes while private members cannot.A program that demonstrates accessing protected data members in a derived class in C++ is given as follows −Example Live Demo#include using namespace std; class Base {    protected :    int num = 7; }; class Derived : public Base {    public :    void func() {       cout

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

311 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

Advertisements