Found 7347 Articles for C++

Implementation of a Falling Matrix in C++

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

436 Views

We have seen falling matrix scene in different films etc. Here we will see how to write a C++ program to do like that.To solve this problem, we have to care about these steps.Define width of the matrixTwo successive characters may or may not have same amount of gap between themA certain amount of delay between printing each line to visualize the falling effect.Example#include #include #include #include #include #include const int wd = 70; //set the width of the matrix window const int flipsPerLine =5; //five flips for the boolean array 'alternate' const int sleepTime = 50; //it will take ... Read More

Rint(), rintf(), rintl() in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

94 Views

Here we will see three functions. These functions are Rint(), rintf() and the rintl(). These functions are used to convert floating point values into rounded format.The rint() FunctionThis function is used for rounding floating point value to integer. The syntax is like below. If the result is outside of return type, the domain error may occur. When the argument is 0 or infinity, then it will return unmodifiedfloat rint(float argument) double rint(double argument) long double rint(long double argument)Example#include #include using namespace std; main() {    double a, b, x, y;    x = 53.26;    y = 53.86; ... Read More

Catch block and type conversion in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

103 Views

In this section, we will see how to use the catch block for exception handling and the type conversion in C++.At first, let us see a code, and we will see what will be the output, and how they are generating.Example#include using namespace std; int main() {    try{       throw 'a';    }    catch(int a) {       cout

How to launch a program using C++ program?

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

2K+ Views

Here we will see how to start some third-party application like notepad or anything using C++ program. This program is very simple, we can use command prompt command to do this task.We will pass the application name inside the system() function. This will open it accordingly.Example#include using namespace std; int main() {    cout >> "Opening Nodepad.exe" >> endl;    system("notepad.exe"); }Output

Determining how many digits there are in an integer in C++

karthikeya Boyini
Updated on 31-Oct-2023 02:43:30

26K+ Views

Here we will see how to check how many digits are there in an integer in C++. At first we will see the traditional rule, then see one short method to find.In the first method, we will reduce the number using dividing it by 10. And count until the number reaches to 0.Example#include using namespace std; int count_digit(int number) {    int count = 0;    while(number != 0) {       number = number / 10;       count++;    }    return count; } int main() {    cout >> "Number of digits in 1245: ... Read More

How to get memory usage under Linux in C++

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

2K+ Views

Here we will see how to get the memory usage statistics under Linux environment using C++.We can get all of the details from “/proc/self/stat” folder. Here we are taking the virtual memory status, and the resident set size.Example#include #include #include #include #include using namespace std; void mem_usage(double& vm_usage, double& resident_set) {    vm_usage = 0.0;    resident_set = 0.0;    ifstream stat_stream("/proc/self/stat", ios_base::in); //get info from proc    directory    //create some variables to get info    string pid, comm, state, ppid, pgrp, session, tty_nr;    string tpgid, flags, minflt, cminflt, majflt, cmajflt;    string ... Read More

What is the difference between size_t and int in C++?

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

5K+ Views

Here we will see what are the differences between size_t and int in C++. If we consider the standard, both are integers of size 16 bits.On a typical 64-bit system, the size_t will be 64-bit, but unsigned int will be 32 bit. So we cannot use them interchangeably.One standard recommendation is that the size_t be at most as big as an unsigned long. So you may think that we can use unsigned long in the place of size_t, but unsigned long on 64-bit system, if the OS ins Windows, will be of 32-bits, but size_t will be of 64-bits.Read More

Functions that can’t be overloaded in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

272 Views

In C++, we can overload the functions. But sometimes the overloading is not done. In this section, we will see what are the different cases, in which we cannot overload the functions.When function signatures are same, only the return type is different, then we cannot overload the function.int my_func() {    return 5; } char my_func() {    return 'd'; }When the member functions have the same name and same parameter list in a class, then they cannot be overloaded.class My_Class{    static void func(int x) {       //Something    }    void func(int x) {     ... Read More

Lexicographically next permutation in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

2K+ Views

Here we will see how to generate lexicographically next permutation of a string in C++. The lexicographically next permutation is basically the greater permutation. For example, the next of “ACB” will be “BAC”. In some cases, the lexicographically next permutation is not present, like “BBB” or “DCBA” etc.In C++ we can do it by using a library function called next_permutation(). This is present in the algorithm header file.Example#include #include using namespace std; main() {    string s = "DBAC";    for(int i = 0; i

How to initialize a const field in constructor?

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

687 Views

Here we will see how to initialize the const type variable using constructor?To initialize the const value using constructor, we have to use the initialize list. This initializer list is used to initialize the data member of a class. The list of members, that will be initialized, will be present after the constructor after colon. members will be separated using comma.Example#include using namespace std; class MyClass {    private:    const int x;    public:       MyClass(int a) : x(a) {          //constructor       }       void show_x() {   ... Read More

Advertisements