mrnutty 761 Senior Poster

Can you show ur current code.

mrnutty 761 Senior Poster

in your employee.h, after the #include <string>
insert using std::string;

mrnutty 761 Senior Poster

From project euler :

By starting at the top of the triangle below and moving to adjacent numbers
on the row below, the maximum total from top to bottom is 23.
   3
  7 4
 2 4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bottom in triangle.txt, a 15K text file containing a triangle with one-hundred rows

mrnutty 761 Senior Poster

char is short for character, which means only 1 letter, not multiple.
So doing this char a = "huh" generates an error because a char variable
can only point to one letter.

To solve your problem replace char with std::string, in the return type as well as
the type of nameShift.

mrnutty 761 Senior Poster

I cant say for sure, but read them as ints;

int val = 0;
while(file >> val){
 cout << val << endl;
}
mrnutty 761 Senior Poster

Let me try to take a crack at this, after googling it. Its gonna be a long post, so
I hope you are ready to read it.

So first things first you know what inline functions are right? Just to recap, when
you inline a function, you suggest to the compiler that it inline or substitute the
definition where the function call was.

So the next thing, you probably know what virtual function does. Virtual functions
enable polymorphism. When you call a derived class from a base class pointer/ref, it
calls the derived class function.

Ok so thats cleared up. Now lets get started towards the problem.

Here is the first question that needs to be answered, and the main problem
that underlies with inline virtual function, consider the following code :

struct B{
 inline void show(){ _showIt(); } //explicitly tell compiler to hint of inlining it
 void tell(){ _tellIt(); } //implicitly tell the compiler to hint of inlining this func
};

int main(){
 B b;
 b.show();
 b.tell();
}

So suppose a the compiler accepts your inline hint, and inline those function, then
that means b.show() and b.tell() would be substituted with its definition.

Ok now consider this code :

struct B{
 virtual int id(){ return 1; }
};
struct D: B{
 int id(){ return 2; }
};

int main(){
 B base;
 D derv;
 
 base.id();
 derv.id();
}

Now look at the above code. The type of …

StuXYZ commented: Excellent deep answer +3
Nick Evan commented: Good job +15
mrnutty 761 Senior Poster

>>string word2("Over");
>>string word3(3, '!');

The string class, has the proper constructor that allows those syntax. So it calls
the string class constructor. Other that that, i'm not so sure about your question, maybe its because i'm tired.

mrnutty 761 Senior Poster

Get an instrument and be the next John Darnielle.
Get a large mug of coffee and some smokes, and just lie out in a field.
Get a fast bike and ride off, as far as you can.
Go on a 'trip'.
Write her name in blood, on your chest, email it, and see what ensues

lol, I don't know how ur past relationships went, but I got a little hunch that
those advice wont go so well as planned.


>>The point is, YOU decide where you want to take this

Yes, I know.

>>Firstly, she broke up with you BEFORE she spread her legs
lol, your posts are amusing. I guess its true.

>>But from society's point of view she'll feel like a little slut
We'll i haven't told the society and she hasn't told the society, so i'm not sure how
the society knows about our relationship. Nevertheless, she does feel like a slut,
and I told her that it made her look like one as well, among other nasty comments.

>>All you have to do to turn this to your advantage is to make sure she KNOWS she's fuked up. You're not going to be her comfort blanket who's gonna settle for sloppy seconds... (I think you already have this under wraps.) You do this by going out, having fun and seeing other girls

Lol, thats what i'm doing, i'm going …

mrnutty 761 Senior Poster

You should try looking into operator overloading:

int* operator >> (int *RHS)
{
   RHS = this->array;
   return RHS; //For chaining
}

Your operator overloading would allow this obscure code :

int * a = {1,2,3,4,5};
Integer num = Integer(a,5);
num >>(a)

which to me dosen't make sense that much. It would be hard to read.

@OP: Don't provide a way to return the internal array. Instead make the class
an array, by overloading either[] or () operator.

mrnutty 761 Senior Poster

Here is what I got :

#include <iostream>

using namespace std;

template<typename T>
void printN(T arg, int n){
 while(n--)cout << arg;
}

int main(){
 const int ROW = 9;

 for(int r = 0; r != ROW; ++r){
      printN(ROW, r);		
      printN('*',ROW - r);
      cout << endl;
 }

  return 0;
}
mrnutty 761 Senior Poster

