mrnutty 761 Senior Poster

Wrong answer. Those strings don't have enough space allocated to concatenate them (see original post). Each of those strings need to be copied into some buffer that is large enough to hold all the strings at one time.

Oh, when I said result, I was implicitly talking about a new result string, as suggested by the function prototype that I gave. I thought it was obvious but I guess not.

mrnutty 761 Senior Poster

They have it , in the link I provided you with.

mrnutty 761 Senior Poster

Do you know functions ? loops? classes ? templates ? structs ?
polymorphism ? inheritance ? pointers ? data structures ?

see here

mrnutty 761 Senior Poster

Well what do you know so far?

mrnutty 761 Senior Poster

Since "I started learning C++ November 14th 09!!"

Then I would suggest to keep learning it more a while.

mrnutty 761 Senior Poster

Put the definition in the same file as the templete header, unless your
compiler supports the keyword export.

mrnutty 761 Senior Poster

OK so I'm trying to convert my string to lower case. Shouldn't this get the job done:

for (int i = 0; i == len; i++)
	{
		if(isalpha(sentence[i]))
			temp[i] = tolower(temp[i]);
								//Stores all characters as lowercase in a temporary string
	}

Fix :

for (int i = 0; i < len; i++){  
     temp[i] = tolower(temp[i]);								
}

No need to check isalpha.

mrnutty 761 Senior Poster

Sorry to have to say this. Puncuation and spaces can sometimes be very important in codes!!

when checking for palindrome, it does not matter.

mrnutty 761 Senior Poster

Helpful tips :

create a function that :

1) Returns the lower or uppered case of a string
2) Removes all punctuation from the string
3) Removes all spaces from the string

Then what you are left with is something like this for example :

< Original string > Vanna, wanna V?
< after going through the functions above > vannawannav

Then all you need to do is check the (last - n) character with the (first+n)
character.

mrnutty 761 Senior Poster

>>(all sentences are on one line)

why?

>> Write a C++ program that indicates whether each line on an input file...

mrnutty 761 Senior Poster

To make it easier on your self. Make a function that concats two strings.

//add two string together and places the result in the result variable
void concat(const char *left, const char* right, char * result);

The you can just concat title with first name. Then the result of that
gets concated with the last name. Then finally display the final result.

mrnutty 761 Senior Poster

First

int n, num;
    cout << "Enter the Number of matrix -> ";
    cin >> n; 
    int s[n][n];

The n variable needs to be constant, unless your compiler allowed it,
which is not good.

To pass a multidimensional array you need this :

const int FIXED_COL = 5;
void print(int A[][FIXED_COL], int rowSize);

The compiler needs to now the size of the column for a 2d array.

mrnutty 761 Senior Poster

When you don't specify a copy constructor the compiler does a shallow
copy. Which means that it just copies the value from one class to another.

MyClass obj ( anotherMyClassObj ); //shallow copy

Now if inside MyClass contains a pointer variable( allocated by new).
Then that copy constructor does not copy the pointers value, but
they both point at the same location. This causes many troubles.

mrnutty 761 Senior Poster

Seems fine. Although you might want to Make a const MAX_NUM_OF_NAVY
then use that where ever you need it.

mrnutty 761 Senior Poster

Modulo 10?

eg:
54%10 = 4

TO expand x % 100 will give you the last 2 digits, and x % 1000 will
give you last 3 digits, and in general :

x % 10^n will give you the last n digits. IN the special case
where n = 0, the result will always be 0, since you ask to get the last "0" digits, which does not make sense.

mrnutty 761 Senior Poster

This should work. However, your all of your function does not
necessarily return something. Also use code goes here

// Purpose: Complete the program to allow the entering of 3 integer
// numbers and have the program calculate the average, maximum,
// and minimum.
//------------------------------------------------------------------------


#include <iostream>
#include <cmath>
using namespace std;

//-----------------------------------
void Display(float AveXYZ, float maxXYZ, float minXYZ);
float ComputeAve(float x,float y,float z);
float FindMax(float x, float y, float z);
float FindMin(float x, float y, float z);
//-----------------------------------

int main()
{
float x, y, z;

//read data into x, y, and z
cout << "Enter 3 integer numbers: ";
cin >> x >> y >> z;

//compute the average of x, y, and z
float AveXYZ;
AveXYZ = ComputeAve(x,y,z);

//Find the maximum of x, y, and z
float maxXYZ;
maxXYZ = FindMax(x,y,z);

//Find the minimum of x, y, and z
float minXYZ;
minXYZ = FindMin(x,y,z);

//Display average, maximum, and minimum
Display(AveXYZ, maxXYZ, minXYZ);

//terminate program
return 0;
}


