William Hemsworth 1,339 Posting Virtuoso

If all your trying to do is sort int's / floats you are doing it the hard way, all you have to do is convert each string you input to a float and then sort them. So you can delete the other two functions (lrg, posd). Something thing you should aim to improve is your formatting, some parts of the code were very difficult to understand. And finally, not the biggest mistake in the world but you shoulden't use system("pause"), reason here: http://www.gidnetwork.com/b-61.html

But what I have done is converted the strings to floats by using atof and then sorted them. As atof can only handle plain char* strings you have to convert them by using string::c_str().

#include <iostream>
#include <string>

using namespace std;
   
int main(void)
{
	int n;
	string numz[200];

	cin >> n;

	for (int i = 0; i < n; i++) {
		 cin >> numz[i];
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (atof(numz[j].c_str()) > atof(numz[j+1].c_str())) {
				numz[j].swap(numz[j+1]);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		 cout << numz[i] << ' ';
	}

	//cout << numz[0];

	// Pause the better way
	cin.ignore();
	cin.ignore();

	return 0;
}

I have colored the main changes I made, hope this helps.

William Hemsworth 1,339 Posting Virtuoso

I have formatted the code for you and fixed it to the way it should have been done. :icon_neutral:

#include <iostream>
#include <vector>

using namespace std;

class Pair {
private:
	int x;
	int y;
public:
	Pair(int a, int b) {
		x = a;
		y = b;
	};
	int get_x() {
		return x;
	};
	int get_y() {
		return y;
	};
};

int main()
{
	vector<Pair> set;

	Pair a1(70, 64);
	set.push_back(a1);

	cin.ignore();
	return 0;
}

Hope it helps.

William Hemsworth 1,339 Posting Virtuoso

Many problems in the code.. but this will remove the error:

#include <iostream>
#include <vector>

using namespace std;

class Pair {
public:
Pair(int a, int b)
{x=a; y=b;};
int get_x()
{return x;};
int get_y()
{return y;};
private:
int x;
int y;};

int main()
{vector<Pair> set;
Pair* a1 = new Pair(70, 64);

set.push_back(*a1);


system("PAUSE");
return 0;
}

- Dont use system("pause")
- Format your code better
- Use code tags

William Hemsworth 1,339 Posting Virtuoso

I think you need to learn how to use pointers. Heres a tutorial:
You probably only need to look at the Pointer initialization section.
http://www.cplusplus.com/doc/tutorial/pointers.html

William Hemsworth 1,339 Posting Virtuoso

If it says 'Release' just to the right of the run (Start Debugging) icon then when you run or compile the project it will have compiled as release, but the reason I think you get the error message (Which I always used to get) is because the computer without MSVC doesn't have the correct netframe, thats the reason I started plain Win32 / MFC because .NET projects arent very portable.
Downloading http://www.microsoft.com/downloads/details.aspx?FamilyID=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en
should fix the problem on the other computer.

William Hemsworth 1,339 Posting Virtuoso

To Build the project in release, click on the drop down menu by the run icon and set it to 'Release' then compile it. The program should be under the directory 'Visual Studio 2008\Projects\PROJECTNAME\Release\PROJECTNAME.exe'

William Hemsworth 1,339 Posting Virtuoso

The other computer you are testing it on probably does have the required .NET framework to execute the program.

William Hemsworth 1,339 Posting Virtuoso

For C you can use these functions:

#include<iostream>
using namespace std;

typedef unsigned char UCHAR;

template<class t> inline
char *toBase(t val, char base, char *values) {
	register char d = 1; t c;
	register bool _signed = val < 0;

	if (val >= 0) for (c = base; c <= val; c *= base, d++);
	else for (c= -base; c >= val; c *= base, d++);

	register char i = d + _signed;

	char *bin = new char[i + 1];
	if (_signed) bin[0] = '-';

	for (val *= base; i - (_signed); i--)
		bin[i - 1] = values[(val /= base, (
		(val % base) < 0 ? -(val % base) : (val % base)))];

	bin[d + _signed]='\0';
	return bin;
}

inline char GetIndex(char *str, char c) {
	for(UCHAR i = 0;; *str, i++)
		if(*str++ == c) return i;
	return 0;
}

template<class t> inline
t fromBase(char *val, char base, char *values) {
	t v = 0;
	for (char i=val[0]=='-';val[i];i++) {
		v*=base;
		v+=GetIndex(values, val[i]);
	}
	return val[0]=='-'?-v:v;
}

int main() {

	// 0100101111111 in hex
	int decimal = fromBase<int>("0100101111111", 2, "01");
	char *hex = toBase(decimal, 16, "0123456789ABCDEF");
	cout << hex << '\n';

	// 3F16 in binary
	decimal = fromBase<int>("3F16", 16, "0123456789ABCDEF");
	char *bin = toBase(decimal, 2, "01");
	cout << bin << '\n';

	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

can you just do

Form2->Text = "write something";
William Hemsworth 1,339 Posting Virtuoso

try

Int32::Parse(stringname)
William Hemsworth 1,339 Posting Virtuoso

Dont know why.., but I made the entire class for you (and me), including a parser and just about every operator available :)

Some examples on how it works:

  • fraction(33,99) automaticly turns into 1/3
  • Parser will work with spaces e.g
    fraction f = "1 /2 /    3";

    is the same as 1/2/3 (1.66666)

  • fraction f = 12.2; // f will cout "12/1/5"

Code is getting abit big so I have attached the code.
If you find any problems with it, let me know :icon_wink:

William Hemsworth 1,339 Posting Virtuoso

And the multiplication is faily easy:

fraction operator *(fraction &fraction2) {
	int n1 = Numerator;
	int d1 = Denominator;
	int n2 = fraction2.Numerator;
	int d2 = fraction2.Denominator;
	fraction f(n1 * n2, d1 * d2);
	f.Shrink();
	return f;
}
William Hemsworth 1,339 Posting Virtuoso

Heres the corrected code:

#include<iostream>
using namespace std;

class fraction {
public:
	int Numerator;
	int Denominator;
	fraction(int n, int d) {
		Numerator = n;
		Denominator = d;
	}
	bool Shrink() {
		bool sucessful = 0;
		for (int i = min(Numerator, Denominator); i; i--) {
			if ((Numerator % i == 0) && (Denominator % i == 0)) {
				Numerator /= i;
				Denominator /= i;
				sucessful = 1;
			}
		}
		return sucessful;
	}
	fraction operator +(fraction &fraction2) {
		int n1 = Numerator;
		int d1 = Denominator;
		int n2 = fraction2.Numerator;
		int d2 = fraction2.Denominator;
		int MatchedDenominator = d1 * d2;
		fraction f(
			((MatchedDenominator / d1) * n1) + 
			((MatchedDenominator / d2) * n2)
			,MatchedDenominator);
		f.Shrink();
		return f;
	}
	void Display() {
		cout << Numerator << '/' << Denominator;
	}
};

int main() {
	fraction f1(235, 1000);
	fraction f2(2, 10);
	fraction f3 = f1 + f2;
	f3.Display();
	cin.ignore();
	return 0;
}

Should work perfectly :)