ahahaha your post is so funny. Actually, this relationship is too too complicated
to even write down, so I'd rather not write down and just forget about it. Now she's
trying to get back with me,and I'm just telling her that there is no way you and me
could ever be together again.But i'm thinking about friends with benifits. We'll see
what happens.

And by the way, no girl really gets to accepts this one, most girls i dated, and just
brushed of my shoulders, but there was something about this one. But its history
now, and now I'm over her. Thanks for the late reply, nevertheless, the reply.

mrnutty 761 Senior Poster

5.4: inline makes no guarantee on what happens with the function. The compiler decides
what will happen to all function, whether to inline or not.

5.6: No its not possible, although you can always use a struct wrapper.

5.7: what happens there is, when you return num, the compiler makes a copy of num
and stores it in some temporary address, then retrieves it if needed.

mrnutty 761 Senior Poster

Just another way, use stl::map;

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;


int main(){
	std::map<string,int> dict;
	std::vector< pair<string,int> > vec;
	vec.push_back( make_pair("basketball",0));
	vec.push_back( make_pair("soccer",0));
	vec.push_back( make_pair("tennis",0));
	vec.push_back( make_pair("football",0));
	vec.push_back( make_pair("swimming",0));

	dict.insert(vec.begin(),vec.end());

	string input;	
	cout << "Enter a sport and see if I have it\n<input>";
	while(cin >> input){
		if(dict.find( input ) != dict.end() ){
			cout << "I have it in my dictionary\n";
		}
		else cout << "sorry, I don't have it\n";
		cout << endl << "<input>";
	}

}

I would recommend it using this way, if you list of words are very large or even
mildly big.

mrnutty 761 Senior Poster

>>And what will happen if the first character is white space
Then it just skips it because I used cin and not getline. Here is a test.

#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <sstream>

using namespace std;


int main(){
	string input = " hello this is a test";
	std::stringbuf inStream = std::stringbuf(input);
	cin.rdbuf(&inStream);
	string in;
	while(cin >> in){
		in[0] = toupper(in[0]);
		cout << in << endl;
	}
}
mrnutty 761 Senior Poster

>>Ultimately if you want to make programming a career then you will need a college degree
Not necessarily, I know and heard of plenty of people that are doing really well
without a degree. From what I have heard, a degree will really help get you that first
job, afterwards its all about experience and knowledge.

@OP: Go buy some C++ books. Here is a good list of books.

mrnutty 761 Senior Poster

whats with the c-style syntax? Use proper C++ syntax here, or else jump towards the C
forum, where your kind are welcomed lol.

string input;
while(cin >> input){
 input[0] = toupper(input[0]);
 cout << input << endl;
}
intills commented: thanks and sorry for not using Proper C++ syntax im new to this cite and to both c and c++, thanks a lot +0
mrnutty 761 Senior Poster

p@arse
thank you drunken master...


firstPerson/Ancient Dragon
so the single quotes are only used for single characters (ONE of the 256)?

yea grasshopper, although its not necessarily limited to 256.

mrnutty 761 Senior Poster

Does browser treat "id" and "class" as the same, even though they have different meaning?

mrnutty 761 Senior Poster

My father's name is Jesus, so whats my mother name?

mrnutty 761 Senior Poster

Try doing this :

int64 bigEndian(short* hex, int size){	
	if(size > 18 || size < 1) return -1; //int64 cannot hold anymore
	int64 res = int64();
	for(int i = 0; i != size-1; ++i){
             //OR and SHIFT as we go
		res |= hex[i]; 
		res <<= 8;
	}
        //Just OR the last value since it does not need to be shifted, thats why our loop went from i = 0 to size-1.
	res |= hex[size-1];
	return res;
}
int main(){
	short hexValues[8] = {0x00,0x00,0x00,0x00,0x00,0xBC,0x61,0x4E};
	cout  << bigEndian(hexValues,8) << endl;
}
mrnutty 761 Senior Poster

Just to repeat whats been said again.

int IntegerArray[5] = {0};
initializes all elements inside the array to 0.

int IntegerArray[5] = {0,0,0,0,0};
Here you are explicitly initializing each element to 0.

int IntegerArray[5] = {10,20,30,40,50};
Here you are explicitly giving each element inside the array a value.
So IntegerArray[0] has 10 stored, IntegerArray[1] has 20, and so on.

