Duoas 1,025 Postaholic Featured Poster

Don't use

  • getch()
  • system("PAUSE")

Both are non-portable.

Instead, do it the C++ way:

#include <iostream>
#include <limits>

void pause() {
  std::cout << "Press ENTER to continue... ";
  std::cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
  }

Now if you want to pause, just use the function:

int main() {
  using namespace std;
  string name, color;

  cout << "WHAT, is your NAME!?\n";
  getline( cin, name );

  cout << "WHAT, is your favorite COLOR!?\n";
  getline( cin, color );

  cout << "Aaaiiiiiieeeee!\n";

  pause();
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Actually, I missed that one. Its a nice link. Unfortunately, it doesn't help...

I've got a functional keymap, and it is in the correct place, but Kubuntu doesn't seem to pay it any attention on boot.

I could just stick a loadkeys command in one of the startup scripts, but the problems with that are two-fold: the next update could clobber any changes I make; and loadkeys needs to be called pretty early in the boot process, but not too early. These two problems are at odds with any simple change I could make...

So I was just wondering if anyone knew the "Debian/Kubuntu approved way" of telling the init process how to use the keymap.

Alas.

Duoas 1,025 Postaholic Featured Poster

Hi all. I know this is an odd question, but I'm hoping someone else out there knows how to do this.

I've just installed Kubuntu 7.10 (which I like), but Debian seems to have messed around with the startup a bit...

I've replaced my /etc/console-setup/boottime.kmap.gz file with one that changes my Caps_Lock into a Control key and the "Windows" Super_L into Caps_Lock (yeah, I do use caps now and again).

I've tested my new mapping with sudo loadkeys, and it works fine, but Kubuntu doesn't seem to find it when booting up!!??

I know I can do this with X. The point is that I don't want to. I want my keyboard modifications whether or not X is running.

I've been googling for a couple days now without useful advice. I'm not a unix guru, but I'm not exactly a neophyte either. Is there anyone out there that knows how to make Kubuntu behave?

Duoas 1,025 Postaholic Featured Poster

The problem is that a1, b1, time, and amount are all defined as double, and your routine wants a pointer to double.

Call as:

Runthrough(&a1,&b1,&time,&amount);

Since this is C++, you could prototype your function as

void Runthrough(double &from, double &to, double &when, double &howmuch)
{
   ...
}

then you could call the function the way you were.

In either case, one line or the other must have &'s.

Please use code tags.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Read me.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Two system() calls, two shells executed.

If you want to run more than one command then use system() to execute a shell script. I know nothing about the Symbian OS, but I do believe that there should be some sort of command shell on it?

Duoas 1,025 Postaholic Featured Poster

I disagree.

I'm not alone. You may also want to read here.

You shouldn't program to avoid learning things. The purpose of namespaces is to encapsulate your code into logical units and avoid name collisions. The using statement explicitly defeats that purpose.

So, the question should be: when is it appropriate to use using?

The answer is simple: don't contaminate other modules' code with foreign namespace data. For example, a using statement should not appear in any header file, because any program that #includes it is automatically contaminated with a (probably unwanted) namespace.

A good rule of thumb, then, is when writing library code either don't use using or only use it in local blocks; and when writing your main application (the file that has the main() function in it) feel free to use it, but beware.

For more, see this thread wherein Ancient Dragon and Narue make very good points on the use of namespaces.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Same here, using GCC and XP.

Duoas 1,025 Postaholic Featured Poster

Essentially, yes. Except a pointer goes one step further than a magic number: it is the index of an actual memory location.

Duoas 1,025 Postaholic Featured Poster

Ah, OK. So to write to the file you'll need to open it, much like I did above, but using the rewrite procedure, and write a TPrices record to the file of TPrices. Once done, close the file. The format of your FormDestroy procedure should look a lot like the FormCreate procedure.

I assumed that PricePerLitre was a global or a class variable because of the way you used it in the code you posted.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Question: What is the type of TPrices? Is it a record?

You'll have to read up on file handling in Delphi. Here's a very good article I googled.

Good luck.

Duoas 1,025 Postaholic Featured Poster

That means that your program couldn't find the file. Try running the program from the DOS command prompt.

Duoas 1,025 Postaholic Featured Poster

Your prices file needs to be the right type.

procedure TfrmCashier.FormCreate(Sender: TObject);
  var
    NewPriceRec : TPrices;
    Pricesfile : file of TPrices;  // 1
  begin
    assignfile(Pricesfile,'Staff.dat');
    try
      PricePerLitre := 5.999;  // 2
      reset(Pricesfile);  //3
      try
        read( Pricesfile, NewPriceRec );
        PricePerLitre := NewPriceRec.PricePerLitre
      finally
        closefile(Pricesfile)
        end
    except end
  end;

1. The prices file is a file of TPrices records.
2. The default price per litre. (5.999. I don't know what type of thing PricePerLitre, which I assume is a class variable, is, so I assume it is a double.)
3. To read the file, use reset. To overwrite the file, use rewrite.

The try blocks are there to make sure things work smoothly. You might want to add something in the except block (for example, ask the user what the default price per litre is).

The FormDestroy should look similar, except you should write the file instead of read it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Everytime an application is terminated, all the variable's values are lost.

You can "remember" things between invocations a number of different ways. On Windows, the two most common ways are:

  1. By using the registry
  2. By using a file

Number 2 would be simpler for you right now (but if you want to do #1 I can give you a useful example, just ask). To do #2, just take the following steps:

  1. In the FormCreate procedure, try to open the file. If you can, try to read the saved price per litre. If you can't do either, just set the price per litre to some default or ask the user for an initial value.
  2. In the FormDestroy procedure, rewrite the file. Write the current price per liter to the file.

Some variation of that should work for you.

Duoas 1,025 Postaholic Featured Poster

If it is possible to read anything from the file, eof will not return true.
Therefore, while not eof, you can read and print a line of text.

Your previous code would read the last line of text, but not print it if eof was true. Hence, the last line of text was lost (read but not printed).


Wait, was that what your "how?" was for?

Duoas 1,025 Postaholic Featured Poster

I just tested it with gpc also.

There is a logic error, btw. You should have:

i := 1;
while not eof( t ) do
  begin
  readln( t, s );
  writeln( 'line ', i, ': ', s );
  inc( i )
  end;

so as not to lose the last line of the file. (Unlike C and C++, Pascal is forward-capable when finding EOF.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I compiled and executed your program with FreePascal 2.2, Delphi 5, and Turbo Pascal 4 and it works just fine for me.

The file "untitled.txt" should be in the same directory as the exe.

It is possible that the IDE is running your program in the wrong directory. Try executing it from the command line.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Actually, you can't get around having a list of the words to find. Both an array of string and a linked list of strings are just as efficient.

Unless you have to find more than 100 words or so on a large text, there is no point in trying to make a more efficient (and much more complicated) algorithm.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Post your code and I'll take a look at it.

Duoas 1,025 Postaholic Featured Poster

I think your professor is an idiot and a jerk.

Tell him that an IDE is an "Integrated Development Environment", meaning that it is at least a compiler and a nice text editor.

Tell him also that if he has further problems with your choice of a compiler he can

  1. Tell the class explicitly which compilers (other than VisualStudio's, of course) are acceptable
  2. Take it up with the Ombudsman or Dean for Student Affairs (in which case he will also need to explain why VisualStudio's compiler is unacceptable and why your homework failed to meet the assignment's criteria.)

There is absolutely no excuse for a professor to loose his cool with a student.

Duoas 1,025 Postaholic Featured Poster

There is no such thing as simple networking in C++.

You are better off reading the game's documentation (there are command-line options to connect to a specific IP and port).

Once you know how to connect exactly like you want by typing from the command-line (or in the Start->Run box), then make a plain text file with those commands. For example, if you type iw3mp.exe +set net_ip 62.211.12.142 +set net_port 27015 then create a file named something like Call of Duty 4.bat

@echo off
:: Start call of duty 4
iw3mp.exe +set net_ip 62.211.12.142 +set net_port 27015

Now, to start the game, just run the batch file.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Heh heh heh... :)

Usually I'm the one who's too slow... :sweat:

Duoas 1,025 Postaholic Featured Poster

Unfortunately, Windows Vista no longer supports the old 16-bit DOS subsystem.

But, you aren't totally dead in the water. Take a look at DOSBox, which is a very nice x86 emulator for 16-bit applications. (It was specifically designed for gaming, but it will work for your program also.)

The only other recourse is to use virtual machine software and install a copy of DOS on a VM.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can fix the second one by using getline( myfile, msg ); Enjoy!

Duoas 1,025 Postaholic Featured Poster

You'll need to track mouse down and mouse up events, then use the Pythagorean theorem.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Then you can't go through the print spooler at all. You'll need to google "delphi pdf component" or something to find what you need.

I don't know whether or not there is anything free out there, but I do know there are some nice components you can pay for...

Good luck.

Duoas 1,025 Postaholic Featured Poster

istream.ignore()

The first does what you want, accepting whatever the user types until he (hopefully) presses ENTER (or the input ends, whichever comes first).

The second just waits for a single character, which may or may not be the newline.\

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Just use a std::string:

#include <iostream>
#include <fstream>
#include <string>

int main() {
  using namespace std;

  ofstream writer;
  string filename;

  cout << "Enter a file name please> ";
  getline( cin, filename );

  writer.open( filename.c_str() );
  if (!writer) {
    cout << "Could not open " << filename << endl;
    ...
    }

  ...
  }
Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

At the top of the forum there's an announcement post named "Please use BB Code and Inlinecode tags". It makes reading and copying code both easy and pleasant.

So, did you get your program to work?

Duoas 1,025 Postaholic Featured Poster

The problem is that type int does not have members named HeightinFeet and HeightinInches.

Starting at line 108:

int temp;
  temp.HeightinInches = ...

An int is not a Height.

Chandra.rajat hit it right on: your operators are supposed to work on your class. So, the + operator should have the following prototype: Height Height::operator + ( Height &h ) Remember, you are supposed to be adding Heights.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Did you read the OP's post?

Your code works fine for me.

Perhaps you think you are a lot brighter than I, who took the time to actually compile and execute his code, after reading it over and finding no obvious flaw?

I'm sorry to be harsh...

Duoas 1,025 Postaholic Featured Poster

You need to watch your brace style. (The while end-brace should be at the same indent as the while keyword, based on your other braced blocks.)

The loop never ends because you forgot to cin >> x; at the end of your loop also.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Hold on. You'll need to make sure you have the right to distribute that program with your application.

I'm pretty sure there are some Delphi PDF components out there. In addition to fayyaz's link, there's also Primo PDF, which is pretty nice.

In all cases, however, I think you need to pay some money to get distribution rights...

Duoas 1,025 Postaholic Featured Poster

Please use code tags.

Your code works fine for me. What's giving you trouble?

Duoas 1,025 Postaholic Featured Poster

That link deals entirely with your exact problem and why it occurs, and tells you how to fix or avoid it. Please read it through carefully, again. this->imgp = cvLoadImage( filename ); cvSaveImage( filename, this->imgp ); Good luck.

Duoas 1,025 Postaholic Featured Poster

In C and C++ the only time it makes a difference is with the increment and decrement operators, which each come in two forms: postfix and prefix.

Here we have an integer: int a = 42; Let's play with it: cout << a << endl; prints 42 cout << ++a + 1 << endl; prints 44 cout << a << endl; prints 43
In this example, a was incremented before the expression was evaluated. (The entire cout statement.) This is prefix: the increment is done first. cout << a << endl; prints 43 cout << a++ + 1 << endl; prints 44 cout << a << endl; prints 44
In this example, a was incremented after the expression was evaluated. This is postfix: the increment is done last.

There is a caveat. For each distinct variable, you cannot use more than one increment or decrement operator in the same statement. Hence: cout << ++a++ << ++a << endl; BAD!
is likely to get you a random number.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You don't understand. CUI mode excludes fancy graphics. You can't display an image in CUI mode. You need to change to a graphics mode to display the image.

Duoas 1,025 Postaholic Featured Poster

Ah, Vista must have moved the file. Just change the file path in the RC file to point to whatever WAV file you want to play.

Duoas 1,025 Postaholic Featured Poster

Yeah, sorry about that. You don't need to worry about window procedures.

By volatile is meant that it can be destroyed at any time. Since you can't have a window proc, you can't be informed at all the times it needs to be re-drawn. So, while you are technically able to draw in the console window, it doesn't make much sense to do so, since you can't guarantee that the image won't be destroyed before you would like it to.

Since you are using TC, stick with the VGA graphics stuff. I would stick to using a simple, easy-to-read file format like BMP or TGA.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Ah, ye old double-post button. Since I'm not allowed to edit anything I post after a couple minutes I'll just add a new post:

You'll have to go ask your professor how he expects you to remember whether a number was inputed previously or not. There is no simple, straightforward way to do it without at least an array or a linked list.

Let me know what you want to do.

Duoas 1,025 Postaholic Featured Poster

I haven't looked through the QStat sources (and I don't plan to), but if it really is just a plain-vanilla command-line application then you only need to spawn it as a subprocess, and re-route its standard input and output to your application.

Look through the docs for CreateProcess.

Hope this helps.

jonc commented: Thanks for your advice and URL for more info. Much appreciated :) +1
Duoas 1,025 Postaholic Featured Poster

I must be stupid.

Duoas 1,025 Postaholic Featured Poster

Yes, I understand that.

What you did is assign all the variables to have the same value as g, because you used = instead of == .

Is this schoolwork? If so, have you learned about STL vectors, or arrays? You will need one of them to keep track of which numbers have been entered already.

Duoas 1,025 Postaholic Featured Poster

Are you allowed to use a vector? Or just an array?

Whenever you find yourself doing the same thing over and over and over, it is time to use a loop.

1. declare my vector or array or whatever
2. while not done
2.1. get a number from the user
2.2. if the number is not in the vector/array/whatever:
2.2.1. then add the number to the vector/array/...
2.2.2. else complain

Your posted if statement uses assignment operators, so it is the same as saying:

f=g;
e=f;
d=e;
c=d;
b=c;
a=b;
if (a) cout << "a is not zero.";
else cout << "a is zero.";

Make sure you use the == operator to test two values for equality:

int x, y;
x = 12;
y = 94;
if (x == y) cout << "impossible!";
else cout << "yeah!";

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yeah, I'd love to be able to also (I want to catch window resize events [as opposed to buffer resize events]).

Unfortunately, windows doesn't think your console applications have any business using a window proc...

Alas.

Duoas 1,025 Postaholic Featured Poster

The line cube[5]; is just a number. However, since the array has only five elements and you are trying to access the sixth, you'll get a bounds error (or worse).

Use a for loop to set each element of the array to zero.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

> On the plus side, being DOS, you can generate simple low-resolution graphics (which a true Win32 console cannot).

Actually, if you get the DC of the console window, you can draw on it like any other. Unfortunately, it is impossible to use a window proc on the console window... so the graphic must be considered volatile...

Duoas 1,025 Postaholic Featured Poster

Please use [[I][/I]co[I][/I]de[I][/I]] tags.

average
Your average template function itself is fine, but you did not overload it. You need to write another average function that takes only two arguments.

You don't typically need to specify the type when you call a templated function, unless you have to. For example: cout << average( 12, 14, 15 ) << endl; produces 13, since the arguments are taken as ints. You can force double by cout << average<double>( 12, 14, 15 ) << endl; and get 13.6667.

college course
Looks pretty good. One error and some suggestions:

  1. Your << operator writes to cout instead of out.
  2. Your + operator doesn't add l and r's honor points. You should do that, then set the new hnrPoints object's honor points to the sum before returning it.
  3. Your / operator should have the prototype: friend double operator / ( collegeCourse &cc, int divisor );

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Alright, I tried it myself. You are using the GCC? (I get the same error message.)

res.rc

one WAVE "c:\\WINDOWS\\Media\\notify.wav"

wave.cc

#include <iostream>
#include <limits>
#include <string>
#include <windows.h>

void play_wave_resource( std::string resname, bool is_loop ) {
  HANDLE hfound, hsound;
  LPVOID data;

  hfound = FindResource( NULL, resname.c_str(), "WAVE" );
  if (hfound != 0) {

    hsound = LoadResource( NULL, (HRSRC)hfound );
    if (hsound != 0) {
      data = LockResource( hsound );

      if (data != NULL) sndPlaySound(
        (char *)data,
        SND_ASYNC | SND_MEMORY | (is_loop ? SND_LOOP : 0)
        );

      UnlockResource( hsound );
      }

    }
  FreeResource( hfound );
  }

void stop_wave_sound() {
  sndPlaySound( NULL, 0 );
  }

int main() {
  using namespace std;

  play_wave_resource( "one", true );

  cout << "Press ENTER";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

  stop_wave_sound();

  return EXIT_SUCCESS;
  }

To compile at DOS prompt with GCC

D:\prog\foo\wave> windres -o res.o res.rc

D:\prog\foo\wave> g++ -o wave wave.cc res.o -lwinmm

D:\prog\foo\wave> dir/b
res.o
res.rc
wave.cc
wave.exe

D:\prog\foo\wave> wave

Press enter before you've heard enough "notify" to go insane.

Let me know if you get anything different.