Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can i concate two integers
like
int a=12
int b=41
c=1241

int c = (a*100) + b;

as a general rule you would not want to do that because if a or b are large enough it will cause data overflow and provide the wrong answer. If you are certain the values are small enough then it would be ok.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes. After using ClassWizard to generate all the variable names, such as m_m1 through m_m10, then create your own int array and replace all those variables with your array You will need to delete (or comment out) the m_m1 ... varaibel in the .h file and in the .cpp file. Then make the change below in the DoDataExchange() method.

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTest2Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_array[0]);
	DDX_Text(pDX, IDC_EDIT2, m_array[1]);
	DDX_Text(pDX, IDC_EDIT3, m_array[2]);
	DDX_Text(pDX, IDC_EDIT4, m_array[3]);
	DDX_Text(pDX, IDC_EDIT5, m_array[4]);
	DDX_Text(pDX, IDC_EDIT6, m_array[5]);
	DDX_Text(pDX, IDC_EDIT7, m_array[6]);
	DDX_Text(pDX, IDC_EDIT8, m_array[7]);
	DDX_Text(pDX, IDC_EDIT9, m_array[8]);
	DDX_Text(pDX, IDC_EDIT10, m_array[9]);
	//}}AFX_DATA_MAP
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> i wouldnt need c++ for dummies

If you like tossing your money away, then go ahead and buy that book! Dispite its name its not really for dummies. There are many lots getter intoduction to C/C++ books available.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

May it help?

Possibly -- if you would post a link to it so that people can test it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>"in simpelist programing"
:mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen:

I really have no idea how to do it either, but I know it is not simple and requires advanced c/c++ skills and a GUI platform, such as MS-Windows or *nix Motief (or something similar). There are several compilers that will make it a lot easier, such as Microsoft Visual Studio 2005, or even (gasp!) Borland C++ Builder.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to include iostream

#include <iostream>
// rest of program here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

its not nice to post the same question in two different threads. you will probably get mixed results and possibly conflicting answers. The answer I posted at the bottom of your other thread should work with your compiler.

you will have to use

sprintf(...)

Narue gave you an answer for a more modern compiler.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are trying to learn how to drive a car, would you start out by learning how to drive horse & buggy as people did 200 years ago? They why try to learn programming with a very very old and outdated compiler?

There are probably several ways to solve your problem. One way is to use printf() with the width specier. For example, printf("%5d", 12) will print the number 12 right-justified in a field of 5 characters -- it will be padded on the left with spaces. Replace the 5 with * and you can specify the with in the first paremter to printf. for example, printf("%*d", 5, 12);

You can use that little bit of information to format the lines like you want them. First determine the maximum width of the output -- say 123 * 11 == a 4 digit number.