//-----------------------------------
// Name: ComputeAve
// Input: the average equation
// Output: the average of x,y,z
//-----------------------------------
float ComputeAve(float x, float y, float z)
{
return (x+y+z)/3;
}
//-----------------------------------
// Name: FindMax
// Input: None
// Output: The Maximum
//-----------------------------------
float FindMax(float x, float y, float z)
{
if (x > y && x > z)
{return x;}
if (y > x && y > z)
{return y;}
if (z > x && z > y)
{return z;}
}
//-----------------------------------
// Name: FindMin
// Input: None
// Output: The …
mrnutty 761 Senior Poster

When printing a binary tree you can either print it in pre, mid, or post
order. I am not going to explain all of these. You should google them.

The usual way one would display a binary tree is by either one of the printing methods from above, pre ,post or min.

The way below is mid order :

void _recursivePrint(_Node* &Parent){					
		if(Parent != _NULL){
			_recursivePrint(Parent->leftChild);			
			std::cout << Parent->data.var <<" ";
			_recursivePrint(Parent->rightChild);			
		}
		else return;
	}

A per order would put the cout statement before the parent->leftChild
recursive call and a post order would put it after the recursive call
parent->rightChild.

What it does is it first goes all the way to the left most node. And prints
it. If the left most node has a right node, then it prints that. It "goes"
up the tree like that. Google it, better explanation out there. Its late
so I can't use my brain much.

mrnutty 761 Senior Poster

You minXYZ and your maxXYZ function name should be :
FindMin and FindMax.

So replace the word minXYZ with FindMin and replace your maxXYZ with
FindMax.

mrnutty 761 Senior Poster

Your function prototype and your function definition are not the same.

You have

void Display(float AveXYZ, int maxXYZ, int minXYZ);
float ComputeAve(int x,int y,int z);
float FindMax(int x, int y, int z);
float FindMin(int x, int y, int z);

Does this match the definition that you provide? Are the names the
same for the prototype and the definition?

mrnutty 761 Senior Poster

post your current code.

mrnutty 761 Senior Poster

Ouch, your logic is bad. You are killing your program slowly. Luckily it
fights back with the runtime exceptions.

Can you comment line by line so I see what your thinking process is.
That way you will learn better when you see whats wrong.

mrnutty 761 Senior Poster

Can you give me an example, as to how to use this, because I want to set the range of numbers.

int main()
{
   srand( time( 0 ) );

   cout << rand() % 2 << endl;
}
mrnutty 761 Senior Poster

This function :

float Display(int x, int y, int z)
{
cout << "\tAverage= " << AveXYZ << endl;
cout << "\tMaximum= " << maxXYZ << endl;
cout << "\tMinimum= " << minXYZ << endl;

return 0;
}

1st should be a void function.
Seconds you meant :

float Display(int x, int y, int z)
{
cout << "\tAverage= " << x<< endl;
cout << "\tMaximum= " << y<< endl;
cout << "\tMinimum= " << z<< endl;

return 0;
}

Third, make the x,y,z a different variable name, something more meaningful.

mrnutty 761 Senior Poster

>>denominator = 1*2*...*k

I hope you know thats not valid. 1 * 2 * 3 ... k is called the factorial of K

So if K was 5, the the denominator will be 1 * 2 * 3 * 4 * 5.

So make a function : unsigned long factorial(unsigned long num);
Where it returns the factorial of the parameters passed. So if num
was 5, then the call would be : denominator = factorial(5); // = 120

Fix that then post back, because there are other problems.

mrnutty 761 Senior Poster

You need to do a little more :

int LoadBitmap(const char* filename)
{
   GLubyte* pixels;
   HBITMAP hbmp;  
   BITMAP bmp; 
   GLuint size;
   GLenum format;
   GLuint totalBytes;

   texID++;

   hbmp=(HBITMAP)LoadImage(GetModuleHandle(NULL), (LPWSTR)filename.c_str(), IMAGE_BITMAP, 0, 0,      LR_CREATEDIBSECTION | LR_LOADFROMFILE );
   if(hbmp==NULL)
   {
	   MessageBox(NULL,L"ERROR : CANNOT LOAD FILE!",L"IMAGE LOADING",MB_OK);
	   return -1;
   }

   GetObject(hbmp,sizeof(bmp), &bmp);  				   		 
 
   size = bmp.bmHeight*bmp.bmWidthBytes;
   
   totalBytes = bmp.bmBitsPixel/8;

   pixels = new GLubyte[size];

   memcpy(pixels,bmp.bmBits,size);
	
   DeleteObject(hbmp);
   
   delete [] pixels;
   
   return 1;

}
mrnutty 761 Senior Poster

