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

>>for(numStudents; numStudents > 0; numStudents -= 1)

Or just simple this: for( ; numStudents > 0; numStudents -= 1) >>So basically whether you are declaring a variable or not, you must always have the semicolon? then the condition and then the counter(s) ?

Yes, there must always be two semicolons. As a minimum like this: for( ;; ) which is the same as this: while(true)

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

One problem is that you are using the same variables to read from two different files.

for(int count = 0; count < Size && capeFile >> F.date; count++)
{
    //B1[count].setFlightDetail(F);
      capeFile >> F.FlightNum >> < all the rest here> ;
      cout << F.date << "   " << F.FlightNum << "\n";

    if(date == F.date && flight == F.FlightNum)
    {
	//Accept the passenger detail
    }
    else 
    {
	cout << "No match found" << endl;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The if statement is not working at all and when outside the loop it only reads the last date and flight number from the file

No it hasn't -- the loop reads every line in the file. The if statement after the loop sees only the last line in the file, or the last variables that were read. All other data in the file are just tossed into the bit bucket because there is nothing in the loop to capture them.

ok now how do I take my if statement inside the loop without having to ask the user to enter their details until eof for 30 times if the size of the file is 30

The if statement on line 36 has nothing at all to do with asking anybody anything.

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

Don't know -- what error message(s) did you get ?

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

The program has to read all the fields, not just two of them, inside the loop.

for(int count = 0; count < Size && capeFile >> F.date; count++)
{
          capeFile >> F.FlightNum >> DepartAt >> ArriveAt
              >> AirGraft >> Price >> Seats;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The for statement is actually explained on page 97. paragraph 6.5.3.3 shows the correct syntax. Without doing any research I'll bet there has been a later correction to 6.5.3.1 and what was shown at the botton of page 95.

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

Either learn to use your compiler's debugger so that you can see the values of the variables as the lines are executed, or add more print statements. For example move line 21 up inside the loop.

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

The code you posted doesn't make a lick of since when compared to what you said in your original post. The code you posted is reading date and FlightNumber, not date name and Surname (three fields)

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

sorry about that -- I edited my post.

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

If the file is in the format 13-02-2004 Ellethy Pytro then your program is reading it incorrectly. It is only reading two fields, not three.

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

its hard to say without seeing the code. I don't have a crystle ball, I'm not a psychic, and I don't have xray eyes.

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

>>What usually be the cuase of the file reading the wrong data
A bug in your program.

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

The best way to prevent that problem is by using code guards in header files. Most header files suppied by compilers include them

// *.h

#ifndef _MYHEADER_H
#define _MYHEADER_H

// headef file stuff goes here

#endif // end of coode guard

The above only prevents header files being included in the same *.c file more than once. If you include your header file in two or more *.c files then attempt to link them you will get duplicate function declarations because of the reason I stated previously.

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

In MS-Windows you will probably want to have two threads -- one thread for dialing and the other thread to do other things. The Sleep(int milliseconds) is available from windows.h

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

comply: there were a few translation problems but I managed to fix them so that I could show you what you need to do.

First, I added a comparison method in that structor that returns an integer similar to strcmp() or std::string's compare()

struct student
{
    string name;
    char code;
    int operator==(struct student& st)
    {
        int ret = name.compare(st.name);
        if(ret == 0)
        {
            ret = code - st.code;
        }
        return ret;

    }
};

Here is a partially rewritten find function. You still have to finish it to update the new value of M if the structure comparison is not 0.

void find_element(int &N,struct student vector[])
{
    int Left=0,Right=N-1,M,i,NC=0;
    string element;
    char code;
    bool found=false;

    cout<<"What's the name of the element ?"<<endl;
    cin>>element;
    cout<<"What's the code of the element"<<endl;
    cin>>code;
   //binary search
    struct student st;
    st.name = element;
    st.code = code;
    while((Left<=Right)&&(found==false))
    {
        M=((Left+Right)/2);
        int cmp = (vector[M] == st);
        if(cmp == 0)
        {
            cout<<"element  found"<<endl;
            cout<<"The index is "<<M<<endl;
            found=true;
        }
        // Add code here to compute new value of Left or Right.
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I was a kid growing up in central Iowa we called it pop. Where I now live we call it soda. I never did use coke as a generic term for that substance.

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

Now that you have posted your homework assignments, what are you asking from us ?

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

lets say you have an array of structures

struct Students
{
    std::string name;
    int studenID;
};

Students stdarray[500];

Now you want to find the row for "Smith" code 123; Here is how the comparison function should work

int compare(Student* s1, Student* s2)
{
     int rtn = s1->name.compare(s2->name);
     if(rtn == 0)
     {
            rtn = s1->code - s2->code;
     }
     return rtn;
}

}

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

You don't put the function implementation code in *.h files then include the header file in two or more *.c files, or include it more than once in the same *.c file. That is what is causing the duplicate declaration errors. Put only the function prototypes in the header files and the implementation code in one *.c file, then link all object files that your compiler produced from the *.c files together to create the executable program.

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

Instead of me guessing, what is it that you are trying to search? An array of structures or classes, a linked list, or what ?

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

The comparisons are not limited to just one field within a class or structure, you can compare as many class objects such as strings that you want to. In the comparison, if the two names being compared are the same then compare the code.

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

Reputation, good and bad, means zero here in the Coffee House.

Dave Sinkula commented: Good point. :p +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

stargs.h contains the functions. Example here.

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

I have no idea what you mean by LOCATOR, but a linker is a program that creates an executable file from the object files and libraries.

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

Why do you need more than 30 minutes to edit your post? It seems to me that 5 minutes should be pleanty of time to correct typing or other errors. But I suppose more than 5 minutes might be needed by people who hunt-and-peck at the keyboard.

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

The code you oposted has a huge memory leak. Line 24 allocates some memory then line 25 tosses the pointer away and uses it for something else. One of those two lines needs to be deleted. My preference is to keep line 24 and delete line 25 so that the class has complete control over all its data.

Since MyClass does not own the memory for Other1 and Other2 (see lines 25 and 26) the MyClass destructor will most probably cause a core dump or some other nasy abnormal segmentation fault. You can not delete[] something you did not allocate with the new operator.

line 48: you compiler will give you an error on that line because you do not call destructors explicitly.

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

Here's why floating point is not very accurate. It talks about Python but applies to all other programming languages too that use Intel Floating Point. If you need more accuracy then use one of the several alternate math libraries.

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

There are some very very old shareware libraries that do text-based menuing stuff -- I recall using it 10-15 years ago. Ive tried to find it again on the net with no success, probably because it is so old.

You will not be able to create a dropdown menu like you see in Windows that that ancient compiler. Upgrade to modern compiler and learn to program the real way. Turbo C was nice in its day, but like me its day has come and gone. Get yourself one or more of the many free modern compilers if you want to do anything in MS-Windows or *nix.

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

From what I see on the net, an Excel Database is just another name for an ordinary Excel file and can be accessed as previously mentioned by Tesuji.

Otherwise, you can access any ODBC compliant data base through the ODBC driver functions. There are several tutorials and c++ classes.

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

add the structures in sorted order. When adding a new node search for the word that is less than the current word and insert the new node there. Very similar to finding the insert position of an array of integers. You don't need a sort algorithm to do this.

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

thanks... btw, i used to live like two hours away from st. louis, in lebanon, mo. ^^

Using google maps I see that is 192 miles west from where I live.

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

1) Study c++ classes. You can create a character class that contains all sorts of skills or data types.

2) Study c++ classes. You can create a calendar that contains whatever dates or data types you want. Also study fstream class to save and read back the data to/from data files.

I realize my answers above are very broad. At your level of understanding you need to get at least a basic understanding/knowledge of the c++ language before diving off the deep end with projects are are too difficult for you. Take your time, and you won't be disappointed.

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

>>or there are other ways todo this
Nope -- there is no magic way to do it. std::map is the ideal way, but you can't use it. If you put the nodes in sorted order then you could use some sort of binary search algorithm to locate the correct node if it exists. But that requires more slightly complex coding. Search google for binary search algorithms because they are fairly popular.

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

Oops! you are right :)

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

There are going to be many porting issues. Just take them one at a time. For example, iostream.h is depricated (obsolete). use <iostream> (without .h extension) instead.

>> skipped when looking for precompiled header use
The first line in *.cpp files with that compiler needs to be #include "stdafx.h" because that is for precompiled headers. Several compilers use precompiled headers, and Microsoft compilers typically using stdafx.h, although you can change the name of that file if you want to. You can also turn off precompiled headers.

>> fatal error C1083: Cannot open include file: 'intro_sht.cpp':
That error should be obvious to you. The error message of quite explicit.

>>At this point I think I need some location sources to read. Any recommendations?
I don't know what kind of documentation you are looking for. Instructions on how to use the compiler? Or what ?

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

>>So linkedlist is the way to go?
That's the way I'd do it. You don't have any idea how many items are in the file so an array is not a very good or efficient alternative. You could use a dymically allocated array but its not very efficient.

iamthwee commented: I would agree +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you talking about RSS feeds ?

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

MS-Windows: Sleep(milliseconds) -- *nix: usleep(milliseconds).

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

>>Im restricted from using STL btw.
That means you might as well be writing a C, not a C++ program because you can't use anything from fstream, iostream, string, vector, map, etc. etc.

With that restriction I would create a structure that contains an int for counter, another int for line number, and char* that contains the word. Each time the program reads a word it needs to find out if it is already in the linked list of those structures. If found, just bump the counter up by one. If not then add a new structure to the linked list.

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

Why don't you ask them ?

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

line 3 does not allocate any memory for that array and sprintf() doesn't allocate it either.

void cabext(const char *fname)
{
	char command[1024] = {0};
	sprintf(command,"cabextract -L -d /tmp/ %s",fname);
	system(command);
}
Salem commented: Yes indeed. +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You might try FlashWindow() or FlashWindowEx().

Great :) So it is just a simple function call afterall.

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

