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

Its not necessary to pass those pointers by reference because the functions aren't changing them. Passing by reference in those functions does nothing more than bloat the code. Just pass the pointers instead.

>>++mat->element;
You don't want to do that. Do it like this:

for (int j = 0; j < mat->columns; ++j)
{
        print << mat->element[j] << "  ";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> "U better get it all wrong than copying it or writting something that u dont understand coz U gona get 0 if u cant explain what u did or u have copied it"
Good for your instructor :) :) I'm not about to rewrite your program for you because I don't want you to get a 0 one the paper. Its better that there are a few errors in the program than to make it look like you didn't write it.

line 10: you need to initialize the array to 0 like this: int quantity[6] = {0}; line 40: This is where you seem to be having lots of problems with the array. That array has 6 elements -- the first one is number 0 and should represent the quantity of "Floral Dreams" purchased. Therefore you want to enter a value in quantity[0] like this: cin >> quantity[0]; In the next case statement it shoule be quantity[1], then in the next quantity[2], etc.

lines 12 and 14: you can't use the same variable name more than once.

lines 42 and 43: you don't need those lines at all. Just delete them and similar lines in the other cases.

line 90: this is another common error -- the array elements range from 0 to and including 5, the for loop should be for( i = 0; i < 6; i++) . Note that all you have to do in your program is replace the <= symbol with just <.

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

The function beginning at line 52 inserts a new node at the head of the linked list. It does this by first setting the new nodes's link pointer to the current head, then changing the current head to be the new node. The function looks like it will work correctly.

>>And i think my output function is not right
You are correct -- that function is not correct because it needs a loop to iterate through the linked list and print them one at a time

while( temp != NULL)
{
    // print the node's data is not shown

   // advance to the next node
   temp = temp->Link;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Put all the text in the box into a String, not necessarily what's at the current cursor position. But look in MSDN at the methods available for the text box and see if there is an easier way to do it, but I doubt it.

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

If that text box is like MFC then you have to get the string that's already in the box, make whatever changes you want, then put the entire string back.

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

It's just a simple function call. Read this:. The paramter [x] would be the value of e (whatever that is) and the paramter y is the calculation -((W1A * pix1) + (W2A * pix2)));

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

your code needs to call pow() to raise x to the power of y. Don't know what exp is in your code.

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

The problem was the way the files were being read in main(). Attached is a corrected copy of the cpp file.

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

<deleted>

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

There are a lot of classes that do not have an implementation file. Take this simple example:

class Hello
{
public:
    Hello() { message = "Hello World";}
    void SayHello() { cout << message << "\n";}
private:
    string message;
};

In the above, lines 4 and 5 are called inline methods because all the code needed to implement the functions are right there in the interfact file. Entire classes can be coded that way.

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

One last question, if I separate my classes into two interface files can I use the same implementation file? I am pretty sure I can but not certain...

You can, but a better question is should you? Do it however your instructor/professor and/or textbook suggests. In some cases you may not need an implementation file at all -- when everything is inline in the interface file.

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

>> but I am not a commander of brownie points and thus cannot give any to you.
Awe shucks, and I was hoping to have some brownies tonight :)


>>Can an Interface file contain multiple classes?
Yes. There is no restriction by the compiler or c++ standards on how may you can put into the same file. But for your own sanity (and maybe a better grade) if the classes are large you should separate them into different files.


>>If so how would one implement this interface file (what specifications do you need to use to specify which class you are using)?
It's the same whether the classes are in the same or different files. <class name>::<method name> identifies a specific method within a class.

>>If this is not legal or is a bad programming practice then please explain why
Here are only three reasons. I'm certain other programmers can think up many more reasons.
1) Its just better management to put the classes in different files and it makes the files smaller too.

2) Instead of editing a one-million line file you can edit a file with only a few dozen or so lines.

3) Its easier to find the class you need to work with. If all the classes are in one file you have to search through the entire file to find the class you want -- assuming you put all the methods …

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

Is this a test question? How many browney points do I get for answering it :)

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

line 36 and 95 are wrong. should be sizeof(buff) (which is 16) not sizeof(buf_num) which is an integer and more likely to be 4. OR maybe you want to set all the unread bytes to the value of pad? If that's correct then why not just set the entire buffer to spaces and the do the read?

I think all the lines 31-36 and 91-95 are suspect. It looks like it is trying to do too much work. Just tell read() to get 16 bytes, and if the file size is smaller than that then read() will get the entire file. There is no need to outguess the read() function. You can call stream's gcount() function to get the actual number of bytes read.

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