Ouch. First off your code is not very readable. In fact there are statements
in your code that you probably think is doing something else than it does.

I think we need to take this step by step, for your sake and for my eyes.

So what is your main goal? You can't just dump some code and expect
us to know precisely what you want, you know?

mrnutty 761 Senior Poster

I think you task is to make a simple anagramsolver.

Is this true?

mrnutty 761 Senior Poster

>>I need to check if two provided words doesn't have the same letter in it

By that you mean if two strings are not equal to each other.

Is this case sensitive?

If so then using tolower would be a good idea( or toupper).

Can you use std::strings , instead of c-style strings ?

mrnutty 761 Senior Poster

Ok then, some comments.

Where is ch declared in : ch == lower

Why are you returning in a void function?


Make a toUpper fuction, that takes in a char and returns the upper cased of it.

So for example :

cout << toUpper('a') << endl; //displays 'A';
cout << toUpper('A') << endl; //displays 'a';

Then you can just use a loop for a string to upper it.

string str = "upperThis";
for(int i = 0; i < str.size(); i++)
     str[i] = toUpper(str[i]);
vickietende commented: i think this code is more appropriate but could you care to put the whole code snippet and i could test how it runs +0
mrnutty 761 Senior Poster

Use toupper function in cctype header file.

mrnutty 761 Senior Poster

I assume you call CheckTimer in a loop somewhere right?

mrnutty 761 Senior Poster

don't use the sqrt function. compare the squared distance.

mrnutty 761 Senior Poster

Can you use vectors instead of arrays?

mrnutty 761 Senior Poster

You don't have to manipulate the array after being sorted.

You can use a for loop to start from 1 to the array size to show the array. This would disclude the last element. Of course you need to see a 0 at the beginning, so before the for loop just show a 0.

mrnutty 761 Senior Poster

what is "it"?

mrnutty 761 Senior Poster

yea thats not a compiler error message. you could say that its a remark, i guess the code i wrote doesnt do what it wants me to. but i dont understand what it wants. what i wrote looks right to me, but it says its wrong so its wrong.

Is "it" a online judge? If so then post the question.

mrnutty 761 Senior Poster

Thanks for your help..:) If I post my code, someone who studies in my university can find the code and copy it. Because we like research on internet and copy it:D So it become plagiarism and I can go to discipline. I am frightened about this issue.:D

Ok then.

Here are some tips.

1) Whenever you have "new" keyword used, match it with a "delete"
keyword. Make sure there is a 1 to 1 relationship there.

2) Instead of raw pointers, use smart pointers or auto_ptr.
They will destroy the pointer for you.

3) Or PM someone and they might help you out a bit more, if you want

mrnutty 761 Senior Poster

post your code and you will get more help

mrnutty 761 Senior Poster

In what sense of "Marketing"?

mrnutty 761 Senior Poster

using structs or classes would be easier and more elegant. What do
you think?

mrnutty 761 Senior Poster

The function uses the & operator. That operator makes a variable
synonym.

For example :

int num = 10  ;
int &ref_num = num;
ref_num = 4;   //same as doing    num = 4

So similarly, since this function :

istream& read(istream& is, Student_info& s)

Take a look at this part :

istream& is, Student_info& s

What ever we pass to that function ( assuming its acceptable),
is becomes a synonym, and s becomes a synonym.

So say this is how we call the that function

read( cin,  anStudentObject ); //function call

Since the prototype is :

istream& read(istream& is, Student_info& s)

and since cin is a istream object, and anStudentObject is a Student_info object, that function call is acceptable.
You remember what the & operator does right? Passing in , cin and
Student_info makes the variable, "is" and "s" synonym to cin and anStudentObject , respectively. So using the "is" variable is like
using the cin variable, its just a different name. Ok?

The reason it returns a istream object is to show you that it can.
And when you get to operator overloading you will see the significance
of it.

But know that you can do this :

Student_info& student;
//...insert info into s

//call your read function and since it returns an object, we can use it cin again
read(cin , student).clear()
mrnutty 761 Senior Poster

This shouldn't be this hard.

You want to read from a text file of the format :

Firstname;Lastname;178

