[Solved] What would be the most efficient way to find if a number n contains a specific number k?

If finding a count of how many times a specific digit appears in a number is what you mean, than the complexity will be O(n) where n is the length of the string (number): char x = ‘7’; std::string number(“9876541231654810654984431”); int count = 0; for (size_t i = 0; i < number.size(); ++i) if (number[i] … Read more

[Solved] C# form press any key to continue [closed]

The action you are looking for is the form’s KeyPress event, So you can handle KeyPress of your start screen form //you need to register the event handle to your form first.. //so the following line could be in your start screen form’s constructor this.KeyPress += new KeyPressEventHandler(Form1_KeyPress); //then you can open your new form … Read more

[Solved] What this function do? [closed]

This function counts all distinct elements in an array. The outer loop loops over all array elements. The inner loop loops over the array until the element of the outer loop. The count is incremented if there is no preceding element which is similar to the current element. For instance, given the array [1, 2, … Read more

[Solved] Why this c++ code doesn’t compile? [closed]

std::list<Tree<T>&>* children; Standard containers can’t store reference types. From the rest of the code, it looks like this should store Tree<T> objects. (If you wanted to refer to objects that live somewhere else, you’d have to store pointers rather than references; but this doesn’t seem to be the case here). You also have a duplicate … Read more

[Solved] Need help and a concise explanation for updating an existing constructor in C#

Modify the constructor by adding one extra parameter dateOfBirth. Use this parameter to initialize your property DateOfBirth. This way, the Person can never be instantiated without a valid value for DateOfBirth. public Person(string firstName, string lastName, DateTime dateOfBirth) { FirstName = firstName; LastName = lastName; DateOfBirth = dateOfBirth; } now you can construct it like … Read more

[Solved] System of equations program error

The problem is here: Console.WriteLine(“Enter row2 col1”); string strX2 = Console.ReadLine(); double dblX2 = Convert.ToDouble(strX1); <— Error You’re converting strX1 instead of strX2. As a result, it thinks the two X values are the same. 3 solved System of equations program error

[Solved] How does this code initialize the 2D array? [closed]

The given array is an array of strings. Each index of words is a string. e.g: words[0] = “india”words[1] = “pakistan” and so on. You can use words[0][j] to refer to the characters present in india, words[1][j] for referring to characters of pakistan. Maybe the following code will help you visualize the array: #include <iostream> … Read more

[Solved] In C++, why should I use “new” if I can directly assign an integer to the pointer without using “new”? [closed]

int *ptr_a = 1;doesn’t create a new int, this creates a pointer ptr_a and assigns a value of 1 to it, meaning that this pointer will point to the address 0x00000001. It’s not an integer. If you try to use the pointer later with *ptr_a = 2, you will get a segmentation fault because the … Read more

[Solved] initializing char* a = new char[size] does not work

You are not null-terminating your mString data, but it is expecting to be null-terminated when you pass it to std::cout. Without that terminator, std::cout reads into surrounding memory until it encounters a random null byte (or crashes with a read access error). That is why you are seeing std::cout output random garbage after your data. … Read more

[Solved] Does this usage of if statements cause undefined behaviour? [closed]

will I get undefined behaviour by not including all 3 variables into every condition? The behaviour of not including all variables into every condition is not undefined by itself. Will every unaccounted for condition go into the else statement? Statement-false (i.e. the statement after the keyword else) is executed if the condition is false. what … Read more