Oh! buff is a two dimensional array then ? If you want to fill the entire array with spaces then the simplest way is to use memset memset( buff, pad, sizeof(buff) ); Otherwise you need two loops, which is a lot more code and a lot slower than menset().

for(int i = 0; i < 4; i++)
{
   for(int j = 0; j < 4; j++)
   {
          buff[i][j] = pad;
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 6: you are attempting to assign a string to a character. Replace the double quotes with single quotes: char pad = ' '; line 9: how is buff declared? Is it a character array? then you need to index into buff like this: buff[i] = pad;

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

just put C/R in several places. The compiler doesn't care where they are.

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

just put a space between each one cout << The average of: " << a << " " << b << " " << c << d << " " << e << " "<<" = "

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

That means you still have errors. You three options to resolve that problem -- they are all correct but some are better than others.

1) put using namespace std; at the end of the include list, on line 4. This is probably the least preferred option.

2) add using statements for each function you want to use from the std namespace on line 4

using std::cout;
using std::endl;
// do the same with all the rest of the functions

3) Identify the namespace inside the code itself. I don't like this though because it makes the code look somewhat awkward. std::cout<<"What is the price of the vehicle?"<< std::endl;

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

>>I'm trying to do section off functions by themselves first
Excellent appropach to the problem. Do it just a little bit at a time and you won't have so many problems.

Line 8: remove the semicolon at the end of the line. That is a very very common error that we all get occasionally.

lines 2 and 3: those header files belong in angle brackets, not quotes

#include <iostream>
#include <iomanip>

The only header files you put in quotes are the ones you create yourself and are in your project directory or those that may be located in some non-standard directory that your compiler doesn't know about.

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

if you're gonna pass the address of the variables as stated in line 23:
void yrCalc(int totalDays, int& year, int& month, int& day)

Your variables should contain also their address in line 16:
yrCalc(40000, &year, &month, &day);

Not so -- you are thinking C, not C++ because yrCals() does not take pointers.

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

line 23 should look like this: void yrCalc(int totalDays, int& year, int& month, int& day) If you do that then you also have to change lines 25-28 to use the valid variable names shown above.

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

line 23: you are attempting to give each of the variables two names -- delete a, b, c and d then leave all the rest.

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

>> strcpy(view[place.y][place.x],"s");//says that the problem is here[/b]

That is just a character, not a pointer. same as attempting to do this: strcpy( view[0][0], "S"); If all you want to do is replace the single character then use the assignment operator, not strcpy(); view[place[i].y][place[i].x] = 's';

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

Another version

void capitalizeFirsts(char *buf)
{
    while( *buf )
    {
        while( isspace(*buf) )
            buf++;
        *buf = toupper(*buf);
        while(*buf && !isspace(*buf))
            buf++;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

typecast it

float n = 123.45F;

double x = (double)n;

or
double x = static_cast<double>(n);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hummmm. Seems your function needs a tad bit more work. But its close.

int main()
{
    char str[] = "now \tis     the   time  for   all    good    men\n";
    capitalizeFirsts(str);
    puts(str);
    return 0;
}

Results

Now     is     The   Time  for   All    good    men

Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>capitalize the first letter of each word they type in,
One way to do it would be to use strtok() to find each work then toupper() to change the first character to upper case. strtok() modifies the original string so you will want to make a copy of the string before doing anything with it.

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

line 14: you have to specify the name of the Student object, not just the data type float calculateGrade(Student& stu) When writing inline functions like that one you must always given the parameters both data type and variable name. In this case I would make it a reference to a Student object so that the compiler doesn't have to duplicate it when it is passed.

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

Sorry AD. In another thread you added line numbers to my code so I tried to add them, but used the wrong button.

All you have to do is add the language to the code tags

[code=cplusplus] // put your code here

[/code]

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

Why did you use list tags when you posted that code? That just makes it impossible for anyone to copy/paste into their compiler's editor. Please repost without using those tags.

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

use the fstream's >> operator, exactly as you already posted in your program using cin to get the name.

ifstream in("filename");
string word;
while( in >> word)
{

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

add this just before getline: cin.ignore();

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

line 4: delete it because its redundent. Its not necessary to predeclared the class if your going to fully define it in the very next line.

line 13: As written that function does nothing. YOu need to add a bit of code that sets array Grade = array G.

line 18: that operator is not written correctly. Student x must be passed by reference, not by value, and y must have a data type. Its also missing ) at the end of the if statement

line 19: Teacher has not been declared yet, so the compiler will error on that line, which is probably the error you mentioned in your description post. Move the declaration of Teacher beginning on line 21 up above the declaration of Student and it will probably compile ok.

Lines 30-33: I don't think you can do it here even though it is declared a friend class. The compiler doesn't have any clue there array Grade is located. Best way to resolve this is to put the code in Student::setGrade method and pass array G to that method.

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

That form of cin.getline() only works with character arrays, not std::string objects. To use string do this instead. getline(cin, address)

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

The functions in graphics.h are only supported by old ancient Turbo C and Turbo C++ compilers. Those functions can not be used by any modern 32-bit compiler. You can either get a copy of that old MS-DOS compiler or use win32 api GDI functions or get one of several graphics libraries such as OpenGL and QT.

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

If you look at the code snipped I posted earlier you will see that the filename is surrounded by double quotes to that you can easily tell if there are leading and/or trailing spaces.

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

>> cin >> address;
The >> operator does not accept spaces. So if your address contains spaces it will pick up only the text before the first space. Use getline() to get everything including spaces.

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

Next step: display the name of the file that it is attempting to open, then compare it with what you think it should be. There is obviously something wrong with it. Even one mis-placed space will make a difference.

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

You posted those in your original post -- I missed that :)

to use is_open()

ifstream FindFile( FileName3.c_str() );
if( FindFile.is_open() == 0)
{
   cout << "Error opening file: \"" << FileName3 << "\"\n";
}

Sorry that I can't be much more help because you didn't post enough of the code to allow me to compile and test.

If you run that code on any other version of Windows other than XP it will not work because "c:\Documents and Setting" doesn't exist on Vista.

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

Please post the contents of NewDataGroup.txt -- or at least the first 5 or 6 lines if the file is really huge.

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

You don't have to specifically clear the vector because it will be destroyed and recreated on each loop iteration. Just wasting cpu cycles to clear it yourself.

>>foor-loop
Its spelled for-loop. There is no such word as foor, other than as a proper name. :)


