Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 25 26 [27] 28 29 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100732 times)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #390 on: January 21, 2012, 11:27:33 pm »

Actually, int nLeave(); is a declaration of an integer using the default constructor. For example, Object myObject(myInt); declares an object myObject and initializes it with a constructor from Object that takes an integer.
No it isn't, because I'm pretty sure integers don't have constructors in C++.
« Last Edit: January 21, 2012, 11:42:33 pm by RulerOfNothing »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #391 on: January 22, 2012, 01:40:33 am »

@Mephisto:
Argh, I eat my own words. It actually is a function declaration. Ironically, it's because I've been programming in Java so long I forgot some basic C++, haha.

@RulerOfNothing:
You're right, it isn't, but for the wrong reason.

Constructors for primitive types in C++ are kind of nebulous. You can write something like int m(5); or int *n = new int(6); which sure look a lot like constructors for int. Whenever you leave out the parens, you're calling the default constructor (I forgot this fact, heh), i.e. Object myObject; calls the default constructor for Object. Someone with a degree in CS correct me if I'm wrong, but I'm fairly sure that constructors also implicitly allocate memory for the object they are constructing, so something like int myInt; implicitly calls the int default constructor.

Also, apparently function declarations can have a non-global scope, even if their definition is in the global namespace, which is really odd. It's kind of difficult to come across in practice, but something like this:

Code: [Select]
/* myFunc.cpp */
int m() { return 32; }

/* main.cpp */
#include <iostream>
int main() {
  {
    int m();
    std::cout << m() << std::endl;
  }
  int m = 5;
  std::cout << m << std::endl;
}

is apparently perfectly valid C++ (at least according to Cygwin MinGW; different compilers may think differently), which is really odd since C++ doesn't allow nested functions. You can't even use it like a function pointer. Anyone care to elucidate what's up with this?

Also, as an afterthought, it should be pointed out that C++11 fixes this by making initialization use curly braces instead of parens.
« Last Edit: January 22, 2012, 01:52:44 am by Normandy »
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #392 on: January 23, 2012, 12:19:42 pm »

Not sure if SQL should go here, but whatever.
Code: [Select]
SELECT City.[City], Count(Student.ID) AS [Count]
FROM City, Student
WHERE (((City.ID)=[Student].[Home Town ID]))
GROUP BY City.[City];
This query counts the amount of students in a table called "Student" which live in a certain city (Home Town ID). The result is a table with one column for the cities and another for the amount of students, but cities without students don't show up. How do I show cities with 0  students in them?

In short, I get this:
Code: [Select]
City          | Count
----------------------
Jacksonville  | 2
Washington    | 3
But I want this:
Code: [Select]
City          | Count
----------------------
Jacksonville  | 2
Washington    | 3
New York      | 0
San Francisco | 0
 
e, This is MS Access by the way.
« Last Edit: January 23, 2012, 12:35:20 pm by ILikePie »
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #393 on: January 23, 2012, 12:37:42 pm »

In oracle you could do it like this:

Code: [Select]
SELECT City.[City], Count(Student.ID) AS [Count]
FROM City, Student
WHERE (((City.ID)=[Student].[Home Town ID](+)))
GROUP BY City.[City];

But I'm not sure if that will be supported in other SQLs.  Alternatively, you could do:

Code: [Select]
(SELECT City.[City], Count(Student.ID) AS [Count]
FROM City, Student
WHERE (((City.ID)=[Student].[Home Town ID]))
GROUP BY City.[City])
union
(SELECT City.[City], 0 AS [Count]
FROM City
WHERE City.ID not in (select [Home Town ID] from student)
GROUP BY City.[City]);
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #394 on: January 23, 2012, 12:39:14 pm »

This query counts the amount of students in a table called "Student" which live in a certain city (Home Town ID). The result is a table with one column for the cities and another for the amount of students, but cities without students don't show up. How do I show cities with 0  students in them?

Generally it would be something like this;

Code: [Select]
SELECT City.[City], Count(Student.ID) AS [Count]
FROM City
LEFT JOIN Student ON (((City.ID)=[Student].[Home Town ID]))
GROUP BY City.[City];

A left join (rather than the default cross join) will return a null entry for what you join to. However I'm not sure if the syntax for ms access is correct here as Its been a while since I've had to use it.
It might be enough to point you in the right direction though.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #395 on: January 23, 2012, 02:40:40 pm »

The left join did it, thanks.
Code: [Select]
SELECT City.[City], Count(Student.ID) AS [Count]
FROM City
LEFT JOIN Student ON City.ID = Student.[Home Town ID]
GROUP BY City.[City];
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #396 on: January 23, 2012, 11:22:07 pm »

I'm sure this is pushing the limits of "Programming Help", but as I'm reading this thread, anyway...

