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

Actually, I do write programs with user interfaces in emacs IN Linux. -Fredric

Its really all a matter of gaining experience. gtkmm, and fltk may be easy for you to use because you have learned how to use them. MFC is (pretty much) easy for me to use for the same reason. I don't have to look up everything in MSDN any more either, but I'll bet we both had to do that when we first starting learning the libraries. So I think is not really a matter of "which is better, MFC or gtkmm", but of which one you want to spend a lot of time (in terms of months) learning. MFC has about a one year learning curve to learn it well. I have no idea about gtkmm and fltk.

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

Your program compiles and links without error using VC++ 6.0 compiler, just like WolfPack said it would. I tried the same thing with Visual Studio 2003 and got the same error that you did, but unfortunately I havn't been able to figure out the problem either.

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

Is there any such limitations in 32-bit systems?

I think there is a 2Gig limit on a 32-bit os because of the limitations of unsigned long.

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

read those error messages again. The compiler (really the linker) is saying that one or more functions are missing. And it tells you the name of them.

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

If you still want to stick to calloc, malloc etc. then try farmalloc or halloc i.e. you may have to change the memory model.

Those two functions are only available on ancient 16-bit compilers such as Turbo C. Modern 32-bit compilers have no such functions. OP didn't say what compiler or operating system he is using.

i want to create an array of size 1 million bits.

arrays are allocated in bytes, not bits. so 1 million bits on most computers will be 1,000,000 / 8 = 125,000 bytes. :)

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

what function(s) did the compiler say was missing? Look at your code and see if you coded them. If they are in a library somewhare did you include the library?

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

your code is missing parentheses. Without parentheses, only the first line after the if statement belongs to the condition, all other lines will be executed regardless of the if condition.

if(flag == 1)
  {
	printf("*********************************************************************\n");
	printf("*******************  item found  ********************\n");
	printf("*********************************************************************\n");
  }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In my opinion, if you can sit down in a simple text editor, and without looking at any notes, write out the code for a simple application, then you are using the right libraries for the job. If you have to constantly look things up in a help menu or go to online tutorials, then you are using the wrong libraries for the job.

Bullpucky! All you want to do then is write console applications. There is NO GUI operating system or set of libraries that are that easy to use. If you think MFC and MS-Windows is difficult, then switch to *nix and use X11 and Motif. or program for MAC os. Or if you want to use a simple text editor such as Notepad.exe then you should be writing HTML code, not C or C++.

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

what don't you like about it? just calling something "a piece of junk" is not very helpful. Do you have a better resource editor in mind? That's my opinion of QT too, but that doesn't mean it is no good -- it only shows my inexperience with the product.

Doesn't do bitmaps very well, but you can use other pait programs to create *.bmp files then import them into VC++ 6.0 project.

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

My main beef with MFC is its resource editor

MFC (Microsoft Foundation Class) doesn't have such a thing as a resource editor. MFC is a library of functions, not a compiler or IDE.

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

depends on the operating system. QT is portable between both *nix and MS-Windows. The others are not portable. I'm not a *nix programmer, so I can only say that on MS-Windows the Visual Studio .NET 2003 (2005 coming out this month) are the best. But again, it is not portable to other operating systems. You might also check Borland products.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
tmp[r][c] == 0;

The above is probably wrong. My compiler, VC++ 6.0, produced a warning -- your should have too.

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

when the string is found, check the character immediately before and after to see if it is a space. If not a space, then the string is not what you want.

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

Can individual users, such as color blind people, customize the colors? They may not be able to easily read text that is in green, such as inside code tags.

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

Its been my experience that .dat files contain binary data, such as the computer's binary representation of an integer and not the ascii digits that you will find in a text file. .dat files normally can not be easily read by text editors such as Notepad.exe.
Exemple:

struct mystruct
{
   int a;
   long b;
   float c;
   double d;
};