int IntegerArray[] = {10,20,30,40,50};
Here noticed that there is no 5 like before. By putting no number, and just using the
array brackets,[], you tell the compiler that the size of the array is the number
of elements inside the array. Since this "{10,20,30,40,50" has 5 element, the compiler deduces that IntegerArray has 5 elements.

mrnutty 761 Senior Poster

>>I read that code reading will enormously boost your programming skills.
Nope. It might help sometime, but to get better at programming you need to go program.
Of course seeing someone else's code might trigger something in your brain for the better.

mrnutty 761 Senior Poster

@OP, why is your code so bad? I don't know what you need, but how about something like
this :

string aLine;
const int MAX_PRINT_CHAR = 80;
getline(fileIn,aLine){
 if(aLine.size() < MAX_PRINT_CHAR ) cout << aLine << endl;
 //else print the first MAX_PRINT_CHAR characters and then print the rest in a different line
 else cout << aLine.substr(0,MAX_PRINT_CHAR) << endl << aLine(MAX_PRINT_CHAR);
}
mrnutty 761 Senior Poster

So what do you think? You are the one writing the paper? Here are some question that
helps answer it.

Was it easy to write?
Is it easy to read?
Was it complicated?
Was it more work?
Did it run fast?

try to come up with your own question.

mrnutty 761 Senior Poster

Since you are already using std::vector, why not use std::sort. All you have to do
is define a compare function.

bool sortByExp(const poly& lhs,const poly& rhs){
 return lhs.exp < rhs.exp;
}

//....
//somewhere in your code
std::sort(a.begin(),a.end(),sortByExp);
mrnutty 761 Senior Poster

You can use an online compiler if you want. That way you can compile your code and such.

mrnutty 761 Senior Poster

>>What can i say about the results obtained with STL when implementin Data Structures

Not sure if tat question makes sense. Do you mean, What can I say about the results obtained, when using STL to implement a data structure?

>>Future research about data tsructures using STL.
Recommend books, papers, documents , etc ?

mrnutty 761 Senior Poster

>>What can i say about the results obtained with STL when implementin Data Structures

Not sure if tat question makes sense. Do you mean, What can I say about the results obtained, when using STL to implement a data structure?

>>Future research about data tsructures using STL.
Recommend books, papers, documents , etc ?

mrnutty 761 Senior Poster

Also this code, remember to use brackets to declare a block :

if(AdventureGame.keypressed[DIK_6]){
 /* code goes here */
}

Also I'm not sure if ur trying to optimize by this statement :

if (AdventureGame.keypressed[DIK_F] && (ignition == false))
		ignition = true;
 
if (AdventureGame.keypressed[DIK_G] && (ignition == true))
		ignition = false;

but you can just do this :

if(AdventureGame.keypressed[DIK_F] ) ignition = true;
else if(AdventureGame.keypressed[DIK_G]) ignition = false;
mrnutty 761 Senior Poster

>>Well that response was througough. Good job

Do I get a cookie?

mrnutty 761 Senior Poster

Create a structure :

struct Player{
 string name;
 int score;
 Player() : name(), score(){}
};

Define an extraction operator, to extract into the struct :

std::istream& operator >>(std::istream& inFile, Player& p){
 return inFile >> p.name >> p.score;
}

now create a vector of players :

std::vector<Player> players;

now define a binary boolean function to be used with std::sort.

bool sortByScore(const Player& lhs, const Player& rhs){
 return lhs.score < rhs.score;
}

Now read in from the file into the vector of players :

std::vector<Player> players;
ifstream inFile("filename.txt");
//error check
Player tmp;
 while(inFile >> tmp){ players.push_back(tmp); } //read all from file
 std::sort(players.begin(),players.end(),sortByScore); //sort it
 //now do whatever with the sorted player vector

none of the above is compiled, just an idea to get you started.

mrnutty 761 Senior Poster

The question isn't very clear to me neither.

mrnutty 761 Senior Poster

You don't need while loop. IMO the forloop looks better and easier to read( most of the time).

mrnutty 761 Senior Poster

lol, you guys are so funny.

mrnutty 761 Senior Poster
shankarz commented: if u know pls answer my doubt or else leave it, atleast others will answer my question... +0
mrnutty 761 Senior Poster

