Ejaz 0 Newbie Poster

ok,

ifndef MY_HEADER_FILE
#define MY_HEADER_FILE

// ... Here goes the implementations

#endif // MY_HEADER_FILE

Ejaz 0 Newbie Poster

Well, I haven't seen the files but here is my guess. The most common reason while compilation of this error is that, you include a file in one file and include the same file in some file (there is no problem so far) and after that in some other file, you include both files, now since both files contains the definations of the original file, the compiler goes through the first one and when it finds that the other file also has the same definations that the other had, then it start complaining.

I suggest to use inclusion guards (preferably in all the files, with different identifiers) and try your code, like

#ifndef _MY_HEADER_FILE_
#define _MY_HEADER_FILE_

// ... Here goes the implementations

#endif // _MY_HEADER_FILE_

If the problem persists, please post the error code with its descripition.

Ejaz 0 Newbie Poster

The two different implementations can acheive the same results, but they belong to two different familes. One is strucutural and you'll find the C implementations like that (although it does work in C++ as well).

Where as classes are part of C++, which applies Object Oriented approach to solve the problems. In C++, the concept is like, you implement the algorithms in terms of class member functions and these can be accessed through the object (instance) of the class. (for static methods, you don't need the object of the class). This approach gives you good abstraction, encapsulations of data and many other benefits.

There is another pradigm, referred as Generic Programming, where the implementations are done through templates (like STL).

Ejaz 0 Newbie Poster

Take a look at http://cse.yeditepe.edu.tr/~osertel/courses/CSE211/materials/lect6.pdf,
You'll find the explaniations in it.

Ejaz 0 Newbie Poster

What compiler are you using? I had this problem way back, when I was in learning phase and used Turbo C++, and I had to stop it manually, in MS Visual C++ console applications, it is handled automatically.

You can use

system("pause");

in the end or its equivalent to stop it. (and if it didn't work, then you can do what I did, I used getch() and displayed a messaged myself when I used Turbo C 3.0 ;) )

Ejaz 0 Newbie Poster

Yes, you can write all the 3 class definations in one header file and implementation in one source file (in fact, you can write everything in one file as well).

// Class delarations
class A
{
	A();
	~A();
	void MethodOfA();
};

class B
{
	B();
	~B();
	MethodOfB();
};

class C
{
	C();
	~C();
	MethodOfC();
};

// Class Implmentations
A::A()
{
	// A ctor
}

A::~A()
{
	// A ~ctor
}

void A::MethodOfA()
{
	// MethodOfA
}

// ******************
B::B()
{
	// B ctor
}

B::~B()
{
	// B ~ctor
}

void B::MethodOfB()
{
	// MethodOfB
}

// ******************
C::C()
{
	// C ctor
}

C::~C()
{
	// C ~ctor
}

void C::MethodOfC()
{
	// MethodOfC
}
Ejaz 0 Newbie Poster

One solution can be, before inserting the new no. in the array, scan the array (iterate through it), to see whether the no. is already in the array or not, if not, insert it and yes, loop again.

You can either iterate by simple loop or if you manage to create the array in sorted order, then you can use binary search (which is much faster) to serve the purpose.

If you can use STL, then you can use vector and find algorithm, which can make your life much easy.

Ejaz 0 Newbie Poster

try this,

struct SData
{
	char  	name[128];
	int 	Values[3];
};

SData myData[3];

strcpy( myData[0].name , "Name 1");
myData[0].Values[0] = 1;
myData[0].Values[1] = 2;
myData[0].Values[2] = 3;

strcpy( myData[1].name , "Name 2");
myData[1].Values[0] = 4;
myData[1].Values[1] = 5;
myData[1].Values[2] = 6;

strcpy( myData[2].name , "Name 3");
myData[2].Values[0] = 7;
myData[2].Values[1] = 8;
myData[2].Values[2] = 9;

int total[3];
for (int i = 0; i < 3; i++)
	total[i] = myData[i].Values[0] + myData[i].Values[1] + myData[i].Values[2];

cout << total[0] << endl << total[1] << end << total[2] << endl;

The code may contain some typo errors, haven't compiled it, just typed it. Btw, is it an assignmnet? Are you allowed to use STL???

Ejaz 0 Newbie Poster

I have MFC Application which expected to generate reports in XML formats, my problem I do not have an idea for how simply dealing with XML as found in .NET (XmlDocument Class).
can u suggent me with solution?


Regards

Take a look at this

Ejaz 0 Newbie Poster

Here is what I have

#include <iostream.h>

int main() {
int i, total[3];
int myValue[3][3];

myValue[0][0] = 53,000;
myValue[0][1] = 5;
myValue[0][2] = 1;


myValue[1][0] = 89,000;
myValue[1][1] = 3;
myValue[1][2] = 2;

myValue[2][0] = 93,000;
myValue[2][1] = 3;
myValue[2][2] = 3;

for (i = 0; i < 3; i++)
{
total = (myValue[0]/1000) + (myValue[1] - myValue[2]);
}

cout << total <<endl;
return 0;

}


For some reason, I can't get the array to print at all.....It justcomes up with the initial value of 3, Im fairly new to programming.

Original Problem

I have the formula A/1000 + B - C. I need write a program that readsa the file and determines a priority number (like above). Then the prorgam needs to build a priority queue using the priority number and prints a list in accending order.

Try this

int i, total[3];
	int myValue[3][3];

	myValue[0][0] = 53000;
	myValue[0][1] = 5;
	myValue[0][2] = 1;


	myValue[1][0] = 89000;
	myValue[1][1] = 3;
	myValue[1][2] = 2;

	myValue[2][0] = 93000;
	myValue[2][1] = 3;
	myValue[2][2] = 3;

	for (i = 0; i < 3; i++)
	{
		total[i] = (myValue[i][0]/1000) + (myValue[i][1] - myValue[i][2]);
	}

	cout << total[0] <<endl;
	cout << total[1] <<endl;
	cout << total[2] <<endl;

Don't put commas in the numeric figures.