printf("%*d\n",4,123);
printf("%*d\n",4,11);
printf("--------------\n");
printf('%*d\n",4,123);  // 123 * 1 = 123
printf('%*d\n",3,123);  // 123 * 1 = 123
printf("--------------\n");
printf("%d", 123 * 11);

Now, instead of hard-coding the numbers as I did above, you will want to replace the with program variables.

I know that can also be done with c++ cout, but I'm pretty lousy with that so I won't even try to show you. I prefer printf() for anything more than triviel output because to me printf() is easier to use.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>first i am using tc3 compiler
That's mistake #1. Trash it and use something more modern, such as Dev-C++ from www.bloodshed.net

>>which gives error for cstdlib
your compiler is too ancient. See above

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Main problem is that you also need to define operator=.
2. you can simplify other parts. '
3. You need better formatting style. to make the code easier to read.

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std ;

class twodimfield
{
public:
	size_t sizeP;
	string itsmali;
	int itsline, itsrow, itsFragment, nslova;
	char **polje;
	twodimfield(int nslova, string mali);
	twodimfield(const twodimfield &L);
	void operator=(const twodimfield& t);
	~twodimfield();
};


twodimfield::twodimfield(int nslova, string mali)
{
	int i;
	itsrow = nslova+1;
	itsmali = mali;
	sizeP = itsmali.size();
	itsline = sizeP;
	itsFragment = sizeP-(nslova-1);
	polje = new char * [itsline];
	for(i=0; i<itsline; i++)
	{
		polje[i] = new char[itsrow];
		memset(polje[i],0,itsrow);
	}

	for (i=0; i < itsFragment; i++)
	{
		string s2;
		for (int j=0; j<nslova; j++)
		{
			s2 += mali[i+j];
		}
		for (int l=0; l<itsrow; l++)
		{
			polje[i][l] = s2[l];
		}
	}

}


twodimfield::twodimfield(const twodimfield &L)
{
	operator=(L);
}

void twodimfield::operator=(const twodimfield &L)
{
	itsline = L.itsline;
	itsrow = L.itsrow;
	
	polje = new char * [itsline];
	for(int i=0; i<itsline; i++)
	{
		polje[i] = new char[itsrow];
		memcpy(polje[i],L.polje[i],itsrow);
	} 

	cout<<"copy constructor"<<endl;
}



twodimfield::~twodimfield()
{
	for (int i=0; i<itsline; i++)
	{
		delete [] polje[i];
	}
	delete [] polje;
	cout<<"destructor"<<endl;
}

int main()
{	
	int nslova=4;	
	string neki("mariomario");
	twodimfield objekt2(5,neki);
	twodimfield objekt(4,neki);
	objekt2 = objekt;
	cout<<objekt.polje[1][1]<<endl;

	
	system("PAUSE");
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Portability depends on the program you wrote. If you use any MS-Windows functions at all then you will have porting problems. If however you used ansi standard C and C++ then you will have few porting problems. And most *nix systems come with gnu gcc and g++ compilers installed, which I believe is the backend to Dev-C++.

The only *nix IDE I know of is canned vi. Its not really an IDE as we would know it, but a very good (and old) programmer's text editor. Learn to do command-line compiles with makefiles.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>Wow! what a screwed-up mess that can become! I would be tempted to change careers very quickly

What career can one change to when they're in an old folks home?

;)

Fish'n :cheesy:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Alright thanks for the info. Instead of making a new directory can it also be placed in an existing one.

well maybe yes, and maybe no. The user must have write permissions in the directory. But that is also true if a new folder is created. And that is why most installers require the user to be logged in with an account that has (MS-Windows) administrative privaledges or on *nix with root privaledges.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Wow! what a screwed-up mess that can become! I would be tempted to change careers very quickly.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that is not the right formula either, but it has the right idea. Entering the numbers from the keyboard will get very very timesome if you have to run the program quite a few times for debugging and testing. -- better to just hard-code the numbers in the program or save them in a file, makes debugging a whole lot easier.

you need two float variable -- numerator and denominator.

float numerator = 0, denominator = 0;
vector<float> array;
for(i = 0; i < array.size(); i++)
{
   numerator *= array[i];
   denominator += array[i];
}

float result = numberator / denominator;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look around goodle and you might find a shareware version for little or no cost. Microsoft Installer may also be free (I don't know a thing about it).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No it isn't.
Take for example two resistances. That is the simplest case. 1/R = 1/R1 + 1/R2 => R = (R1)(R2)/(R1 + R2 )

Ok so my math was wrong. But that is still pretty simple to program once the values of R1 ... Rn are known and in an array or file. The danger, of course, is with math overflow -- R1 * R2 * ... Rn can become a very very huge number that no computer on this planet has enough memory to hold when n approaches infinity. So using computer programs is only feasible for pretty small values of n.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ahh, well couldn't you do it a quick and dirty way, like creating a directory, then copying the files you wish to distribute into that directory in binary format?

I think there is a command called makedir_ or something like dat?

For very simple programs, yes that is probably the best and easiest way. Large applications are not so easy and require lots of checks and tests. Ever hear of "DLL HELL!" -- making sure the dlls or shared libraries you want to install are not older than those that are already on the computer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't think it is free -- read the link and you will find out. You can google for "install programs" and maybe find others, such as this one

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

do you mean something like Install Shield ?

If you wrote the programs yourself, then there is probably few if any limitations as to what you can distribute. But you may have to also install other DLLs or shared libraries that your program(s) depend on. For those you have to consult the author's license.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm no math whiz but isn't that formula the same as
R =1 / (r1 + r2 + ... rn)

so first you need the values for r1, r2 .. rn. where do those come from? put them into an array then you can easily calculate the formula (this has not been compiled or tested).

float foo(vector<int> array)
{
   int sz = array.size();
  float R = 0;
  for(int i = 0; i < sz; i++)
     R += array[i];
  return 1.0/R;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think the problem is the use of uninitialized variables. Set them to 0 and the output will look reasonable. I don't know if it is correct, but the program displays reasonable numbers.

int main()
{

 double length = 0, width = 0, discount = 0, carpetCost = 0, area = 0,
	 labor = 0, installPrice = 0, 
	discountedPrice = 0, Total = 0, totalCarpet = 0, totalDiscount = 0,
	subTotal = 0, Tax = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the purpose was to pass one set through pointers and the rest arrays

yes it is silly -- arrays are always passed as pointers. The below are both identical and interchangable. The problem with both of these is that they are both arrays of unspecified size. And the first one may not be an array at all but a pointer to just one int. So the function foo() has to be written smart enough to know what is going on, and the calling fuction has to pass an object of the type that foo() knows about.

foo(int *array);
foo(int array[])
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It will work as long as you open it up as a .html in your web browser. .

I thought that was what I said. However, the OP needs to clarify his question -- print to what? have a browser display the text on the screen or print it on a printer?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a popular tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If it's an html file then just open it through your C code and append <font size="+somevalue"> after beginning body tag and </font > before closing body tag.

that will work ok in a web browser, but I don't think a laser printer or other text editors such as Notepad will interpret it. It will just simply print the tags as you typed them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have Used Turbo C++ For My Text Editor.

I hope you are not using that ancient compiler in an attempt to learn the c++ language -- if you are then you will be learning the wrong language. Its like reading Shakespear to learn modern-day English, not very useful. Get one of the free c++ modern compilers, such as Dev-C++

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
struct Move
{
   Vertex orig;
   Vertex dest;
   friend istream & operator >> (istream & is, Move & m);
}; 

   istream & operator >> (istream & is, Move & m)
   {
    is >> m.orig;
       is >> m.dest;
          return is;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ can be used for anything -- nearly all the programs that run on your computer were written in either c or c++, even the operating system. Unix os was originally written in c. I think most (if not all) games are written in either c or c++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you mean you want to change front at a laser printer attached directly to your computer or on a network -- that is a pretty complex topic all in itself. There are several c++ classes that can make it somewhat easier, and all require more advanced knowledge of c++. Here is probably one of the more easier examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I can't really help much without seeing most of the code, but below won't work with filenames that contain spaces. and hopefully fname is defined to be max size for your operating system so that it can contain full path to the file. Id suggest you use std::string for the filename instead of C-style character array buffer, and use getline() instead of cin's insertion operator.

cin>>fname;
strcat(fname,".txt");

std::string fname;
getline(cin,fname);
fname += ".txt";
fstream buf(fname.c_str(),ios :: out);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if you know how to write a c++ class, you can do the project with no c-style arrays at all. Two classes and a vector should do the job.

class judge
{
public:
	long	JudgeID;
	float	weight;
};

class PianoRE
{
public:
	PianoRE() {PlayerID = Proficiency = 0; WeightFactor = 0.0f;}
	void SetPlayerID(long id) {PlayerID = id;}
	long GetPlayerID() {return PlayerID;}
	void SetProficiendy(long prof) {Proficiency = prof;}
	long GetProficiency() {return Proficiency;}
	void SetWeight(float w) {WeightFactor = w;}
	float GetWeight() {return WeightFactor;}
	void SetJudge(const judge& j) {judges.push_back(j);}
	const vector<judge>& GetJudges() {return judges;}

protected:
	long	PlayerID;
	long	Proficiency;
	float	WeightFactor;
	vector<judge> judges;

};

or if you cannot yet handle that, you can create a structure and make a linked list of those structures

struct judge
{
	long	JudgeID;
	float	weight;
        struct judge* next;
};

struct PianoRE
{
	long	PlayerID;
	long	Proficiency;
	float	WeightFactor;
	struct judges*  HeadJudge;
        struct PianoRE* next;
};

now just learn how to do linkes lists, and again you need not use
any c-style arrays.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you attempt to use try/catch blocks as I posted earlier? compilers are not required to return NULL.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> int answer = ( (*a) * (*b) );
what is the intent of ^^^ that line? variables a and b are used before they are initialized and will surely cause your program to crash. Just simply code it like this:

int answer;

>> a = &x[11];
that ^^^ is setting variable a to point to an element of x that is beyond the end of the array. array indices in your example are numbered 0 to 10. So if you want variable a to point to the last element of x, then it should be like this

a = &x[10];

But if you want variable a to point to the first element of x, then do this

// the following two lines do the same thing.
a = x;
a = &x[0];

>> for( int i = 1; i < a; i++ )
Variable a is a pointer -- why would you want to use a pointer like that?

>> for( int j = 1; j < y; j++ )
variable y is an array of integers. and you can't use the name of an array in an expression like that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So, according to your description
Player ID = 6010
Proficiency Level = 1
Weight Factor = 1.3
Judge = 23
Score = 7.0

Then the next set is
Player ID = 25
Proficiency Level = 8.5
Weight Factor = 34
Judge = 7.0
Score = 12


That doesn't look right to me because the numbers in the first set are not the same type as those in the second set. You need to clarify what that data rally means before you can write a program to read them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see any code that actually enlarges the 2d matrix. it just copies data from one array to another then back to the original again. how is myGrid defined? Is it dynamically or statically allocated? You need to post a bit more code that shows these details.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What is Library Directories & Include Directories & Resource Directories?
Please use my downloaded linkgrammar folder, link41b as an example.

Library directory: the directory (or folder) that contains library files (file with .lib extension). You need not specify the compiler's standard library path (see your compiler installation directory)

Include directory: the directory that contains include files (with a .h extension or sometimes no extension at all). You need not specify your compiler's standard include directories (see your compiler's installation directory).

resource directory: the directory where you put the *.rc file(s) and other resources, such as icons and bitmaps.

You can leave all those direcories blank if you do not use them.

>>Please use my downloaded linkgrammar folder
Use your own head and attempt to figure it out yourself. Use your head for something other than a hat rack.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

my gcc v3.3 doesnt support exception.

Then it isn't a c++ compiler so it will not support new and delete either. :eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>when new is unable to allocate the specified memory it will return NULL

No it doesn't. c++ standards say that new throws an exception when there isn't enough memory, although Microsoft compilers may still return NULL as well. There may be better ways to code this exception handling routine, but this is the basic concept.

int *array;
try
{
   array = new int[100];
}
catch(...)
{
   cout << "out of memory" << endl;
   return 1;
}

[edit] Just found this one too that doesn't throw an exception

array = new (std::nothrow) int[0x3fffffff];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If MC is a C or C++ compiler, you have to put a number inside those brackets to tell it how big that array is going to bel
Record ListOfRecords[100];

You don't need another pointer in order to pass it to another function.

// use only ONE of the following, not all three.  It shows three ways 
// to code the function.
void foo(Record ListOfRecords[100])
void foo(Record ListOfRecords[]) << this is also ok
void foo(Record* ListOfRecords) << so is this
{
   // blabla
}

int main()
{
   Record ListOfRecords[100];
   // pass the array to function foo()
   foo(ListOfRecords); <<< see here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

here is a few free source files -- browse around that site and you might find additional help. Otherwise its just a c and c++ compiler that compiles normal programs.

Browse around your compiler's menues and test out some of its options. That's the best way to learn it. Start with File --> New --> Project.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you posted the entire function then what you did is probably as simple as any. you could use a switch statement, but it doen't shorten or reduce your program and might actually increase the bulk of the program.

switch(ch)
{
  case 'a': ++array[0]; break;
  ...
}

If you need to evaluate all (or most) of the 255 possible characters, then you could use the character as the index into the array.

int array[255] = {0};
...
int ch;
while( (ch = getch() ...)
{
   ++array[ch];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> helping me understand Visual C++ 2005 better

I have problems with that compiler too and I've been programming for over 25 years! My opinion -- it is not a very good compiler for beginners to learn programming because it takes a lot of time just to learn how the compiler works. Dev-C++ is better for beginners to intermediate programmers because the IDE is pretty simple to use.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> But I would like to test it in C ( not in vc).

VC is the name of a Microsoft compiler, not a computer language. It compiles both C and C++ code just like any other compiler will do. Give the file a *.c extension and the compiler will compile it as a C program.

You could also use free Dev-C++ from www.bloodshet.net. Dev-C++ is another compiler whose name might be confusing -- it also compiler C as well as C++ code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

graphics is an advanced programming topic that you are obviously not yet ready to tackle. Learn the language and in about 6 months or so you MIGHT be ready. And it depends on the compiler and operating system you are using.

Why do you need tutorials? most text books cover introduction to programming and are a lot better than any tutorials you may find online. Just study your textbook, listen carefully to your instructor, practice (do the exercises) and ask your instructor plenty of questions you may have.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

by the way, I really want to know where you are from

I am not from Japan.

Now that we know where you are NOT from, where among the 1,000 or so other nations on this earth are you from :cheesy:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A lot depends on the program you are writing. Two hints:
1. Using c++ std container classes instead of C-style dynamically allocated objects is the first place to start -- assuming your compiler supports those container classes, not all c++ compilers do.
2. If you are writing Microsoft Windows programs you have to be careful about the system-wide resources that your program allocates, make sure the program frees/releases the resources before terminating.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Moe: does that Borland 5.5 compiler support long filenames (it too is pretty old) If it does NOT then you will have to get a different compiler. Otherwise if it does then it should be ok.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

first you have to know how to create projects with that compiler. You cannot use just one of the *.c files from that library, but you have to compile all of them and link them all together. There are 29 *.c files that you must compile and link together. If that is a command-line driven compiler you will probably have to create a makefile that contains all the instructions your compiler needs to compile all those *.c files and create the executable program. If you would get the free copy of VC the IDE will do that for you. If you have IDE with Borland then it might do it too.

You should not have copied the *.h files into your compiler's include directory. That directory should just contain the files that are supplied by your compiler. Compilers have options to tell it where else to look for include files. VC++ has -I flag, such as "I\c:\mydirectory\include" will tell the compiler other .h files are located.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to pay more attention to semicolons and placement of braces. There are other problems than I identified below, but fix these first.

#include <iostream>
#include <iomanip.h>
const int size = 100;
void generate (float x[][size], int n, float&xij)
{
        for (int i=0; i<n; i++)
        {
                for (int j=0; j<n; j++)
                cout.width(6);
                /* variable j is undefined below this line because of the
                lack of braces.*/
                cout.precision(3);
                        cout<<x[i][j]<<"\t";
                cout<<endl;
                xij = 1.0/(i+j);
        }
}
void transpose(int x[][size], int xt[][size])/*<< what is this???  It looks like a function prototype, but is missiong a semi-colon at the end.  function prototypes normally eppear at the beginning of the file, not scattered throughout the program unit.*/

void multiply (int xxt)
{
        int x, xt;
        xxt = x * xt;
       /* This function does nothing.  It probably should
          return the result of the multiplication.  Where are variables x and
          xt initialized?  they just contain garbage */
}
main ()
{
        int i,j,xt,xxt,x;
        cout<<"Enter number of row(s) for the matrix:"<<endl;
        cin>>n1>>endl;
        cout<<"Enter number of column(s) for the matrix:"<<endl;
        cin>>n2>>endl;
        void generate (array);  /* where is variable `array` defined? */

        for (i=0; i<n; i++)
        {
                for (j=0; j<n; j++)
                cout<<setw(6)precision(3)x[i][j]<<"\t"\

                /* x above is not an array but you are using it like one.  See
                   definition of x at the beginning of main() missing close brace 
                   probably here.*/

void transpose (x[][], xt[][]);
           /* and line below.  these are nothing more than function prototypes.  
              They do not call the functions.  move both lines near the top …