what you are looking for is std::vector<string> . Here are some examples.

std::vector<string> v;
v.push_back("hello");
v.push_back("goodbye");
cout << v[0] << endl;
cout << v[1] << endl;
mrnutty 761 Senior Poster

Download this great app, that
I created. You will like it if you like basketball, especially.

mrnutty 761 Senior Poster

>>*array[4]; // pointer to 5th content of array.

The above is correct only if array is declared as DataType*** array ,
because you deference it twice. If you declare array as DataType array[] then *array[4] is invalid syntax, because you are using the dereferencing operator on a DataType, and from your post, DataType is something like int,char, or some POD.

>>what is the difference between these?
char num1 = 64;
char num1 = '64';

Try it, the second one is a compiler error.

mrnutty 761 Senior Poster

Remember, when defining a class, you should make that class objective minimal as possible. So don't dump all functions and variable into the class if not necessary.

mrnutty 761 Senior Poster

Also, use getline(cin,stringVariable) to accept a whole line of input instead
of just cin >> stringVariable because cin stop reading input after
it sees a whitespace.

mrnutty 761 Senior Poster

You mean if g2 is a subgraph of g1? Or else, g2 is automatically a subgraph of g2.
Well read this paper on the algorithm.

mrnutty 761 Senior Poster

I hope that function is not public!

mrnutty 761 Senior Poster

and ... Whats the problem

mrnutty 761 Senior Poster

1)ISO C++ does not support 'long long'
2)Use functions, it makes it easier and clearer
3)No need for system("pause"), either let the IDE handle that, or use better options
4)Rename your variable to something more appropriate.
5)Why 999999? Why do you limit it to that?

Compare with this :

#include <iostream>
#include <string>
#include <limits>

using std::string;
using std::endl;
using std::cout;
using std::cin;

bool isPrime(int num){
	if(num < 2) return false;
	if(num == 2) return true;
	if(num % 2 == 0) return false;

	for(int i = 3; i < num/2; i += 2){
		if(num % i == 0) return false;
	}
	return true;
}
void pauseState(){
	cin.clear();	
	cin.ignore( std::numeric_limits<std::streamsize>::max(),'\n');
	cout << "\nPress enter to exit...";
	getline(cin,string());
}
int main()
{
	
	cout << "Enter the limit of prime number to generate " << endl;	
	size_t max = 0;
	cin >> max;

	for(int i = 2, count = 0;  count != max; ++i){
		if(isPrime(i)){
			cout << ++count << ") " << i << " is prime\n";
		}
	}

	pauseState();

	return 0;
}
mrnutty 761 Senior Poster

>>while(counter<=SIZE)

check that one again

mrnutty 761 Senior Poster

For #2, iterators are just classes. They have certain operation defined for them.
For example they define the deference operator, which is why you can deference them.
Similarly, the library does not define the operator << for the iterators, thus it is
a compiler error.

For #3, "selection < gameLibrary.end())"

.end() function returns an iterator to the one-pass-the-end element. It is not what
you want there. What you want is the .size() function.

mrnutty 761 Senior Poster

Closing int main() hopefully :)

lol wrong person, sorry for the ambiguity.

mrnutty 761 Senior Poster

@dusktreader: You can combine your convert code into 1 :

template<typename ReturnType, typename InputType>
ReturnType convertTo(const InputType& in){
 std::stringstream ss;
 ss << in;
 ReturnType ret = ReturnType();
 if( (ss >> ret).fail()) throw std::exception("Conversion failed");
 return ret;
}

int main(){
 float pi = convertTo<float>("3.1415");
 string strPi = convertTo<string>(pi);
}
mrnutty 761 Senior Poster

>>If there are three logic bugs in total and one's down, two are left.

Holy shit. That's some amazing math!
Although you obviously think otherwise: I'm not stupid. I was asking where the two remaining errors are.

I think he got this code from the book. And the book probably said there was x amounts
of errors in the code. And so, he is left hunting for them. Thats why, he maybe saying there are 2 errors left.

mrnutty 761 Senior Poster

Oh this is a silly mistake, your function name and the variable name are the same.
Change one of them. Plus you are not returning anything? Do this :

double length ( const int a[], int size )
{
       double len = 0;
       for ( int i = 0; i < size; i++ )
       {
           len += pow((double)a[i],2);
       }
       return sqrt( len );
}