int main()
{
    myruct s 

   // write the structure to the file
   ofstream out("mydata.dat", ios::binary);
   out.write((char *)&s,sizeof(s));
   out.close();

   // now read the file
   ifstream in("mydata.dat", ios::binary);
   in.read((char*)&s,sizeof(s));
   in.close();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want the clock in the display to tick off the time while you are typing in another control (such as an edit control), then use SetTime() to set an event to happen once a second. Then in that timer event update the clock display with current time. See MSDN for SetTimer() function.

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

unless you just happen to have the source code for notepad and MSWord (which is not very likely), the first two questions are nonsense and unanswerable unless they are answered in the text book where you got those screwy questions.

I don't know the answer to 3.

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

ok so would the following statement work then?

char *str[5];
str[0] = "123";
int n = atoi((LPCTSTR)str[0]);

you don't need to typecast character arrays -- that typecast is to convert a CString object to const char*.

char *str[5];
str[0] = "123";
int n = atoi(str[0]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

for CString (I assume you mean Microsoft MFC CString class)

// convert from CString to int just requires typcasting the CString
CString str = "123";
int n = atoi((LPCTSTR)str);

// convert from int to CString
str.Format("%d", n);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The two loops are not correct. Outer-most loop runs from 0 to (start-1). Inner-most loop runs from (outer_loop_counter+1) to start. There are other ways to do it, but I find this algorithm the most logical (easiest to comprehend) because neither loop counts backwards.

void sortAssending(int nums[], int size)
{
     for (int start=0; start< (size-1); start++)
     {
         for (int end=start+1; end < size; end++)
         {
             if (nums[start] > nums[end])
             {
                 int temp = nums[start];
                 nums[start] = nums[end];
                 nums[end] = temp;
             }
         }
     }
}
server_crash commented: thanks +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sprintf("Got Data: %s\n", buffer);

The above is wrong. Was it just a posting error or is it really like that in your program ?

sprintf(InputBuffer, "Got Data: %s\n", buffer);

or

strcpy(InputBuffer,"Got Data: ");
strcat(InputBuffer,buffer);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now the thing works but it takes about 6 hrs to run

LMAO :lol: :lol: :lol: Sorry for laughing so much! But the last time I heard something like that was way back in 1987 on an old Unix computer -- the program (no, I didn't write it) took 48 hours to run. I rewrite it in C and got it to run in under 10 minutes.

Post your program and I'm certain someone will help you with it.

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

set a timer event for the amount of time you want it displayed, then in the event handler kill the message box -- send it WM_CLOSE event.

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

I think you will want to search here and ask that question on one of its public forums.

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

where are 26 days between 5 and 31 Jan (31-5=26). 26 in Jan + 28 days in Feb = 54.


There are 60 days between 1 Jan 2000 and 1 March 2000 -- year 2000 was a leap year.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int calcDays(int month, int day, int year)
{
	int i;
   int numDays = 0;

   for(i=1850; i<year; i++)
   {
       numDays += 365;

       if (isLeapYear(i))
           numDays++;
   }

   for (i=1; i<month; i++)
   {
       switch (i)
       {
           case 1: case 3: case 5: case 7: case 8: case 10: case 12:
               numDays += 31;
               break;
           case 9: case 4: case 6: case 11:
               numDays += 30;
               break;
           case 2:
               numDays += 28;
               if (isLeapYear(year))
                   numDays++;
               break;
       }
   }

   numDays += (day-1); // excludes the current day

   cout << numDays << endl;

   return numDays;
}

and use absolute value of the two days because the first value may indeed be less than the second, such as if the first date entered is 1850-01-01 the calculation is 0.

// I thought this was where I was getting the negative number from,
// so i put the 'if' statements around it but that still seems to fail.
   int days = calcDays(montha,daya,yeara) - calcDays(monthb,dayb,yearb);
   days = abs(days);
   cout << days << endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, forget the array stuff. Just fix the other problems.

the first problem with your last post is setting the dbd to the wrong value.

dbd = year - 1;

   for (int i = 1850; i<dbd; i++)
   {
       dd += 365;

       if (isLeapYear(i))
           dd++;
   }

then when calculating the number of days in a month, you need to increment the number of days when current year is a leap year. Also, it doesn't need that while statement around the loop or the m counter. This will cause the program to sum up the number of days multiple times (If it's December, it will sum up the days 12 * 11 times!).

case 2:
                   numDays = 28;
                   if( isLeapYear(year) )
                      numDays++;
                   break;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

dbd should be year-1, not year-1850.

for the days in current year, you need to use a table that will contain the cumulative number of days from 1 Jan to the end of the previous month. Using a table for this saves a lot of time because loops are expensive. For example

static short MonthDays[13] =
	{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};

So if current date is 15 March, the number of days from 1 Jan to (but not including) 1 March is MonthDays[2] (where Jan = 1, Feb = 2 ...), or 59. If this year is a leap year then add one.

Finally, just add to the previous total the day of the current month.

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

make the variables global and don't pass any parameters. An alternative (and better) is to make a c++ class to hold data and associated methods.
[edit]Note: I did not run your program. Only made it compile without errors. :rolleyes: [/edit]

#include <iostream>
using namespace std;
void DisplayMenu(void);
void Enter_Inventory();

int Display_Inventory();
void Purchase_Soda();

int inventory_number_coke=0;
int inventory_number_pepsi=0; 
int inventory_number_cd=0; 
int inventory_number_hires=0;
	

int main()
{
	const char SENTINEL = 'Q';
	char Choice;

	do
	{
		DisplayMenu();
	
		cin >> Choice;
		cout << " " << endl;

	switch (Choice)

	{
		case 'E': case 'e':
			void Enter_Inventory();
			break;
		case 'P': case 'p':
			void Purchase_Soda();
			break;
		case 'S': case 's':
			cout << "This is sell" << endl;
			break;
		case 'D': case 'd':
			cout << "This is display" << endl;
			break;
		default:
			cout << "You typed in your entry wrong! Please choose again." << endl;
	}
	
	} while (Choice != SENTINEL);

	return 0;

}

void DisplayMenu(void)
{

	cout << "(E)nter inventory" << endl;
	cout << "(P)urchase soda" << endl;
	cout << "(S)ell soda" << endl;
	cout << "(D)isplay inventory" << endl;
	cout << "(Q)uit program" << endl;
	cout << " " << endl;
	cout << "Please choose by typing the first letter of your choice below." << endl;
	cout << " " << endl;
	cout << "Choice? ";
}

void Enter_Inventory()
{
	int product_value;
	int INC, INP, INCD, INH;
	
	
	cout << "Enter the product number of the inventory you want to submit!" << endl;
	cin >> product_value;

	cout << "Please enter the number of cases" …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you had coded it like this, it would have worked. The constructor without parameters is never used in this example.

#include<iostream>
using namespace std;
class A
{
	int a;
	float b;
public:
	A()
	{
		a=0;
		b=0;
	}
	A(int m)
	{
		a=m;
		b=0;
		cout<<"values are "<<a<<endl<<b<< endl;
	}
};
int main()
{
	A a1(1);
	return 0;	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the code you posted should not even compile because class A is missing the overloaded = operator. in main(), the line "a = 1" does NOT call the default constructor as you might think, but will call the = operator. And since you did not define one the compiler should have complained (screamed loudly) to you.

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

google for ODBC -- there's lots of information about it, and some c++ classes too. You could also use ADO or DAO, but I don't know much about them. ODBC is the oldest of the three and is supported by nearly all commercial database engines.

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

if you have 3 employees, then you need to allocate 3 Employee objects, not one as you did in main(). One Employee object only holds the information for one employee.
The display function should like like this. Also remove that loop from the Set() function too.

void Employee::display()
{
cout<<"employee name is:"<<name<<endl;
cout<<"employee number is:"<<number<<endl;
cout<<"employee salary is:"<<salary<<endl;
}

and main like this

void main()
{
	Employee a[3];	
        for(int i = 0; i < 3;i++)
        {

   	   a[i]. set();
	   a[i]. display();
	}
}

or if you only want one Employe object when you only want to work with one employee at a time.

void main()
{
        for(int i = 0; i < 3;i++)
        {
	   Employee a;	
   	   a. set();
	   a. display();
	}
}

final suggestion: Since this is a c++ program, not C program, use c++ std::string class if your instructor will allow it.

std::string	number, name, salary;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hi plzzz i need ahelp to know what rong with this program
the problem is in the display function
the code

what do you think is wrong with it? Do you get compiler errors? If yes, what errors? Or are there runtime errors -- what are they.

Function display() is attempting to treat each of the class objects m(name, number and salary) as if they were three of each -- there is only one of each. remove the loop and the index into each array

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

Dear Everybody
I have got some reply thanks alottttttttttttttttttt
but I am not satisfy completely

if you don't mind please consider my topic
I have sent you three numbers now I want to know what fourth number after third

thanks

what does this have to do with C or C++ programming???? :eek: This looks and sounds like some sort of IQ test. :mrgreen:

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

thnks jenny for your questions, and for those who posted the solution, thank you very much, u help me a lot :))

you forgot to use the [sarcastic] and [/sarcastic] tags :cheesy:

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

2. using std::cout;
using std::cerr;
// and any others that the header file uses

the above...using std::cout and using std::cerr and std::cerr<<"Error Queue is full\n" there was not function....
i didnt put as u told also no error..
wat is it use?? when will is Error Queue is full will display...
help..again...

you don't need both "using namespace std:" and "using std::cout" at the same time. one one or the other. Both are ok, but not really needed. A lot of programmers don't like to use "using namespace std;" so they use the other forms illustrated.

3. about const int MAX=50; // initialize max string size of 50 characters i put in main.cpp only...can??? is before #include 'Stack.h'
and #include 'Queue.h' rite??

I think it would be better to put that declaration in the *.h that uses it. Current c++ standards allow const like that inside the class itself, but not all compilers support it.

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

also, the numbers are all too big for any 32-bit compiler.

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

I'm trying to pass arguments to my program so that I can store them into an array. For some reason my IDE/compiler is treating the blank space in between arguments as an argument.

There is nothing wrong with your compiler or IDE -- that is the customary way C program startup code uses to parse and build argv strings. If you have a parameter that y0u want to include spaces, then you have to surround it with double quotes

c:> myprogram "This is one parameter" <Enter>

in the above, argc will be 2, argv[0] == the name of the program and argv[1] == "This is one parameter". Without the quotes, argc == 5 and there will be 6 strings in argv.

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

This is a c++ program -- why are you wrinting your own linked lists instead of using STL <list> classes?

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

you must close the file before it can be deleted. use fin.close() before attempting to delete it.

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

you need to post your program. use getline() to get a string that includes spaces.

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

Here is one way to do it. There are probably several other ways too.

std::string n = "1233321";
char s = '3';
int count = 0;
for(int i = 0; i < n.length(); i++)
  if(n[i] == s)
    count++;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The easiest way is to input both as strings, not integers, then simply iterator through the string. Attempting to use integers makes that a lot more difficult.

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

The only reason I know for returning the reference is when overloading operator[] so that it can be changed by the calling function. I suppose if the object being returned is large enough one could return a reference (or pointer) instead of a copy just to save processing time. In your example, the first version is the best.

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

The problem is that the header file doesn't know about namespace std. You can solve this in one of at least three ways:
1. move the line "using names std" before the line "incude queue.h" in the main *.cpp file

2. at the top of queue.h declare classes cout and cerr

using std::cout;
using std::cerr;
// and any others that the header file uses

3. in the queue.h header file expeclitly specify the namespace

std::cerr<<"Error Queue is full\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just need atleast a hint?

start here

#include <iostring>
using std::cout;

int main()
{
    cout << "What type of math problem will you be doing?: ";
   // put your code here


  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is the errors my compiler (MV C++ 6.0) gives me:

month class is missing a close bracket } in the constructor that takes an integer. That is causing all the other errors.

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

Hi,
If I do it this way, then there is no need for the MyString class, right? I'm supposed to make name an MyString object.

Then nix my suggestion.

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

you didn't say what the problem is. But I see a few problems in the Month class. Whenever the month number changes the month name must also change, and whenever the month name changes the month number must also change. I suggest moving those two large switch statements in the two class constructors into the setmonthName() and setmonthNumber() functions, then call these functions from the constructors and each of the overloaded operators. This will keep the month number and month name class objects synchronized.

An alternate solution would be to not keep the month name anyplace in the class. Only set the month number. When the name is needed, it can easily be obtained from the month number. That way no synchronization is necessary. Change the function setMonthName() to set the month number based on the string passed into the function. There is no reason to keep a copy of that string. And change getMonthName() to return the month name string that is appropriate for the month number. An array of month names makes all that very simple and short -- no switch statement is needed. For example:

std::string months[] = { "January","February" ...}
// assume n >= 1 and n <= 12
string getMonthName(int n) {return months[n-1];}