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

Any help with how to replace an instance of a character in the array with the first character of the array would be greatly appreciated :)

sentenceHolder1[i] = sentenceHolder2[0]; will replace a character in sentenceHolder1 with the first charcter in sentenceHolder2.

>>Yea I wasn't planning on handing that part in, my prof just suggested in one of our classes that it
>>was possible and I was wondering how you could do it because he won't tell me.

Yes it is possible. Hint: strstr() from string.h is your friend when working with charcter arrays. There are better ways when using c++ std::string class, but you probably have not gotton to those in your class.

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

Stick to the program requirements and don't try to do fancy stuff. Your task is to code what the prof asked you to code, not to make up stuff on your own.

There isn't anything wrong with trying out various things on your own -- just don't hand any of it in as part of the assignment.

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

line 9: If you want someone to type up to 20 characers then you have to define charString as 21 in order to allow room for the null string terminating character.

line 23: All you want here is to enter a single character, not an entire string. Similar to line 26.

lines 29-42: all you need here is just one loop to test each character in sentenceHolder1 for the character you enter on line 23 and possibly replace it with the replacement character.

int len = strlen(sentenceHolder1);
for(int i = 0; i < len; i++)
{
    if( sentenceHolder1[i] == look_for_character )
        sentenceHolder1[i] = replacement_character;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

by vector do you mean a character array ? Such as char data[255]; Use the FILE and associated functions located in stdio.h to read and write files. Here is a tutorial.

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

create two variables called heavest and lightest. Then create a loop like you did on line 33, but instead of adding up everything keep track of the heavest and lightest values. For example:

if( a[i] > heavest)
   heavest = a[i];

and do the same for lightest except of course your have to use < operator instead of >.

Be sure to initailize both of the variables to a[0] before starting the loop.

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

how it looks is not relevant. Does it work the way you want it to work? Yes -- then its ok. No then you need to do more work.

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

since the array is global it isn't necessary to pass it as a parameter.

line 16: just make that a function call reading_data_into_array(); line 21: make that a void function because it isn't necessary to return anything and delete the parameter because the array is global..

line 24: you need a while loop to read each of the numbers into the array

int i = 0;
while( infile >> a[i] )
    ++i;

line 25: delete it.

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

you have to flush the input keyboard buffer of the '\n' after each numeric input

cout << "Enter the players number :";
        cin >> player[i].number;
        cin.ignore();
        cout << "Enter the players points :";
        cin >> player[i].points;
        cin.ignore();

line 34: that's an infinite loop because 0 is ALWAYS less than SIZE ! Correction here: for (int i = 0; i < SIZE; i++)

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

Unlike *nix you can install the source code anywhere you like.

I downloaded mysql++-3.0.2.tar.gz and used WinZip to decompress it. In the uncompressed directory you will see volders for VC2003 and VC2005. Just fire up your compiler and select File --> Open --> Project Solution. Navigate to whereever you installed MySql++ and select mysql++.sln

I guess you have to have MySql server installed because I can't compile it the VC++ 2008 Express. mysql_version.h is not included in the above download.

VernonDozier commented: Thanks. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would work though the tutorial first to find out how things go. Then it will be easier to understand QT.

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

Or a nuclear war.

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

for( i = 25; i >= 1; i--) Check that i is greater than 1. In your code 25 will always be greater than i because i starts out at 25 and goes down from there.

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

Start at the top of the list you posted and do them just one at a time. Don't attempt to do them all at once. Do the first requirement then compile, correct bugs, and compile again until all problems have been fixed. Only then do you begin the next statement.

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

>>This is the first question I have, does that mean studentType is the base class or persoType is the base class?
personType is the base class.

>>cout << studentList[count].getFirstName
getFirstName is a function, so you need parentheses just like calling any other function cout << studentList[count].getFirstName() Same with getLastName -- use parentheses as above.

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

>> I wonder what's next.
According to legend Pope Benedict XVI is the last pope. The next one will be Saten himself.

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

Assuming we're all still here of course.

I don't know about you but I will be :)

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

ancient said but according to that page, he does.

That was posted before Dani and Happygeek gave me modly powers here :)

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

No one here is going to do your homework for you. Sounds like you are way over your head, so either drop the course or hit the books.

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

please answer for this..i iwll be very grateful to u

You didn't ask a question. All you did was dump your homework assignment here.

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

post code. If its reading character by character then it will pick up spaces too.

char c;
while( infile.get(c) )
{

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

I added some more to my previous post -- please re-read it for more suggestions

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

The code you posted isn't very useful. Check for missing semicolons, especially at the end of the class declaration

class object
{
<snip>
};

Looks like the problem may be in the way you have the header files included.

food.h >> objects.h >> maincontrol.h >> food.h

So nothing is fully defined. Try adding class forward references.

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

There are many companies who have that rule as a coding standard. One way in and only one way out of a function.

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

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

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

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

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

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

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

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 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

>>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

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

>>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

line 6: if you can enter 1-10 characters then that array isn't big enough -- need to make it size of 11 to hold the string null terminating character.

line 9: does your assignment require you to use dynamic memory allocation? If not, why are you using pointers ?

line 16: delete that line and allocate all the memory at one time on line 9 like this: char* Arr = new char[11];

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

want to count upper case 'A' and lower case 'a' separately or as a single character?

I would create an int array of 256 to represent all the possible characters in a text file. Actually that's more than is possible in a text file, but it makes the math easier. Then as you read each character you can let the character itself index into that array. For example, if the program reads the letter 'A'

int arry[256] = {0}; // declare the array

<snip>
int c;
// read a single character
infile.get(c);
// increment the counter for that character
arry[c]++;

Put the above in a loop, when the reading is all done you have the sum for each letter. Just loop through that array and print the values that are greater than 0

for(int i = 0; i < 256; i++)
{
    if( arry[i] > 0)
        cout << "Letter " << (char)i << " = " << arry[i] << "\n";
 }

You could also probably do this with <map> but the coding would be a little more difficult.

coolbreeze commented: definately a guru +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>WHY???

because you failed to correct this line as Salem suggested: scanf( "%d",year); Make that right then retest.

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

>>if(ch = 48,49,50,51,52,53,54,55,56,57)
You can't construct an if statement like that if(ch >= 48 && ch <= 57) or better yet if( ch >= '0' && ch <= '9')

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

Q1: put the strings in an array and then sort them.

#include <vector>
#include <string>
#include <algorithm>

<snip>

std::vector<std::string> strarray[3];
<snip>
std::sort(strarray.begin(), strarray.end());

Q2: Open and close brackets are incorrect.

if (ch = 32)
{
    cout << space << endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Any other ideas why?

Most likely crased because you didn't change "%.3lf" to "%d" everyplace. If you did that then you have to post the code again

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

Its not in the makefile, but a difference in the code. Post the function header in the lib. the prototype in the header file (if you have one), and in the function call in the application program. Could be something as simple as const in one and not in the other.

sjcomp commented: Very helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do it however you want, but you still won't be able to maintain the spacing and tabs of the original program that way because the >> operator skips over them.