tux4life 2,072 Postaholic

When a class has one or more pure virtual methods, the class is called an abstract class, but you cannot just create an object from it, you first have to derive a class from your abstract class and then you've to override the pure virtual methods before you can use it :)

A "normal" virtual method has to do with early and late binding (runtime polymorphism)

tux4life 2,072 Postaholic

I dont want the constructor to do anything except create a FlightManager so I can use its methods.

Just don't define the constructor explicitly (in that case the compiler will use the class' standard constructor to create an instance of the object) :)

Edit:: this means that you just have to strip the line FlightManager(); out of your code ...

tux4life 2,072 Postaholic
int **p = new int*[M];

for ( int i = 0; i < M; i++ )
  p[i] = new int[N];

// And to release the memory:
for ( int i = 0; i < M; i++ )
  delete[] p[i];

delete[] p;

Why not just int *p = new int[M]; ?
Is that because you want to have the opportunity to delete an element from the array?

tux4life 2,072 Postaholic

What you mean is dynamic memory allocation, check out this first and feel free to ask questions if you don't understand something :)

tux4life 2,072 Postaholic

Why didn't you put the end braces?

int _tmain(int argc, _TCHAR* argv[])
{

	cout << "Welcome to Airline Manager v1.0" << endl << endl;

	FlightManager fMan;
[B]}[/B]
class FlightManager
{
	public :
		FlightManager();
[B]}[/B]
tux4life 2,072 Postaholic

Is there a way for the user to say, I want to go to restaurant queue 3?

Yes, create an array of restaurants and access each 'restaurant' via it's subscript :)

tux4life 2,072 Postaholic

So you have to estimate/calculate pi am I right?
Could you please post the whole algorithm (+an example of the series)

tux4life 2,072 Postaholic

Sure that you don't have to put quotes around the number?

tux4life 2,072 Postaholic

Can you post your code please?

tux4life 2,072 Postaholic

Did you try the online manual available on it's site?

tux4life 2,072 Postaholic

->First: Please post using code tags!
->Second: You have to know how to write manipulators :)

tux4life 2,072 Postaholic
[B]ifstream[/B] file;
file.open( file_name.c_str(), ios::[B]out[/B][B],[/B] ios::binary );

shouldn't that be:

[B]ifstream[/B] file;
file.open( file_name.c_str(), ios::[B]in[/B] [B]|[/B] ios::binary );
tux4life 2,072 Postaholic

>I've changed your function to use pointer arithmetic...
1. *(array+index) - it's exactly array[index] definition in C and C++
2. < *lowest - it's ineffective (slow indirection) variant of the original code with int lowest
3. void sort(int*, int) - it's absolutely the same function type as void sort(int[],int) ;)

I know but he wanted to rewrite his function using pointers, but I agree that using the [] braces is better :P

tux4life 2,072 Postaholic

Um, wow, it works. That's going to be a pain in the butt to have to do that for every project.

Unless you use an IDE :P

tux4life 2,072 Postaholic

If you want exact averages you should change (in your function average ) int total = 0; to double total = 0; :P

tux4life 2,072 Postaholic
  • Really?...I tried it and it does work, I didn't think of that...thanks...

    I tried it also and it did work, maybe you did something wrong? :P

  • Just as an exercise to see whether you understand pointer arithmetic or not:
    http://www.daniweb.com/code/snippet1177.html, convert and implement this in your code (using pointer arithmetic, it's not that hard:))
    (use it as a replacement of your current sort-algorithm)
  • It will work, 100% guaranteed :), I tested it but according to the forum rules I'm not allowed to just give the code away
tux4life 2,072 Postaholic

Take a look at your function getnumtestscores() :

int getnumtestscores()
{
    int num;

    cout << "\n How many test scores do you want to enter : ";
    for(;;) // loop forever  ... until return
    { 
        cin >> num;
     
        return num;
    }  
}

This red colored code can be replaced by

cin >> num;
return num;

It's doing exactly the same :) (why? when the return statement executes, the whole function execution ends)

tux4life 2,072 Postaholic

This was really good, the only problem with it is, when it sorted the numbers, the numbers were all the same as the first one entered.

Yup, that's right, I tested it, now it compiles fine we'll have to take a close look at how the algorithm works as it's not working like it should ...

tux4life 2,072 Postaholic

With me it did compile, I tested it on two different compilers (Borland and MinGW)
But there's still an error in your sorting algorithm :(

Edit:: Oh I'm sorry I thought you were talking about my reply (I didn't read your post carefully enough)

tux4life 2,072 Postaholic

I've changed your function to use pointer arithmetic (the changed parts are in green-colored bold):

void sort(int [B]*array[/B], int numts)
{
	int lowIndex, *lowest;

	for (int count = 0; count < (numts-1); count++)
	{
		lowIndex = count;
		lowest = [B]array+count[/B];
		
		for (int index = count + 1; index < numts; index++)
		{
			if ([B]*(array+index)[/B] < *lowest)
			{
				lowest = [B]array+index[/B];
				lowIndex = index;
			}
		}
		[B]*(array+lowIndex)[/B] = [B]*(array+count)[/B];
		[B]*(array+count)[/B] = *lowest;
	}

	return; [I]// this return is not required, but it may be here[/I]
}

New function declaration: void sort([B]int *[/B], int); It should work now :) !!

tux4life 2,072 Postaholic

Why did you rewrite your whole code using pointers?
Edit:: Now you've already experienced that pointers can make a mess of your program :P ...
Edit:: My suggestion is: try to avoid pointers as much as possible ...

tux4life 2,072 Postaholic

What do you mean with it doesn't work?

  • Is it compiling or not?
  • Or are you getting unexpected output?
tux4life 2,072 Postaholic

