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

you don't need valid

Depends on his teacher. Many teachers require only one return in a function. Otherwise I would also do it your way. Using valid is always correct.

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

Also consider Knuth's report: Structured Programming with Goto Statements.

Also note that article was written in 1974 -- 34 years ago! C++ language hadn't even been invented yet and the first version of C++ wasn't released until 1983.

C language wasn't invented until 1971, just 3 years earlier than that 1974 Knuth article and the first version wasn't published by K&R until 1978.

So much for the creditability of that Knuth paper in modern programming.

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

A while loop won't help that.

bool GetNID(char buf[])
{
	int i= 0;
	int length;
	bool valid = true;

	cin.getline(buf, 30);

	length = strlen(buf);

	for (i = 0; i < length && valie == true; i++)
	{
		if (i < 2)
		{
			if ((buf[i] < 'a') || (buf[i] > 'z'))
			{
				valid = false;
			}
		}
		if (i > 1)
		{
			if (buf[i] < '0' || buf[i] > '9')
			{
				valid = false;
			}
		}
	}

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

>>if (buf < 0 || buf > 9)
Wrong -- you need to check for '0' and '9' (in quotes).

Your program has a major logic flaw. First assume the string is valid, then stop looking if any of the characters are not valid. The way you have it the value of valid will flip back and borth between true and false. The final value after the loop terminates in undeterminable -- It could be either true or false depending on the last character in the string.

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

use the isalpha() macro in ctype.h

bool GetString(char buf[])
{
	int i;
	int length;
	bool valid;

	cin.getline(buf, 30);
	
	length = strlen(buf);

	for (i = 0; i < length; i++)
	{
		if( !isalpha(buf[i]) )
		{
			return false;
		}
	}

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

First, the code you posted in red isn't needed.

if( leapyear(year) )
   cout << "is a leap year\n";
else
   cout << "is not a leap year\n";

bool leapyear( int year)
{
   // its actually a little more complicated than this but will do for
   // years in the 20th and 21st centuries.
   return (year % 4) == 0 ? true : false;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Start with this thread. Note that it is using floating point arithmetic, not integer arithmetic like you tried to do.

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

you don't normally put executable code in a header file. All header files contain are function prototypes, classes , structures and macros. Everything else goes in the *.c or *.cpp implementation file.

>> (9/5)*fahrenheit + 32
that is the same as 1 * fahrenheit + 32 because 9/5 = 1 (integer arithmetic discards all fractions)

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

line 30: remove the space between < and =

This is what I get when passed 9999999997 to that function. That is the correct answer.

Enter a number ...9999999997 <<<<< I added this in main() so I could test other numbers
faktor 13 och x 769230769
faktor 769230769 och x 1
13 769230769 Press any key to continue . . .

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

Which of all those files contains the problem you are trying to resolve? queueTest.cpp ? In that file line 3 is just wrong

ostream out("outfile.txt");
<snip>
 queue.Print(out);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you should have had another category: All the above :)

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

did you include <fstream> ?

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

you could have just made that a normal for-next loop

for(index = 0; index < iChk; index++)
{
   people.task(); 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

^ 1980's cool. What language did you use back then? It must be really cool to see how programming evolved to the level it is today. I cant even begin to imagine.

I used HP (Hewlette Packard) Basic, which was more like a mixture of Pascal and Basic. A really nice language in its day, and data storage was on 8 1/2 inch glass diskettes that looked a lot like 33 1/3 RPM records\

Then we got our first real PC -- ran a whopping lightening-fast 128 mz cpu with 64k memory, two 5 1/2 inch single-sided floppy drives and no hard drive and MS-DOS version 1.0 which did not support sub-directories, everything was in the root folder. We got a C compiler (Lattice C) that all fit on one of the diskettes and the data was on the other disk. When I started a compile it took so long to finish that I went to another desk and read a book or did other things. That version of Lattice C implemented the original K&R style C programs.

hammerhead commented: Wonderful. One can really learn from a person with your level of experience. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 9 and 10: why are those pointers? The whole purpose of the std::string class is to remove get rid of pointers and memory allocations from coder's obligations. There is no need at all for those two pointers

lines 23 and 24: again, why? If you don't use the pointers in lines 9 and 10 you don't need to dynamically allocate them here.

If what you are doing with those two pointers is an attempt at making arrays of strings, then a better way is to use vectors, which again do not require you to do memory allocation stuff.

class list
{
public:
    int iMemberCount;

    vector<string> sName;
    vector<string> sAge;

    void task();
    void newInfo();
    void preview();
    void memCount(int iTotalMemb);
    list();
};

line 54: why ???? just code like this: int index = 1; line 56: how is index incremented ? Its impossible for index to anything other than 1 because of line 54.

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

>> it is not displaying the correct value
Yes it is -- it is displaying it in scientific notation. You can do the same thing in C by using "%e" instead of "%f", for example:

int main()
{
    double x = 0.000142;
    printf("%f\n", x);
    printf("%e\n", x);
    return 0;
}

0.000142
1.420000e-004
Press any key to continue . . .

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

It might be compiler dependent, but VC++ 2008 Express will accept a 64-bit integer as the first parameter to seekg() which I guess means it supports huge files.

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

Well you better decide how you want the file because you can't do a thing until you know what the file contains. Your teacher probably left that up to you.

The easiest way is to create a text file with one number per line -- you can create the file with Notepad or any other text editor. Then just read the file as previously shown.

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

It is always recommended to register the component with windows and then use it in VB 6.0.
Add the same from Project---->References

and then use it.

Most dlls can not be registered.

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

Want a Ph.D. ? You can buy one here for $600.00 USD :)

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

I'm supprised they would accept that kind of record because its so easy to cheat. And 30 replies is peanuts compared to many boards and in the Games board here at DaniWeb. One such game has almost 2,000 posts and that's one of the smaller ones.

Now, something like "Online Forum Topic with most replies where no one person posted more than once". That might get some attention :)

I thought about entering one for the most game of MS-Hearts played until I realized it was so easy to fiddle with the numbers.

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

>I implore you AD, don't become one of those silly people who make absolute statements like "never use goto".

Your're about 20 years too late :)

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

what data does the text file contain. In order to read the file you have to know what the file contains.

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

There is never ever an acceptable use of goto. I know teachers who give an F for a program that uses it, and the companies I worked for absolutely forbid it.

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

both -- first the exe file is run then your program should use the file name that you typed. The file name will be in the argv parameter to main

int main(int argc, char* argv[])
{

}

In the above argc is the number of command-line arguments you typed plus 1. So in your example the value of argc will be 2. If it isn't 2 then you did something wrong on the command line.

argv[] is an array of the argument strings. argv[0] is always the name of the exe program, and argv[1] will be the name of the textfile you typed on the command line.

So to open that text file for reading you do something like this:

#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
    ifstream in(argv[1]); // <<<< opens the file for reading
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A couple years?? That is way too long. See http://en.wikipedia.org/wiki/Foot_binding for details as to why. Not that I'm an expert on education or anything. But 2 years is one half of high school!

But two years is only Freshman and Sophmore years of college, hardly what I would consider becomming an expert at anything other than booze and women :)

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

