[Solved] Accessing a data member of a pointer [closed]

[ad_1] It works just fine: http://ideone.com/3E5Uec #include <iostream> using std::cout; using std::endl; class Cat { public: int name; Cat() : name(0) { } int getName() { return name; } }; int main() { Cat* pointer = new Cat(); pointer->name = 42; cout << “getName: ” << pointer->getName() << endl; cout << “name: ” << pointer->name … Read more

[Solved] Validating School Year [closed]

[ad_1] Assuming that 2013-2014 is a valid format, this might be a function that works: public static bool IsSchoolYearFormat(string format, int minYear, int maxYear) { string[] parts = format.Trim().Split(new[] { ‘-‘ }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { int fromYear; int toYear; if (int.TryParse(parts[0], out fromYear) && int.TryParse(parts[1], out toYear)) { if (fromYear >= minYear … Read more

[Solved] How can I use the same name for two or more different variables in a single C# function? [closed]

[ad_1] You can make the scopes non-overlapping using braces: switch (something) { case 1: { int Number; } break; case 2: { float Number; } break; } Going out of scope is the only way a variable name is “deleted” in the sense you are talking about. Notably and unlike some other languages, C# doesn’t … Read more

[Solved] Since when does 3 / 5 = 0?

[ad_1] The / operator looks at its operands and when it discovers that they are two integers it returns an integer. If you want to get back a double value then you need to cast one of the two integers to a double double difference = (endX – startX + 1) / (double)ordinates; You can … Read more

[Solved] C# method signatures – restricting types – what’s the correct terminology? [closed]

[ad_1] I think the term you are looking for is generic type constraints. From the linked MSDN article: When you define a generic class, you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by … Read more

[Solved] C++ if x more than y by 3

[ad_1] The expression (x[i] > y) is a boolean, which in this context is casted as an integer (0 or 1), but hardly ever reaches 3. So the branch will always be skipped. If your values x[i] and y are integers, just take the difference: if (x[i] – y == 3) {…} If those are … Read more

[Solved] Naming a variable based on another variable

[ad_1] No, you can’t, and it makes no sense honestly to have a feature like that. If you want , you can use a dictionary, where you can have the key be a string: Dictionary<string, RectangleShape> shapes = new Dictionary<string, RectangleShape>(); shapes.Add(“nameTheKey”, new RectangleShape( … )); Then you can simply read the “variable” like shapes[“nameTheKey”] … Read more

[Solved] Creating a batch files for visaul studio command

[ad_1] we can create a batch(.bat) file for executing the multiple commands in visual studio command prompt explained below. call “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat” the above command will call the visual studio command prompt and then we have to wrote our multiple commands then it will be executed and save this file in … Read more

[Solved] Why is tabbed space width not constant

[ad_1] It works as intended. The original purpose of tab is printing tables. Rather than expanding to exactly N spaces (N being tab width, normally 4 or 8), it sets X coordinate of the cursor to the next multiple of N. Consider this example: #include <stdio.h> int main() { for (int i = 0; i … Read more

[Solved] How to convert array of char into array of int?

[ad_1] You are trying too hard. Here’s how typecasting should look void typecasting(unsigned char test[SIZE], int array[SIZE]) { for (int i = 0; i < SIZE; ++i) array[i] = test[i]; } Your code might be suitable if you were converting from a C string, i.e. if your original test array was char test[] = “34,201,190,154,8,194,2,6,114,88,45,76,123,87,25,23,…”; … Read more

[Solved] Weird results in c [closed]

[ad_1] In addition to LihOs answer above this block looks wrong: if(tab1[i] != ‘\0′) tab1[i]==result[i]; else if (tab2[i] !=’\0′) tab2[i]==result[i]; else printf(” “); Don’t you mean to assign the value in tab1[i]or tab2[i] to result[i]like this? if(tab1[i] != ‘\0′) result[i] = tab1[i]; else if (tab2[i] !=’\0’) result[i] = tab2[i]; else printf(” “); Also using magic … Read more