William Hemsworth 1,339 Posting Virtuoso

You might have correct abit of that ^^, but its the right idea. My maths isn't that amazing.

William Hemsworth 1,339 Posting Virtuoso

Perhaps a class like this might help.. Ive done abit for you.

#include<iostream>
using namespace std;

class fraction {
public:
	int Numerator;
	int Denominator;
	fraction(int n, int d) {
		Numerator = n;
		Denominator = d;
	}
	bool Shrink() {
		bool sucessful = 0;
		for (int i = min(Numerator, Denominator); i; i--) {
			if ((Numerator % i == 0) && (Denominator % i == 0)) {
				Numerator /= i;
				Denominator /= i;
				sucessful = 1;
			}
		}
		return sucessful;
	}
	fraction operator +(fraction &fraction2) {
		int n1 = Numerator;
		int d1 = Denominator;
		int n2 = fraction2.Numerator;
		int d2 = fraction2.Denominator;
		int MatchedDenominator = d1 * d2;
		n1 = MatchedDenominator / d1;
		n2 = MatchedDenominator / d2;
		fraction f(n1+n2,MatchedDenominator);
		f.Shrink();
		return f;
	}
};

int main() {
	fraction num1(1, 2);
	fraction num2(1, 3);
	fraction num3 = num1 + num2;
	cout << num3.Numerator << '/' << num3.Denominator;
	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

It works because each character contains a value, for example:

'A' is equal 65 // 01100001

01000001 // 65
OR    00100000 // 32
     ----------
      01100001 // 97

97 = 'a'

William Hemsworth 1,339 Posting Virtuoso

This function converts a string to lowercase usering OR

char *ToLowerCase(char *text) {
	char *str = new char[strlen(text)];
	register int i;
	for (i=0;text[i];i++)
		str[i] = text[i] >= 'A' && text[i] <= 'Z' ?
		text[i] | 32 : text[i];
	str[i] = '\0';
	return str;
}
William Hemsworth 1,339 Posting Virtuoso

Are you sure that if you just start a new Win32 application and add '#include<windows.h>' to the start of it that it wont find it ?

William Hemsworth 1,339 Posting Virtuoso

You have to include the parameters in the open() function.
When opening the file just have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

instead of

myfile.open ("lover_names.txt"); ios::ate;

That is all, then you can simply just write to the end of the file by using:

myfile << "Text";
William Hemsworth 1,339 Posting Virtuoso

also, it might help to have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

So it automaticly seeks the end of the file before you begin writing to it.

William Hemsworth 1,339 Posting Virtuoso

Well, it is fairly obvious where the changes are, but I added

do {

where the loop should start and just before the end theres:

} while (!security);

so that the loop will only break if the variable 'security' is true.

William Hemsworth 1,339 Posting Virtuoso
//Login

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()

{
   
   
    cout << "\tWelcome to Login\n";
    int security = 0;
    

    do {
    string username;
    cout << "\nUsername: ";
    cin >> username;
    
    string 
    password;
    cout << "Password: ";
    cin >> password;
    
    if (username == "echoestroy" && password == "561654")
    {
                 cout << "\nWelcome Echoestroy.";
                 security = 5;
    }
    
        if (username == "krissyk6" && password == "spike")
    {
                 cout << "\nWelcome Krissyk6.";
                 security = 5;
    }
    
        if (username == "cjochoate" && password == "troy")
    {
                 cout << "\nWelcome cjochoate.";
                 security = 5;
    }
    
        if (username == "guest" || password == "guest")
    {    
                 cout << "\nWelcome Guest.";
                 security = 1;
    }
    
    if (!security)
       cout << "\nYour login has failed. Please check your username and password and try again";
    } while (!security);
       

    getch(); 
    return 0;

}

this should work.

William Hemsworth 1,339 Posting Virtuoso

not sure, but for doing clicks, you can just do:

mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, x, y, 0, 0);

for a right click

William Hemsworth 1,339 Posting Virtuoso

This code with print all the characters from any file to the console.

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

const char fileName[] = "FILENAME";

int main() {
	ifstream in(fileName, ios::in | ios::binary);
	while (in) {
		cout << (char) in.get();
	}
	system("pause");
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Why dont you say whats not working first..

William Hemsworth 1,339 Posting Virtuoso
int positionen = 0;
positionen = textBox1->SelectionStart;
this->textBox1->Select(0, 5);
this->textBox1->SelectionColor = Color::Blue;
this->textBox1->DeselectAll();
this->textBox1->SelectionStart = positionen;
this->textBox1->SelectionColor = Color::Black;

Hope it helps =]

William Hemsworth 1,339 Posting Virtuoso

Here is how I learn Win32 API, It is a very good tutorial: http://www.rohitab.com/discuss/index.php?act=Attach&type=post&id=698