Anyone know a way to export the list of things normally visible within the Device Manager (in XP, mainly, older/newer Windows versions optionally) to the console/a text file/similar?  I'd also be happy to pick up all known items (including inactive ones, as per one particular view), but only if I get a chance to check to see if a given one is flagged as current, rather than legacy/remembered.

Alternatively, a more direct method to discover such items within Perl, although I have so far failed to find a module listed that does this.  (Probably the failure of my Google Fu, of course.)  A simple backquoted export-to-variable-and-let-me-process-accordingly would suit me down to the ground, however.  Processing the registry would seem to be another method, but I'm not so used to disentangling the likes of the HKLM/HARDWARE area, mostly knowing the HKCR and HKLM/SOFTWARE areas, and only just thought about this as a solution[1], anyway, even as I was editing this post...

(Alternately, I suppose I could integrate something from a more powerful and system-aware ascript/language, directly or indirectly...)


[1] Which I know there's both direct Perl access methods for and a usefully easy-to-use regedit export option that would fulfil my initial criteria.  It may be that I've just answered my own question, now I've put a little more thought into it, but please don't let that stop you giving any advice if you have any!
Logged

Xegeth

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #397 on: January 24, 2012, 03:00:05 am »

Have you tried "msinfo32 /report Path"? It seems to have the right information, but I've not looked into it in depth.
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #398 on: January 24, 2012, 09:36:26 am »

Have you tried "msinfo32 /report Path"? It seems to have the right information, but I've not looked into it in depth.

Looking into that...  "...silently save a text report to <outfile> and quit" is indeed the right sounding parameter (to quote from the /? window).  But when I try it, it's exceedingly silent, in that it doesn't generate the suggested text file.  (And the MS Page has a typo in it, for that line, they obviously cut'n'pasted the .NFO extension :) )  But good lead, cheers, and I think I'll have this all working, either this way of through that direct/indirect registry examination method I thought of at the time of editing.

(Hmm, maybe it wouldn't output because it still had the "/?" window open...  Ahah, an output.  Right, something to peruse, shortly.)
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #399 on: January 24, 2012, 11:47:52 am »

Some more Access, this time, wildcards:
Code: [Select]
SELECT Student.[Student Name]
FROM Student
WHERE Query LIKE '*[Student].[Student Name]*';
I'd like this to work as sort of a search function, where the user enters a part of a name, and the query displays all names matching it. Access seems to be parsing "*[Student].[Student Name]*" literally, and not as Student.[Student Name] with two wildcards around it. I've tried single quotes and no quotes too, but they don't work either.
« Last Edit: January 24, 2012, 12:08:00 pm by ILikePie »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Help Thread (For Dummies)
« Reply #400 on: January 24, 2012, 12:24:16 pm »

Some more Access, this time, wildcards:
Code: [Select]
SELECT Student.[Student Name]
FROM Student
WHERE Query LIKE '*[Student].[Student Name]*';
I'd like this to work as sort of a search function, where the user enters a part of a name, and the query displays all names matching it. Access seems to be parsing "*[Student].[Student Name]*" literally, and not as Student.[Student Name] with two wildcards around it. I've tried single quotes and no quotes too, but they don't work either.

I don't know about access specifically but the SQL standard wildcards are '%' and '_'.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #401 on: January 24, 2012, 12:32:59 pm »

Microsoft decided their wildcards should be * and ? for some reason. Anyway, I got it, it should be:
Code: [Select]
SELECT Student.[Student Name]
FROM Student
WHERE Student.[Student Name] Like '*' & Query & '*';
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #402 on: January 24, 2012, 03:02:05 pm »

I need help and feel retarded for not being able to figure it out on my own,
in need help with a code snippet that returns x and y values of a parabola that passes through these 3 points.
10,353  260,3  and  530,353
spent the last 2 hours trying to figure it out to no avail, I wish I paid more attention in my math classes, lol
I know this is kind of more of a math problem than a programming problem, but it's driving me nuts.
and I need a control variable for how many values it returns,
for example, control = 50, would return 50 values for x between 10 and 53 with 260 being the 25th.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Antsan

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #403 on: January 24, 2012, 03:31:00 pm »

Lets see. You need to know the parabola first (as you don't need to compute it in the algorithm, right?), then you can just iterate over he borders of the intervals (of which there are control-1).
For determining the function for the parabola you can try to use Gaussian elimination. Look it up on Wikipedia.
Remember that the basic form for a parabola is
f(x)=a*x²+b*x+c
Logged
Taste my Paci-Fist

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #404 on: January 24, 2012, 03:52:01 pm »

Spoiler (click to show/hide)

figured it out, only unspoiler if you want to hear my stupid problem / solution
« Last Edit: January 24, 2012, 05:49:14 pm by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.
Pages: 1 ... 25 26 [27] 28 29 ... 91