Imagine you got a class like this:
class Foo {
string key;
int value;
}
How would you select the Foo with the highest value from an IEnumeralbe<Foo>?
A basic problem is to keep the number of iterations low (i.e. at 1), but that affects readability. After all, the best I could find was something along the lines of this:
IEnumerable<Foo> list;
Foo max = list.Aggregate ((l, r) => l.value > r.value ? l : r);
Can you think of a more better way?
#include<stdio.h>
class A { public: int a;};
class B: public A {
public:
static int b;
B(){
b++;
printf("B:%d\n",b);
}
};
int main() {
A* a1 = new B[100];
A* a2 = new B();
return 0;
}
Error:
In function `main':
undefined reference to `B::b'
undefined reference to `B::b'
undefined reference to `B::b'
undefined reference to `B::b'
Can anyone please suggest some good C++ coverage tool. I am basically looking tool that really works fine when it comes to unit testing. The tool should work in the linux environment
When a user clicks a button I need to create a .bmp file on the server. After the .bmp file is created I will load it into the html page. Would Ajax be the best way to accomplish this?
I would like to embed videos and have managed to to do so by manually coding the url in where needed. If my url is stored in <%= @vid.url %, how can I use that string for the value and src parameter?
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/videos/abc123"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/videos/abc123" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
Hey, take this as a challange, my informatics professor made it in less than 10 rows, it work perfectly and its very efficient. I'd like to "surprise" him giving a better/shorted version of it. Ofcourse i wouldn't take the credits, hah, u can trust in me.
It's a simple anagras finder! If you can.. write it in c++! thanks!
I am developing a c++ banking system.
I am able to get the float, newbal, values correctly and when I try to write to file, there is no data in the file.
else
{
file>>firstname>>lastname;
cout<<endl<<firstname<<" "<<lastname<<endl;
cout<<"-----------------------------------\n";
string line;
while (getline(file, line))
{
//stringstream the getline for line string in file
istringstream iss(line);
if (iss >> date >> amount)
{
cout<<date<<"\t\t$"<<showpoint<<fixed<<setprecision(2)<<amount<<endl;
famount+=amount;
}
}
cout<<"Your balance is $"<<famount<<endl;
cout<<"How much would you like to deposit today: $";
cin>>amountinput;
float newbal=0;
newbal=(famount+=amountinput);
cout<<"\nYour new balance is: $"<<newbal<<".\n";
file<<date<<"\t\t"<<newbal; //***This should be writing to file
but it doesn't.
file.close();
The text file looks like this:
Tony Gaddis
05/24/12 100
05/30/12 300
07/01/12 -300
//Console Output looks like this
Tony Gaddis
05/24/12 100
05/30/12 300
07/01/12 -300
Your balance is: #1
How much wuld you like to deposit: #2
Your new balance is: #1 + #2
write to file
close file.
//exits to main loop::::
How can I make it write to file and save it, and why is this happening.
I tried doing it with ostringstream as well considering how I used istringstream for the input. But it didn't work either :\
float newbal=0;
newbal=(famount+=amountinput);
ostringstream oss(newbal);
oss<<date<<"\t\t"<<newbal;
I am trying to self teach c++ so any relevant information would be kindly appreciated.
Is it possible via script/tool to generate a delete statement based on the tables fk relations.
i.e. I have the table: DelMe(ID) and there are 30 tables with fk references to its ID that I need to delete first, is there some tool/script that I can run that will generate the 30 delete statements based on the FK relations for me ?
(btw I know about cascade delete on the relations, I can't use it in this existing db)
I'm using Microsoft SQL Server 2008
Where do you get the best in-depth information for C# programming? I'm looking for tutorials, examples, blogs, specialized forums etc. dedicated to c#.
i want to upload an excel file from the client to the server using asp .then it shud check the field name of the file with the oracle database table and then save its content in the database.
can somebody help me with this....??
I have 40+ TextViews and I want to add click events on them, but I try to do it "shortly" :
final GridLayout myGL;
myGL = (GridLayout) v0725.findViewById( R.id.tab1 );
for( int i = 0; i < myGL.getChildCount(); i++ )
if ( getResources().getResourceEntryName(((TextView) myGL.getChildAt(i)).getId()).indexOf("v")==0 ) {
((TextView) myGL.getChildAt(i)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v("edf", getResources().getResourceEntryName(((TextView) myGL.getChildAt(i)).getId()));
}
});
};
But Eclipse stops me on the Log.v line, because i should be final (but I can't)
any tips?
I need to generate a string of 7 chars that is based on the id of the row. So knowing the id of the image and a secret key, i should get the generated string.
the string must contain chars from "a" to "z" and numbers from 0 to 9.
I have a dir that contains photos like this
dir/p3/i2/s21/thumb.jpg
the generated string is p3i2s21, then is used to calculate the path of the image.
In Java, I want to download some data asynchronously in a Thread (or Runnable) object, and have the Thread put it's data into an Object I've declared within my main Thread.
How could I do this please?
#include<stdio.h>
#include<math.h>
int main ()
{
FILE *fp;
fp=fopen("output","w");
float t,y=0,x=0,e=5,f=1,w=1;
for (t=0;t<10;t=t+0.01)
{
if( y==inf && y== nan)
break;
fprintf(fp,"%lf\t%lf\n",y,x);
y = y + ((e*(1 - x*x)*y) - x + f*cos(w*t))*t;
x = x + y*t;
}
return (0);
}
why is the ouput giving infinite and NAN values?
Hi,
The title says it all. But I don't know if I should go for static methods, just a header, a class, or something else?
What would be best practice? But, I don't want to have an instance of a utility class.
I want to add functions like:
Uint32 MapRGB (int r, int g, int b);
const char* CopyString(const char* char);
// etc. You know: utility methods...
Can this be shortened/improved? I'm trying to make a password checker in python.
Could the if's be put into a for loop? And if so, how?
pw = input("Enter password to test: ")
caps = sum(1 for c in pw if c.isupper())
lower = sum(1 for c in pw if c.islower())
nums = sum(1 for c in pw if c.isnumeric())
scr = ['weak', 'medium', 'strong']
r = [caps, lower, nums]
if len(pw) < 6:
print("too short")
elif len(pw) > 12:
print("too long")
if caps >= 1:
if lower >= 1:
if nums >= 1:
print(scr[2])
elif nums < 1:
print("your password is " + scr[1])
elif lower < 1:
print("your password strength is " + scr[0])
elif caps < 1:
print("your password strength is " + scr[1])
Thanks for any suggestions :D
Public Class A
{
public A()
{
system.out.println("con call");
}
static
{
system.out.println("static call");
}
{
system.out.println("ins call");
}
Public static void main(string[] args)
{
new A();
new A();
}
What is the "computer science" term for the practice of assigning a special meaning to one of a type's values. For example a numeric variable called "amount_to_transfer" where the special value "0" means "entire account balance" or a date value "spouse_date_of_birth" where "1/1/1800" means "unmarried".
I happen to feel that this is quite a bad "smell", but I'd like to have a name for it, and if possible, some blog post or article about why it's bad and how to fix it.
I'm trying to decide if upgrading is viable given all the libraries we are using. The problem is some of these plugins arent being developed anymore so I'm not sure which of them is compatible with 1.4
Any thoughts on how to best approach this given legacy dependencies on older plugins?