There is no support in standard C or C++ for huge numbers beyone 64-bit integers. But you can do some googleing to see if you can find a math library that will supply such functions, or write your own by using character arrays to hold the digits.

>>For the first the long declaration is correct but quiet unessesery
My compiler, VC++ 2008 Express, produced an error or warning on that line. Deleting the int part of that line fixed it. Your compiler probably didn't complain.

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

Take the FileList as the only command line parameter. For example,
C:\>TinyGoogle.exe myfilelist.txt

You need to create a file that contains the names of all the other files that your program is to index. So you have to create myfilelist.txt before you can do anything.

>>what does the command line in the requirement means
I assume you are using MS-Windows ??? Then it means to click the Command Prompt icon on your desktop if you have one, or Start --> Assoirceries --> Command Prompt. Then type that in the command prompt window. Of course you will have had to have written and compiled your program before it will work.

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

line 47: get rid of the else. And check if dd is not greater than the number of days in the month, such as if( dd < 1 || dd > months[dd-1] ) line 65: delete it. Do not do that whether its a leap year or not. The only reason for checking for leap year is to determine whether the max days in Feb is 28 or 29.

You didn't post that leapyear() function which I guess is supposed to determine if the year is a leap year or not.

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

Okay so that fixed everything except that I still have to put in 0 or 1 for the credit score.. Is there any easy way to fix this? .

Of course there is -- I already said all you have to do is change the data type to std::string and then test it like you did the others.

>>To do this I would need a counter of course but how would I get the percentage
You need two counters -- one that counts the total number of applications and the other that totals the number of approved applictions. The percentage is (approved / total applications) * 100

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

Large business applications -- no because it would take too long and too difficult to maintain the programs. There are a few occasions in systems-level programs that might require assembly but any program that requires user interface is not feasible to be coded in assembly.

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

using those requirements

