Are you sure it's not a backface culling problem? glDisable(GL_CULL_FACE)
Does it work with untextured quads?
Does it work with triangles?
If I were to self-teach myself to become a kick-ass java programmer -- without having to buy any books -- where would I begin?
Sure, I'd love to get there, but I want to learn what all of the code and terminology means too. I'm a total newbie. Some people draw, take photos -- I want to learn how to program stuff. Doesn't have to be strictly java I guess.
i'm assuming that all languages share a lot of concepts, with syntax being the major differentiator. at what point should i consider myself 'done' with python (I know this'll be a while) and move on - essentially, how do you know when you've learned the last concept?
int pNumber;
while(!cin);
{
cin >>pNumber;
cin.clear();
cin.ignore();
if(!cin){cout <<"input a number!" << endl;}
}
If I were to self-teach myself to become a kick-ass java programmer -- without having to buy any books -- where would I begin?
The first that you should do is a do...while() loop instead so you get something from the user first and then check if it's a valid character. Once the user enters carriage return(presses enter), call a function that contains an array full of numeric character which will be compared to the inputed string from the user. There are a slew of ways to go about the problem.I'm having some trouble trying to validate int input in C++. The program should only continue if the user inputs a valid number, if the user inputs a number the program then loops until a valid number is given. I have tried to do this for hours in many different ways but I haven't gotten anywhere. Here's a snippet from my project where the thing should happen:
Code:int pNumber; while(!cin); { cin >>pNumber; cin.clear(); cin.ignore(); if(!cin){cout <<"input a number!" << endl;} }
Any help would be welcome.
The first that you should do is a do...while() loop instead so you get something from the user first and then check if it's a valid character. Once the user enters carriage return(presses enter), call a function that contains an array full of numeric character which will be compared to the inputed string from the user. There are a slew of ways to go about the problem.
Another example http://stackoverflow.com/questions/10828937/how-to-make-cin-to-take-only-numbers
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string townA, townB;
int popA, popB, lead, year=0;
double rateA=0.00, rateB=0.00;
cout << "Please enter the name of the first town"
<< " and press enter: " << endl;
getline (cin, townA);
cout << "\nEnter the name of the second town: " << endl;
getline (cin, townB);
cout << "\nEnter the population & growth rate for "
<< townA << " separated by space." << endl;
cin >> popA >> rateA;
cout << "\nEnter the population & growth rate for "
<< townB << " separated by space." << endl;
cin >> popB >> rateB;
if (popA == popB && rateA == rateB)
{
cout << "\nBoth populations match & will grow equally."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << "Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
if (popA == popB && rateA > rateB)
{
cout << "\nBoth populations match, but will grow differently."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
else if (popA == popB && rateA < rateB)
{
cout << "\nBoth populations match, but will grow differently."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
if (popB > popA && rateA == rateB)
{
cout << "\nAny population disparity will grow indefinitely."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
if (popA > popB && rateA > rateB)
{
cout << "\nAny population disparity will grow indefinitely."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
if (popB > popA && rateB > rateA)
{
cout << "\nAny population disparity will grow indefinitely."
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
system("Pause");
return 0;
}
if (popA > popB)
{
lead = 1;
}
do
{
popA += (popA * (rateA / 100));
popB += (popB * (rateB / 100));
year++;
}
while (popA < popB);
do
{
popA += (popA * (rateA / 100));
popB += (popB * (rateB / 100));
year++;
}
while (popA < popB);
if (lead == 1)
{
cout << "\nThe population of " << townB <<
" will eclipse " << townA << " in: " << endl;
cout << year << " year(s).\n";
cout << "\nAt that time " << townA << "'s population "
<< "will be:\n" << popA << " and "
<< townB << "'s population: " << popB << endl;
}
else
{
cout << "\nThe population of " << townA <<
" will eclipse " << townB << " in: " << endl;
cout << year << " year(s).\n";
cout << "\nAt that time " << townA << "'s population "
<< "will be:\n" << popA << " and "
<< townB << "'s population: " << popB << endl;
}
cin.ignore(2);
system("Pause");
return 0;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << " Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void printEnterPopMessage(string town) {
cout << "\nEnter the population & growth rate for "
<< town << " separated by space." << endl;
}
void printPopGrowth(string firstLine) {
cout << "\n" << firstLine
<< endl;
cout << townA << " Population: " << popA << " "
<< "Growth Rate: " << rateA << "%\n"
<< townB << "Population: " << popB << " "
<< "Growth Rate: " << rateB << "%\n" << endl;
}
void printEclipseMessage(string town1, string town2) {
cout << "\nThe population of " << town1 <<
" will eclipse " << town2 << " in: " << endl;
cout << year << " year(s).\n";
cout << "\nAt that time " << townA << "'s population "
<< "will be:\n" << popA << " and "
<< townB << "'s population: " << popB << endl;
}
int main()
{
string townA, townB, largerTown == "";
int popA, popB, year=0;
double rateA=0.00, rateB=0.00;
cout << "Please enter the name of the first town"
<< " and press enter: " << endl;
getline (cin, townA);
cout << "\nEnter the name of the second town: " << endl;
getline (cin, townB);
printEnterPopMessage(townA);
cin >> popA >> rateA;
printEnterPopMessage(townB);
cin >> popB >> rateB;
string message = "";
if (popA == popB) {
if(rateA == rateB) {
message = "Both populations match & will grow equally.";
} else if(rate A > rateB) {
message = "Both populations match, but will grow differently.";
} else if(rate A < rateB) {
message = "Any population disparity will grow indefinitely.";
}
printPopGrowth(message);
} else if(popB > popA) {
if(rateB > rateA) {
message = "Any population disparity will grow indefinitely.";
} else if(rateB == rateA) {
message = "Any population disparity will grow indefinitely.";
}
printPopGrowth(message);
} else if(popA > popB && rateA > rateB) {
message = "Any population disparity will grow indefinitely.";
printPopGrowth(message);
} else if(popA > popB) {
largerTown = townA;
do
{
popA += (popA * (rateA / 100));
popB += (popB * (rateB / 100));
year++;
}
while (popA < popB);
do
{
popA += (popA * (rateA / 100));
popB += (popB * (rateB / 100));
year++;
}
while (popA < popB);
if (largerTown == townA)
{
printEclipseMessage(townA, townB);
}
else
{
printEclipseMessage(townB, townA);
}
}
cin.ignore(2);
system("Pause");
return 0;
}
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
using namespace std;
class town {
public:
string name;
uint32_t population;
double growth;
town(string n, uint32_t p, double g) : name(n), population(p), growth(g) {}
string toString() const {
return name + ": Population " + to_string(population) + ", Growth rate " + to_string(growth) + ".";
}
};
double calculateTime(town a, town b) {
double p1 = a.population, p2 = b.population;
return -log(p1/p2)/(log(a.growth/100.0 + 1.0) - log(b.growth/100.0 + 1.0));
}
int main() {
town a("Town 1", 10000, 2.0), b("Town 2", 1000, 2.5);
if(a.population == b.population) {
cout << "Both populations match ";
if(a.growth == b.growth) {
cout << "and will grow equally";
} else {
cout << "but will grow differently";
}
cout << "." << endl << a.toString() << endl << b.toString() << endl;
return 0;
}
town big = a, small = b;
if(a.population < b.population) {
big = b;
small = a;
}
if(big.growth >= small.growth) {
cout << small.name << " will never reach population of " << big.name << endl;
cout << big.toString() << endl << small.toString() << endl;
} else {
cout << small.name << " will reach population of " << big.name << " after " << calculateTime(big, small) << " years." << endl;
cout << big.toString() << endl << small.toString() << endl;
}
return 0;
}
And if you're using objects, you could actually add something to compare Town objects using a member function. But that's probably for another day.If you are learning C++ this might be a good start to use classes (for the towns).
What is the point of overloaded functions? Or a better phrasing of that would be, what are some real world examples of what makes an overloaded function useful?
template <typename my_type>
my_type max(const vector<my_type>& elements) {
assert(elements.size() > 0);
my_type highest = *elements.begin();
for (auto element : elements) {
if (greater_than(element, highest)) {
highest = element;
}
}
return highest;
}
bool greater_than(const int& a, const int& b) {
return a > b;
}
bool greater_than(const some_class& a, const some_class& b) {
// some special code
}
// etc.
Code:template <typename my_type> my_type max(const vector<my_type>& elements) { assert(elements.size() > 0); my_type highest = *elements.begin(); for (auto element : elements) { if (greater_than(element, highest)) { highest = element; } } return highest; } bool greater_than(const int& a, const int& b) { return a > b; } bool greater_than(const some_class& a, const some_class& b) { // some special code } // etc.
Should have also said I'm a complete beginner to C++ and programming in general. Reading that made my head hurt trying to understand it, haha.
void PrintString(const string& str) { // stuff }
void PrintString(const char* c_str) { // stuff }
Sorry about that.
Basically the gist of it is: Overloaded functions are useful in what is called "generic" or "meta" programming in C++; what I showed in the example. The idea there is that the same code can be reused with different datatypes.
One place where overloading is even more commonly used is in constructors.
And sometimes people like to use them just so they don't have to remember two different function names. Ex:
Code:void PrintString(const string& str) { // stuff } void PrintString(const char* c_str) { // stuff }
I am fairly confident that overloaded functions get compiled out as different functions, so yes. For that matter, unless you're using virtual functions or templates, the vast majority of C++'s object oriented features can also be replaced by differently named functions. Like object oriented programming, function overloading is occasionally useful, so it's in the language. That doesn't mean you have to use itSo it's really only used for convenience purposes? The code that you posted earlier could be done just as efficiently with two differently named functions?
So it's really only used for convenience purposes? The code that you posted earlier could be done just as efficiently with two differently named functions?
Most things in programming can be accomplished other ways and are just there for convenience.So it's really only used for convenience purposes? The code that you posted earlier could be done just as efficiently with two differently named functions?
The person who just wants a simple bounce can call the empty one, and the person who wants a very specific kind of bounce can call whichever overload they want. You could even make a BounceOptions class that has 10 options and just pass an instance of that.
Your school doesn't have their own domain for teacher and student emails?so my programming teacher uses a hotmail account
I should quit this class right
just wanted to learn some actionscript dammit
Efficiently yes, readably and maintainably no. If you have written a Hello World -type program in C++, you have already used function overloading:So it's really only used for convenience purposes? The code that you posted earlier could be done just as efficiently with two differently named functions?
void main {
std::cout << "Hello World! " << 101010 << std::endl;
}
float k = 3;
vec3 position; // vector, length 3 (not a standard type)
mat3 xform, xform2; // 3x3 matrices (not a standard type)
// formula can be written exactly the same as in a math textbook, easy to verify it's correct
vec3 final_position = xform * k * xform2 * position;
vec3 final_position = xform.scalarMult(k).mat3mult(xform2).vec3mult(position);
vec3 final_position = mat3vec3mult(mat3mat3mult(mat3scalarMult(xform, k), xform2), position);
Efficiently yes, readably and maintainably no. If you have written a Hello World -type program in C++, you have already used function overloading:
This code calls three different operator<< functions. Without overloading you'd have to remember and use separate named functions for every different type you want to print. Not only would that be inconvenient, but the code would be less clear, which is a bad thing. The programmer's intention (print these things in this order) would be obscured. (C's printf() function instead asks you to specify types in a format string, which is obscure and sort of unsafe, and still doesn't allow you to print custom types of your own like overloading does.)
so my programming teacher uses a hotmail account
I should quit this class right
just wanted to learn some actionscript dammit
so my programming teacher uses a hotmail account
I should quit this class right
just wanted to learn some actionscript dammit
See also: Turing tarpitsMost things in programming can be accomplished other ways and are just there for convenience.
Head First Java was a good dive to the language in my opinion. Not boring and made learning fun and easy to grasp. Definitely helped me jump straight into my data structures class I'm currently taking. However, it's a bit outdated but the fundamentals are still presented well. My only complaint about it is they don't they don't talk about worst case or recursion. I had to learn that on my own but it's slowly getting better. Codingbat is good for exercises as well. Most are easy but it's good to get you thinking. I bet other people here can recommend something better.What is a good site to learn Java? I would like to develop some apps on Android.
I don't mind getting some books on them too, so any recommendations on those would be amazing as well. Many thanks.
Starting with an empty BST, a sequence of n items is inserted into it, one at a time. The BST is not allowed to have any duplicate keys. What is the worst case big O running time to insert all n items?
Isn't that for insertion of one item?Now, I looked at wiki and it says the worst case for a BST tree is O. Why is it O
?
You know, that makes a lot of sense. ...Isn't that for insertion of one item?
DataSet xmlds = new DataSet();
xmlds.ReadXml("testdemoxml.xml");
this.dataGridView1.DataSource = xmlds.Tables[0];
<row>
<id>1</id>
<description>description 1</description>
<thedate>2013-06-12T00:00:00</thedate>
<somenotes>some notes1asdsadsadsad</somenotes>
</row>
private void yearFilterButton_Click(object sender, EventArgs e)
{
}
Also, this concept seems to be confusing me much more than overloading functions initially did. What is the purpose of passing arguments by reference using & at the end of the type in C++? The book I'm reading is trying to explain it, but I can't even begin to wrap my head around it as they only spend 2 pages to explain the concept with only one example that I don't really understand.
The basic difference between call by reference and call by value is twofold:
1) Memory usage
2) The source value
Call by value is when you pass a value to another function without using "&". You are making a copy of that value's data type and information. The copy is the data that is acted upon within this new function without your original value being affected. This uses more memory (since a copy is created) and your original value is not touched.
Pass by reference is when an "&" is used (I've always put it before but he said after. Maybe it's both?) with your value. This passes the address where the value is stored so the new function is affecting the original value and no copy is created. This uses less memory (again, because there is no copy) and your original value is being used.
As an example, say you're using an int called position with a value of 5. When passed, the new function adds 4 before returning it. This would be the difference:
Value: 5 ->(passed to function and 4 added)-> 9 ->(returned to function)-> 5
Reference: 5 ->(passed to function and 4 added)-> 9 ->(returned to function)-> 9
A reference has to be declared as const, otherwise you won't be able to pass a literal to it (as you would be able to change that literal via the reference).Im trying to mess around with it in visual express, and I notice that you can't simply pass a value into the referenced argument.
Appreciate a nod in the right direction, hope I gave enough info![]()
I'm still sorta confused. When would you use it? Is it only used in situations where you want to save memory?
Im trying to mess around with it in visual express, and I notice that you can't simply pass a value into the referenced argument. You need to define and initialize a variable that will be passed as an argument instead. the value it returns to the console when compared to the same value, but not referenced is the same.
#include <iostream>
using namespace std;
void addition( int position )
{
position += 4;
cout << position << endl;
}
int main( void )
{
int position = 5;
addition( position );
cout << position << endl;
return 0;
}
9
5
#include <iostream>
using namespace std;
void addition( int *position )
{
*position += 4;
cout << *position << endl;
}
int main( void )
{
int position = 5;
addition( &position );
cout << position << endl;
return 0;
}
9
9
In .NET, the type for messing with dates is called DateTime. You can make a DateTime from your string "2013-06-12T00:00:00" using DateTime.Parse(). You can either put the DateTimes in your DataGrid instead of strings, or you can create them just for filtering. Either way, they have a lot of methods and properties that are useful. For example, there's a property .Year which refers to just the year. It returns an int.c# Form questions.
I'm loading an xml file into a dataGridView, then want to filter the date by year when a button is clicked.
How i'm loading that xml file.
Code:DataSet xmlds = new DataSet(); xmlds.ReadXml("testdemoxml.xml"); this.dataGridView1.DataSource = xmlds.Tables[0];
snippet of the xml file
Code:<row> <id>1</id> <description>description 1</description> <thedate>2013-06-12T00:00:00</thedate> <somenotes>some notes1asdsadsadsad</somenotes> </row>
So yeah, google doesn't seem to be offering up a clear answer for what will end up in this...
to display only items from this year.Code:private void yearFilterButton_Click(object sender, EventArgs e) { }
Appreciate a nod in the right direction, hope I gave enough info![]()
public IEnumerable<DateTime> FilterDatesByYear(IEnumerable<string> dateStrings)
{
//this list will hold our DateTime objects we've converted from strings
var dates = new List<DateTime>();
foreach(var dateString in dateStrings)
{
var date = DateTime.Parse(dateString); //parse the string to a DateTime
dates.Add(date);
}
//DateTime.Now gives you a DateTime for this moment in time. .Year is the year of that date (this year)
var thisYear = DateTime.Now.Year;
//this will hold only the DateTimes that fall in this year)
var datesThisYear = new List<DateTime>();
foreach(var date in dates)
{
if(date.Year == thisYear)
{
datesThisYear.Add(date);
}
}
return datesThisYear;
}
public IEnumerable<DateTime> FilterDatesByYear(IEnumerable<string> dateStrings)
{
return dateStrings.Select(x => DateTime.Parse(x)).Where(x => x.Year == DateTime.Now.Year);
}
FilterDatesByYear(new[]{"2013-06-12T00:00:00", "2012-04-19T00:00:00", "1999-01-11T00:00:00", "2013-09-20T00:00:00"})
I don't know exactly what you want to do when the yearFilterButton is clicked, but you can use the code above to at least get the dates from this year.
I'm still sorta confused. When would you use it? Is it only used in situations where you want to save memory?
Im trying to mess around with it in visual express, and I notice that you can't simply pass a value into the referenced argument. You need to define and initialize a variable that will be passed as an argument instead. the value it returns to the console when compared to the same value, but not referenced is the same.
void my_function(const int& arg) {
// stuff
}
void my_function2(int& arg) {
// stuff
}
void some_other_method() {
// ...
my_function(0); // OK
my_function2(0); // Compilation error
}
void assign6(int& my_val) {
my_val = 6;
}
int main (...) {
...
int a = 3;
assign6(a); // Legal. Now a = 6.
assign6(3); // Illegal. 3 = 6? Doesn't make sense.
}