>>What is the difference, Why does it work when I manually specify the pathway to the files
My guess is that the files are not where you expect them to be. After opening a file call the is_open() function to see if the open succeeded. I'll bet it failed. Carefully compare the files and their paths in NewDataGroup.txt with those you hard-coded in the program.

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

I realize you didn't post all your program, but what do you do with the vector ReadInData that is declared inside that for loop ? The entire vector is destroyed on each loop iteration and you do nothing with it but toss it into the bit bucket.

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

x = tolower(x); is how you convert the character in variable x to lower-case.

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

>>'fopen' was declared deprecated
That's only a microsoft warning. You can just ignore it because the c++ standards has not made it deprecated.

FILE, fopen() and all associated functions are declared in stdio.h, not iostream or fstream. In c++ programs you really should not be using those C functions, in otherwords, the file is not in the directory you think it should be in.

The problem is NOT with fopen() -- looks like you coded it correctly. I suspect you are not specifying the correct path to the file.

There is a pretty easy way to tackle your program. There are at most 255 possible characters, and less than half can be typed from the keyboard. So if you make an array of size 255 then when a character is read you can simply use that character as an index into the array and increment it.

int counts[255] = {0};

char line[] = "Hello World";
// count the number of characters in this string
for(int i = 0; line[i] != 0; i++)
   counts[line[i]]++;

Now when the above loop finished, the array counts will contain a list of the number of times each character appears in the string. You can do this for an entire file if you wish.

To find out the characters that appeared in the text just check the array counts for non-zero elements. The letter 'H' has an ascii value of 72 (look it up in any ascii chart), so counts[72] …

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

Bitwise operators

The last one, line 15, is just null-terminating the string. The author could have simply use 0 instead of 0x00.

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

use void main() instead
and add system("PAUSE") at the end after the cout statement

You obviously have no clue. Read this.

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

>>What do you mean by the functions having an internal linkage?

Explaination here:

>>Also, from my understanding, an anonymous namespace is just one without a name, so how would I call that?
The same way you do all other functions in the standard C/C++ libraries (other than class libraries). None of them are defined within a namespace. Just don't declare a namespace for them.


>>The guard would be so I don't call unwanted functions, right? But isn't that implied of an anonymous namespace?

No. Code gards are a completly different issue, and has nothing to do with namespaces.

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

God I love you. I was able to make 2 simultaneous running threads so easily it is funny.

Please deposit $1,000,000.00 USD in my PayPal account :) Glad I could help.

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

your program has a couple problems:

1) you must declare main like this: int main() . You can't leave off the return type.

2) you need to strip the '\n' character out of the keyboard buffer after each cin. There are several ways to accomplish it, but this method will work if the only character is '\n'. For a more complete discussion see Narue's thread here.

cin >> age1; 
cin.ignore();