What happens if you try to link all those libraries?

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

Thanks tux, do you have any examples of pointers being used in functions? My pointers are screwing up my program...

You actually don't need to use pointers for that purpose, just pass the array as an argument to the function (it's just as efficient as using pointers, because an array's name is treated as a constant pointer (a pointer which memory address is constant, which means it cannot be changed) to the first element of the array, you can use the index operator to get an element from the array)

:)

Edit:: Actually I try to avoid pointers as much as possible, only when there's no other way left I will use it ...
Edit:: BTW, the bubble sort example where I've posted the link in my previous post did use a pointer...

tux4life 2,072 Postaholic

Want an example of a bubble sort? Check out this :)

tux4life 2,072 Postaholic

...and was wondering if this would work.

Just compile and run it, and if there are problems: post them (and in case of an unexpected result please tell also what output you did expect) :)

tux4life 2,072 Postaholic

It was actually good old Salem who brought me on the idea :P

tux4life 2,072 Postaholic

Change

while (!(1<=option && option<=2));
	  [B]}[/B]

to

[B]}[/B]
while (!(1<=option && option<=2));

nt option; has to be int option; :)

the following:

....
        cin>>option;
	cin.get();
	do { 
....

should be changed to:

....
	do { 
....

and...

.....
default: cout<<endl<<"Wrong option number!! Try again\n";
	                  cin.get(); //give the user a chance to read the output data
	          }
.....

has to be:

.....
default: cout<<endl<<"Wrong option number!! Try again\n";
	          }
.....

:P

tux4life 2,072 Postaholic

yes i was trying your codes but ist giving error
looks fine to me but giging this error.

Then you must have done something wrong, I tested it and it was working perfectly :)

Could you please post the whole code which was causing this error?

tux4life 2,072 Postaholic

Did you even read my previous post ?

tux4life 2,072 Postaholic

What about the following:

do {
    cin>>option;
    switch ( option ) 
    {
	case 1:
            displayCerteinDate();
	    break;
	case 2:
            displayAll();
	    break;
	default:
            cout<<endl<<"Wrong option number!! Try again\n";
    }
} while (!(1<= option && option<=2));
tux4life 2,072 Postaholic

Could you please post your code (using code tags!!) and paste the exact error message(s) you're getting?

tux4life 2,072 Postaholic

Dear WaltP, actually siddhant3s is right, take a look at the following link:

:)

tux4life 2,072 Postaholic

i guess u didnt understand my code..... why dont you execute this code and see how exactly it works.......
and variable can also be put inside instead of boolean, any way 1= TRUE and and 0 or lesser implies false.......

I know, you don't have to teach me C++, but a boolean takes up less memory :)

tux4life 2,072 Postaholic

flag is a variable name .. u can also write ur name instead of that.. its just that i am a bit convenient with that name that's its.....

I know flag is a variable name, but two things, if you would have to use a flag in this case you should have used a boolean instead of an integer and here it's just overkill, why would you use an integer flag here?

tux4life 2,072 Postaholic

actually u can use a flag......(its just a variable but commonly know as flag when used in such purposes )

Why the h*ll would you use an integer flag? Isn't boolean good enough here ?

tux4life 2,072 Postaholic
while ( cin>>option ) {
    switch ( option )
    {
    }
}

You have to take into account that the loop won't end automatically except if the user enters some text ...

tux4life 2,072 Postaholic

Put

cout<<endl<<"Wrong option number!! Try again\n";
cin.get(); //give the user a chance to read the output data

in a do-while -loop and change cin.get(); to cin>>option; like this:

do {
    cout<<endl<<"Wrong option number!! Try again\n";
    cin>>option;
} while(option<1 || option>2);
tux4life 2,072 Postaholic

well i think this should solve your problem.... very well

http://www.cplusplus.com/reference/string/string/find/
:)

That's actually what I'd already posted :P

tux4life 2,072 Postaholic

Check out this :)

tux4life 2,072 Postaholic

Again this is because I don't know which linker libraries to add

Well, you compiled allegro right? Just check out the directory of the library files (lib) and you'll see :)

tux4life 2,072 Postaholic

while (count=0); has to be while (count==0); If you write while (count=0); then variable count gets assigned value 0, so this means the assignment will return zero which is equal to false with the result the while loop won't run :) ...

tux4life 2,072 Postaholic

Check out this :)

tux4life 2,072 Postaholic

plz help

Don't be impatient, if you want fast help you should give a detailed and understandable description of what your problem is first :)

tux4life 2,072 Postaholic

You could change your get_char function to: char get_char(int n) {return n-'0';} (edit:: unless your goal is to also provide conversions from other bases)

In your rev-function (see line 72) a for-statement would be better to use I think, it will also compact your code a bit :)
(You can use a for like this: for(; q>r; q--, r++) )

tux4life 2,072 Postaholic

Avoid the use of system("pause"); (reason)
Use cin.get(); instead :) ...

tux4life 2,072 Postaholic

>Plus, I still don't know how to load from a text file in SDL
You don't have to use SDL to load the text file, just use the standard C++ file handling routines for this, read a line from the file, put it in a variable and use an SDL function to display it on the screen, is that difficult? NO :) ...

tux4life 2,072 Postaholic

Dear NathanOliver, your code is working perfectly after changing cout << you did not enter an integer."; to cout << [B][I]"[/I][/B]you did not enter an integer."; :)

Edit:: Some additional information on if (test != input) as 'input' is a double and 'test' is an integer, 'test' will be implicitly converted to a double to do comparison :)

tux4life 2,072 Postaholic

isxdigit and isdigit should be preferred. There's no isodigit, so your suggestions aren't completely pointless. :icon_rolleyes:

Thanks for mentioning, I didn't know that :)