bool approved = false;
        if( age >= 16)
        {
            if( credit_rating == 1)
                approved = true;
            else if( house_owner == "yes" )
                approved = true;
            else if( permanent_job == "yes" && monthly_income > 3000)
                approved = true;
        }
        if(approved) {
            cout << "*APPLICATION APPROVED*" << endl;
        } else {
            cout << "*APPLICATION DENIED*" << endl;
        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>do you think it's worthwhile to learn Assembly at a later point?
Absolutely yes because it gives you a better insite into what's going on in the background with the C++ code.

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

I started in 1980, a few years before I retired from the USA military.

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

Learn C++ first.

>>My goal is to learn how to program, not to memorize syntax.
Sorry to burst your bubble but at first that is exactly what you will be doing.

>>I am a Mac OS X user and prefer learning a language on OS X
Nothing wrong with that -- that means you won't be able to learn VB and C# anyway because IFAIK those languages are only supported in MS-Windows.

>>I understand that I won't be an expert over a weekend, but I want to learn, for hobby and later possibly for profit.
If that is your goal then you will want to eventually learn many different languages, especially web development. But for now, just start with c++ and in a couple years when you have learned it well you can think about expanding into other languages.

Don't think for one minute that there will ever be a time when you can say "I have learned all there is to know about C++". That day will never arrive. Computer programming is a life-long learning experience and there will always be something new for you to learn and new challenges.

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

do you mean you want to be able to enter "yes" or "no", or "good" and "bad" instead of 1 and 2? Just make it strings like all the others.

You have other logic errors because no matter what I enter my application is always approved. Even after changing the character arrays to std::string.

I think what you probably want is this: if(age >= 16 && credit_rating == 1 && house_owner == "yes" && permanent_job == "yes" && monthly_income > 3000) { You don't want to approve the loan unless all those conditions are met.

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

>>it works the way I have it...
Depends on your definition of works. If you mean compiles, then the compiler is comparing addresses, not strings because the compiler isn't smart enough to know any different. Try running it and you will see that it doesn't do what you think its doing.

Humm-- this is the output of your program -- no wonder we have a housing crises in this country! :)

KREDA CARD APPLICATION
Name: melvin
Age: 65
Monthly Income: 0
Credit Rating: 1
Owns House: maybe
Has Permanent Job: no
*APPLICATION APPROVED*


Would you like to process another application?

Another run -- note the negative income level

KREDA CARD APPLICATION
Name: melvin
Age: 500
Monthly Income: -45000
Credit Rating: 0
Owns House: nope
Has Permanent Job: nope
*APPLICATION DENIED*

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

When you exchange one array during the sort you have to make similar exchanges in the second array. That's one reason that many (most?) programmers put suich things in an array of structures -- to make sorting a lot simpler.

struct data
{
    int a;
    int b;
};

Now instead of sorting two arrays you only have to sort one array of structures.

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

>>permanent_job == "yes"
You can not compare character arrays like that -- only std::string. So you will have to call strcmp() to compare two character arrays if( strcmp(permanent_job,"yes") == 0) But if you change permanent_job to std::string then the comparison you made will work

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

post code and error message(s)

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

assuming answer is a string

bool result;
if( answer == "YES" )
    result = true;
else
    result = false;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Do While rate <= 0.1
You have to set rate to value of 0.05 before the above line. The way you have it now that variable just contains any old random value which might or might not be less than 0.01.

Just before the end of that loop you have to increment rate by a value of 0.01.

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

Do you mean you want to write a dll with fortran and call it from VB ? I don't know if that is possible or not, you would have to check with your fortran compiler.

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

line 4 is declared wrong. should be long long , not long int To my knowledge there is not such thing as long int

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

The first name must be validated to only accept lowercase and uppercase letters (limited to 30 characters).

That means you need to make room for 30 characters plus null terminator, or total of 31. char first[31];

The NID must be validated to only accept lowercase letters and numbers (limited to 30 characters).

Just like name, the NID (whatever that is) need to be 31 characters char NID[31]; There is no need for a pointer as you have it.

The four functions you have started are incorrect. Look at the return value in the instructions then in the code you hav eposted. They are not the same and you need to correct that.

Now to fill out those four get functions. A get function mearly returns a value from the structure of class. For example, the first one GetFirstName(char *fn) should copy the first name into the parameter and return either true if it was ok, or valse if there is no first name in the structure. Here's an example:

bool GetFirstName(char *fn)
{
    if( name.first[0] != 0 )
    {
        // first name is valid, so copy and return
        strcpy(fn, name.first);
        return true;
    }
    return false;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

digiman: I merged your two threads because they asked the same question.

>>I just posted earlier but realised that the thread was closed
I don't think so. It didn't look closed to me.

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

>>and I have some error in my code ,and I cant correct them
I just got new glasses the other day but I'm still having problems seeing the errors you get on your monitor. So would you post them here to make them easier to read ?

mitrmkar commented: I just got new glasses the other day but I'm still having problems seeing the errors you get on your monitor. <=> LOL +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why don't you format the string and then send it to sybase. The code below won't be 100% correct because it does not account for the floats and integers. The main thing is that you have to surround all strings with quotes, and nothing for floats/integers. You can not pass the strings to sybase without the quotes or sybase will puke up all over you.

char command[1024];
strcpy(command,"insert into my_table values( ");
while (token != NULL) 
{
    strcat(command, "'"); // surround text with single quotes
    strcat(command,token);
    strcat(command,"', '"); 
    token = strtok(NULL, ",");
}

Now the resulting string in the above will be terminated with one too many commas, such you will have to strip it back off

command[strlen(command)-1] = 0; 
ret = dbfcmd(dbproc,command);
if(ret == SQL_SUCCESS)
{
    ret = dbsqlexec(dbproc);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put the longest string in strarray[0], the shortest in strarray[1] and the third string in strarray[2]. Then you can easily print each of the three strings in order they appear in that array.

How do you find out which string is the longest? Here is an example

std::string shortest, longest, other;
longest = str;
if( str1.length() > longest.length() )
    longest = str1;
if(str2.length() > longest.length() )
    longest = str2;
// now make the same tests for shortest
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

or can it expand once limit reached?

If you want something that will auto-expand when the current limit is reached then use std::string. Otherwise you have to allocate a completly new string, which can be somewhat a pain in the a** to code correctly.