Actually, this range only applies to 16-bit compilers such as Turbo C.
Incorrect. That range is the guaranteed minimum specified in the language standard, and it applies to all compilers. You're free to expect a larger range than that, but then you'd be depending on the compiler rather than the standard.
If you assume that int is 32 bits, for example, your code is technically not portable. If you assume that int is 16-bits two's complement (ie. you get an extra step on the negative range), your code is technically not portable.
The advice to jump from int to long when exceeding the range of [-32767,+32767] is spot on.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
There are two different things here, I think.
- Votes: These are the actual point values that contribute to your total up and total down vote counts.
- Currently positive or negative posts: These are lists of posts that are currently positive or negative when all votes on the post are taken into account.
If a post that's negative at -1 gets a positive vote, the value becomes 0 and the post is removed from the negative posts list. However, the downvote that put it on the list in the first place isn't deleted; that record remains in the database and still applies to both the post in question and your totals.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Er, not exactly.
True, but I'd question your sanity if you thought my brief confirmation of the general concept was anything remotely close to an "exact" description of what typically happens. ;)
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Then either the car is still traveling
Nope, the question clearly states that the car traveled (past tense) from A to B (a complete trip).
or it jumped part of the distance?
Or the person asking this question is math impaired? I still think that the most rational answer is 72km/hour and a broken odometer. How else would a car travel 36km and only report traveling 28km?
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
The speed of the car was 72km/hour, and the odometer is broken. ;)
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
What I was trying to say is that when a forum member wants to endorse someone, that particular someone should have a minimum of 'X' number of up-votes in that forum.
Ah, I got it backward. But my example can be reversed too. If Bjarne Stroustup joined, I'd make a beeline to endorse him for C++, regardless of how many up votes he had. ;p
That say, there's a restriction on how many posts you need in a forum before that forum becomes a favorite, and it's based on a percentage of total posts. It's not a very severe restriction (only 2% presently), but that does provide at least a little bit of buffer for the member to earn enough respect for endorsements.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
NOW THE QUES IS THAT I CAN'T UNDERSTAND
Which part don't you understand? The instructions are very explicit, though there's an assumption that you'll figure out how to calculate the distance between two points. I would expect a programming instructor to at least remind the class that the distance between two points can be solved with an equivalence of the Pythagorean theorem:
double a = a.getX() - b.getX();
double b = a.getY() - b.getY();
double c = sqrt(a * a + b * b);
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
One shouldn't expect people to consistently vote on every post one makes, it's really all about who sees it, what their opinion is, and if their opinion is strong enough at the time to make a vote. Further, votes are completely subjective and not restricted to any guidelines (barring personal guidelines the individual voter chooses to follow).
However, it's important to recognize that your votes will trend over time depending on your actual post quality. Those with consistently good quality posts will have an amortized good vote rating, and those with consistently bad quality posts will have an amortized bad rating. For people who fluctuate, the votes should even out over time between positive and negative. If a member is active in the community for a number of months or longer, their overall trend should be reasonably accurate.
Ultimately we all get votes we think weren't fair, but all of these metrics are really just for e-peen points. What really matters is your intangible reputation among the community. There are no numbers for that, it's strictly what everyone thinks about you.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
An abstract class is meant to be used exclusively as a base class. In other words, it cannot be instantiated directly, but classes that derive from it (if not also abstract classes) can be instantiated. An abstract method is the same thing at the method level: there's no method body, and it's intended to be implemented in a derived class.
In C++ an abstract method is created with the pure virtual syntax, and an abstract class is defined as any class that has one or more pure virtual member functions:
class Abstract
{
void foo() = 0; // An abstract method makes the class abstract
};
The above might also be called an interface because it only defines abstract methods.
p.s. I'm answering this in good faith, despite your previous posts following a pattern of signature spammers. That is, posting topical but largely fluff questions and answers, then applying a spammy signature to one's account after accumulating a number of such posts. Note that I'll be keeping an eye on you. ;)
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Database servers will provide a way to query the current ID. For example, in SQL Server you'd select one of the following:
select scope_identity(); -- Last identity generated explicitly in your scope
select ident_current('MyTable'); -- Last identity generated for the specified table
For MySql you might use something like this:
select last_insert_id();
select last_insert_id('MyTable');
Any programming API that supports database access should also provide a convenient (sometimes not so convenient) way of grabbing identities.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Perhaps the user on the server does not have priviliges to modify the registry.
An exception should be thrown in that case, but you can verify permissions without much difficulty using the RegistryPermission class. Here's a helper class that does the grunt work (for cleanliness):
using System.Security;
using System.Security.Permissions;
public static class RegistryInfo
{
public static bool HasAccess(RegistryPermissionAccess accessLevel, string key)
{
try
{
new RegistryPermission(accessLevel, key).Demand();
return true;
}
catch (SecurityException)
{
return false;
}
}
public static bool CanWrite(string key)
{
return HasAccess(RegistryPermissionAccess.Write, key);
}
public static bool CanRead(string key)
{
return HasAccess(RegistryPermissionAccess.Read, key);
}
}
And from there just call either CanRead() or CanWrite() to check for access on a key:
using System;
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
string key = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
string value = "MyApp1";
if (RegistryInfo.CanRead(key))
{
Console.WriteLine("Previous value '{0}': '{1}'",
value,
Registry.GetValue(key, value, "(null)"));
}
else
{
Console.WriteLine("No permission to read key: '{0}'", key);
}
if (RegistryInfo.CanWrite(key))
{
Registry.SetValue(key, "MyApp1", "C:\\WINDOWS\\myexe");
}
else
{
Console.WriteLine("No permission to write key: '{0}'", key);
}
if (RegistryInfo.CanRead(key))
{
Console.WriteLine("Updated value '{0}': '{1}'",
value,
Registry.GetValue(key, value, "(null)"));
}
else
{
Console.WriteLine("No permission to read key: '{0}'", key);
}
}
}
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
storage
In formal terms, "static" is a storage-class specifier.
That doesn't uniquely define static though. There are other storage class specifiers, and data types in general can be described as partially defining a variable's storage attributes.
Unfortunately, persistence doesn't quite cut it either if we're talking about a language like C++ because the static keyword is overloaded to mean different things. At file scope, static would be better described as defining a variable's visibility. As a static class member, a better description might be to define a variable as shared between objects of the class. At function scope, persistence is an excellent choice of words.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Can Coffee Really wipe out sleepiness. I do it a lot but still i become sleepy.
Coffee doesn't make you less sleepy, it's a stimulant that temporarily suppresses the sleepiness. Like all stimulants, there's a crash when it wears off that has you worse off than before. The best way to avoid sleepiness is to get enough sleep.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Oh, in that case what's the reason for it in the software forums -- suggest Dani remove it there.
It's basic Markdown. While possible, I don't really see the necessity of restricting the core formatting like that just for the development forums. However, I do agree with Mike that the font could be tweaked...maybe with an underline attribute and a smaller size.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
I suppose you could give an user an award for reading it. Or a badge. There was a site once, I thinkit was some pro photo upload site (istockphoto??) that tested its proto-members on the rules/regs. They weren't allowed full status until they passed the test. I failed. Ten times. Sod it.
I'd totally write something like that if I thought it had any chance in hell of not being vetoed by Dani. ;)
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
That "for" loop (according to what you have said) is the same as a while loop saying:
Close. It's more like this (note that the braces introducing a scope are significant):
{
int i = 5;
while (i < 2)
{
System.out.println("What?");
i++;
}
}
System.out.println("Who?");
Since i is never less than 2, the loop body is never entered, and the only output is "Who?".
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
As Dani says - it was at the top and very few people clicked on it.
If you want something to remain unread, don't label it "Top Secret" or "Don't Click This". Instead, label it "Rules", or "FAQ", and you'll guarantee that nobody will click the link regardless of its location.
I'd be willing to bet that the majority of clicks for the rules link comes from moderators.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
My first approach would be to monitor the last write time for the USBSTOR registry key in a windows service and persist those results in a separate database or file. Really the most difficult part of that would be working around the complete lack of support for time stamps in registry keys. So you'd have to drop down to the Win32 API for that information.
For example:
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
class Program
{
static void Main(string[] args)
{
string usbStor = @"SYSTEM\ControlSet001\Enum\USBSTOR";
using (var keyUsbStor = Registry.LocalMachine.OpenSubKey(usbStor))
{
var usbDevices = from className in keyUsbStor.GetSubKeyNames()
let keyUsbClass = keyUsbStor.OpenSubKey(className)
from instanceName in keyUsbClass.GetSubKeyNames()
let keyUsbInstance = new RegistryKeyEx(keyUsbClass.OpenSubKey(instanceName))
select new
{
UsbName = keyUsbInstance.Key.GetValue("FriendlyName"),
ConnectTime = keyUsbInstance.LastWriteTime
};
foreach (var usbDevice in usbDevices.OrderBy(x => x.ConnectTime))
{
Console.WriteLine("({0}) -- '{1}'", usbDevice.ConnectTime, usbDevice.UsbName);
}
}
}
}
/// <summary>
/// Wraps a RegistryKey object and corresponding last write time.
/// </summary>
/// <remarks>
/// .NET doesn't expose the last write time for a registry key
/// in the RegistryKey class, so P/Invoke is required.
/// </remarks>
public class RegistryKeyEx
{
#region P/Invoke Declarations
// This declaration is intended to be used for the last write time only. int is used
// instead of more convenient types so that dummy values of 0 reduce verbosity.
[DllImport("advapi32.dll", EntryPoint = "RegQueryInfoKey", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
extern private static int RegQueryInfoKey(
SafeRegistryHandle hkey,
int lpClass,
int lpcbClass,
int lpReserved,
int lpcSubKeys,
int lpcbMaxSubKeyLen,
int lpcbMaxClassLen,
int lpcValues,
int lpcbMaxValueNameLen,
int lpcbMaxValueLen,
int lpcbSecurityDescriptor,
IntPtr lpftLastWriteTime);
#endregion
#region Public Poperties
/// <summary>
/// Gets the registry key owned by the info object.
/// </summary>
public RegistryKey Key { get; private set; }
/// <summary>
/// Gets the last write time for the corresponding registry key.
/// </summary>
public DateTime LastWriteTime { get; private set; }
#endregion
/// <summary>
/// Creates and initializes a new RegistryKeyInfo object from the provided RegistryKey object.
/// </summary>
/// <param name="key">RegistryKey component providing a handle to the key.</param>
public RegistryKeyEx(RegistryKey key)
{
Key = key;
SetLastWriteTime();
}
/// <summary>
/// Creates and initializes a new RegistryKeyInfo object from a registry key path string.
/// </summary>
/// <param name="parent">Parent key for the key being loaded.</param>
/// <param name="keyName">Path to the registry key.</param>
public RegistryKeyEx(RegistryKey parent, string keyName)
: this(parent.OpenSubKey(keyName))
{ }
/// <summary>
/// Queries the currently set registry key through P/Invoke for the last write time.
/// </summary>
private void SetLastWriteTime()
{
Debug.Assert(Key != null, "RegistryKey component must be initialized");
GCHandle pin = new GCHandle();
long lastWriteTime = 0;
try
{
pin = GCHandle.Alloc(lastWriteTime, GCHandleType.Pinned);
if (RegQueryInfoKey(Key.Handle, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pin.AddrOfPinnedObject()) == 0)
{
LastWriteTime = DateTime.FromFileTime((long)pin.Target);
}
else
{
LastWriteTime = DateTime.MinValue;
}
}
finally
{
if (pin.IsAllocated)
{
pin.Free();
}
}
}
}
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Apply electric shocks to your genitals.
Kinky.
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
Here you can download visual c++ ...
Visual C++ no longer supports <iostream.h>. Nice try, but please attempt to understand the question before answering. ;)
deceptikon
Challenge Accepted
3,435 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56