repost your program so we can see what you did.

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

am i going to change the code in 103

with the code you give????

You have to do something similar in all three cases -- lines 98, 103, and 108

>>it also has error.....
What error ?

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

The problem is the recursive call at line 103 (as posted above). Change that to a loop instead of doing recursion.

if (area==0)
{
    r = 0;
    while( r < 1 || r > 2)
    {
        cout<<"(First Class Passengers May Only Choose Row[1-2]):";
        cin>>r;
    }
}

And it would help if you would use a better coding style -- there is nothing wrong with being very liberal with spaces and lines because it make the code a lot easier to read and understand.

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

Now that I think about it, comparing the above values with compilers on different computers (such as yous and mine) will be of little to no value. But might help to demonstrate the differences among compilers on the same machine.

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

I don't have either of those compilers. Why don't you just write a simple little program that demonstrates the problem and that can be compiled by any compiler, then compare the output with the results on other compilers. This one for example: I'm using win32 api function QueryPerformanceCounter() below because the program runs too fast for clock() to produce any measurable results.

#include <fstream>
#include <iostream>
#include <windows.h>
using namespace std;

int n[100000];
int main()
{
    
for(int i=0; i<100000; i++) 
 n[i] = 1;

fstream out("test", ios::out | ios::binary);
if(!out) {
 cout << "Cannot open file.";
 exit(0);
}

LARGE_INTEGER t1, t2;
QueryPerformanceCounter(&t1);
cout << t1.QuadPart << " ";
 out.write((char *) &n, sizeof n);

QueryPerformanceCounter(&t2);
cout << t2.QuadPart << "\n";
cout << "milliseconds between = " << t2.QuadPart - t1.QuadPart << "\n";

out.close();
}

The output on my computer (Vista) using VC++ 2008 Express is. Note: The results are NOT in milliseconds, but just the difference in the high resulution performance counter values.

475833937637 475833946257
milliseconds between = 8620
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its not a simple function call -- you have to code something that will such as 1) erase the icon, 2) wait a few milliseconds, and 3) redraw the icon. Repeat for as long as you want it to appear to be flashing. Don't ask me how to do it because I don't know without doing a considerable amount of research.