where the ';' means the word has ended. And you know you will
always read firstname, then lastname, then the value. Now first
you need to open a file. Of course you know how to do that :

ifstream getFromFile("text.txt");

That opens a file to read. Now you have to read.

First lets say this is the file :

Firstname;Lastname;000
Tony;Montana;100;
Best;Forever;99;
Richard;Jones;98;
World;Hello;97;

You now need to read the file. What you can do is read 1 line into a string. Then have a function find all occurrence of ';' and replace it with a space.

Here is a complete example :

#include <iostream>
#include <string>
#include <fstream>
#include <vector>


using namespace std;

//find wherever ';' is and replace it with ' '
void wordReplace(string& source,char find = ';', char replaceWith = ' ')
{
	size_t pos = 0;

	while(true)
	{		
		pos =  source.find_first_of(find,pos);	 //find the position of ';'
		if(pos == string::npos)
			break;
		source[pos] = replaceWith; //replace ';' with a space
	}

}
int main() 
{	
	ifstream iFile("test.txt"); //open file to read
	
	if(!iFile) return -1; //check if file is opened

	string word = ""; 
	
	vector<string> fullNameWithValue;
	
	while( getline(iFile,word)) {		 //get a line into a string
		wordReplace(word); //replace ';' with ' '
		fullNameWithValue.push_back(word); //add word to out list
	}

	for(size_t i = 0; i < fullNameWithValue.size(); i++) //print out word
		cout<<fullNameWithValue[i]<<endl;

	 	
	return 0; …
mrnutty 761 Senior Poster

>>This leaves my wondering if it would be possible to use -= to decrease after each loop in any way ?

Try it. Put Fr->callEvent -= Fr->callEvent after the call to Dt->eventHandler.

mrnutty 761 Senior Poster

>>Is there a way to delete the content on the left side of += after each loop ?

Can't know for sure without knowing Fr->callEvent type, but
Assumming callEvent is a string ? You can just reset it

for (int i = 0; i < 3; i++)
{
      Fr->callEvent = "";
      Fr->callEvent += gcnew Dt->callingEventHandler(this->callEvent );
}
mrnutty 761 Senior Poster

Change this :

if (num > largest)
    largest = num; 
    count++;

to this :

if (num >= largest) {
    largest = num; 
    count++;
}

And I think it should work.

mrnutty 761 Senior Poster

Don't worry about that. Just do it with if statements.

For example to sort 2 variable you can do this :

int n = 0;
int m = 0;
cin >> n >> m;

if(n < m )
   cout << n << " " << m;
else
cout<< m << " " << n;

For 3 variables, the concept is similar.

if( num1 < num2 )
	{
		if(num2 < num3 ){
			cout << num1 << num2 << num3 << endl;
		}
		else if(num1 < num3){
			cout << num1 << num3 << num2 << endl;
		}
		else cout << num3 << num1 << num2 << endl;
	}
	else if( num2 < num3 )
	{
		if(num3 < num1){
			cout<< num2 << num3 << num1 << endl;
		}
		else if(num2 < num1 ){
			cout << num2  << num1 << num3 << endl;
		}
		else cout << num1 << num2 << num3 << endl;
	}
	else if( num3 < num1 )
	{
		if(num1 < num2){
			cout<< num3 << num1 << num2 << endl;
		}
		else if(num3 < num2 ){
			cout << num3  << num2 << num1 << endl;
		}
		else cout << num2 << num3 << num1 << endl;

	}
	else
	{
		cout<<"default\n" << num1 << num2 << num3;
		
	}

But there is an easier way . Check the input when you get the data.

int num1(0);
	int num2(0);
	int num3(0);

	int min(0);
	int mid(0);
	int max(0);

	cout << "Enter 3 numbers : ";
	cin >> num1;
	min = max …
FraidaL commented: how would I modify this if I had a 4th variable? +0
mrnutty 761 Senior Poster

Its not hard.

#include<fstream>
using namespace std;

int main()
{
   ifstream readFromFile("test.txt");
   string var1, var2;
   readFromFile >> var1 >> var2 ;
  return 0;
}
mrnutty 761 Senior Poster

read this

mrnutty 761 Senior Poster

Use the ? : operator.

mrnutty 761 Senior Poster

replace the && with the ||. You wan't the loop to run if either currentX OR currentY is not equal to toX or toY, respectively.

Also take out the

else { currentX-- } and else{ currentY-- }

there is not point since say currentX will not increment if its 100.

mrPaul commented: very good advise +0