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

which one you use might depend on what the callback function is going to do with it. If the callback function is going to change anything in the string then use the first one because the second is (probably) a pointer into read-only memory.

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

Here is a working code snippet. Just remove the const keyword when declaring data should solve the problem.

char data[] = "Callback Function called";

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

That's because by definition *nix software can't be pirated, it's already free.

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

Do you want to change the wallpaper on the computer? Here is a code snippet. that works for Windows os.

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

Or am I competely screwing it up?

Put it in a compiler and try to compile it. The compiler will tell you if you are correct or not.

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

I agree, I don't really like the preview either as it seems confusing at times. A checkbox or control panel option to disable it would be nice.

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

For lines 15 and 16 it is not possible to get the length of the string because neither string is NULL-terminated. If you ended each of those strings with '\0' then func() could call strlen() to get the length of the strings. In any event, its impossible for func() to know the actual size of the array, which may or may not be the same as the length of the string contained in the array.

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

No, like this.

    enum Category
    { 
        ROCK, POP, COUNTRY
    };

    struct Time
    {
        unsigned char minute;
        unsigned char seconds;
    };


    struct Song
    {
        string Title;
        string Album:
        string Artist;
        Time someTime;
        Category cat; // <<< this should not be a string
    };

int main()
{
    Song mySong;
    mySong.Title = "Test";
    mySong.Album = "Testing";
    mySong.Artist = "Tester";
    mySong.someTime.minute = 6;
    mySong.someTime.seconds = 54;
    mySong.cat = ROCK; // <<< No quotes on this one because it isn't a string
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you want to add a line to the end of a file you don't have to rewrite the file, just open with "a+", which will open the file for update and move the pointer to the end of the file. See more detailed description at this link.

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

[edit]^^^ exactly as Mike posted above.

The best way to do that is to create a virtual function in ExtraTerrestre class named putAlien() then override it in each of the derived classes. With that, line 28 in the code you posted will call the correct function in the derived class.

class ExtraTerrestre
{
   ...
   virtual void putAlien() = 0; // pure virtual function
}


class Dalek : public Extraterestial
{
    ...
    virtual void putAlien()
    {
      // implementation here
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Item 4. You're close. Move the structure definitions up above main() and outside any function so that they can be use in other functions when you write them. Structurde defined inside a function are not visible to other functions. Putting them at the top of the program, after includes, makes them global to the entire *.cpp or *.c file.

you can remove lines 26-28 because they were intended for the first exercise and not relevent to the 4th.

line 44: You have to put string literals in quotes, e.g. mySong.Title = "Test";

lines 47-48: you need to assign a value to those structure members like you did the other structure members.

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

what compiler are you using? I presume it's Turbo C on MS-DOS. What you have to do is scroll the whole screen up one line then print something on the blank line at the bottom. Wait awhile then repeat the process. It's not going to look as smooth as you see in the movies because MS-DOS windows aren't capable of that. If you want to see smooth scrolling then use a modern compiler and a graphic library such as OpenGL

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

See answers here

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

No.

int main()
{
    struct Time
    {
        unsigned char minute;
        unsigned char seconds;
    };

    Time someTime;
    someTime.minute = 6;
    someTime.seconds = 54;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The second problem is incorrect. You can't assign values to the variables inside the structure. Instead, inside main() declare an instance of the structure then assign the values to that instance.

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

You need to pass the head of the linked list by reference rather than by value. That means functions need two stars, not one.

For this function, since you are adding the new node to the head of the list an if statement isn't necessary. But you see that it needs a pointer to a pointer so that this function can change the address of the caller's pointer.

void push_node(struct node **node, int data){
    struct node *new_node = (struct node *)malloc(sizeof(struct node));
    new_node->data = data;
    new_node->next = *node;
    *node = new_node;
}

 int main(){
struct node* head = NULL;
push_node(&head, 10); // <<< see change on this line
push_node(&head, 2); // <<< see change on this line
display_node(head);
getchar();
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Maybe it would be easier to debug if you wrote a small program with main() that tests that class. That way you can test it without trying to debug your entire game at the same time.

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

The loop is all wrong. Don't assume there will be 51 numbers in the file. What will happen if there are only 10 numbers? or 100 numbers? It's not necessary to specifically test for eof() because the file stream will return NULL when eof() or an error is encountered.

 while(x < 51 && infile >> list[x]){
    cout<<list[x];
    ++x;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to include <string> header file.

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

I didn't know google bookmarks existed, that will solve one of the torns in my side too.

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

did you try this?

Mike Askew commented: Ah the classic link! +0
Prysm[VA] commented: I approve. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Instead of reading the file one character at a time, read an entire line at once and then parse it to break it up into its individual parts.

std::string line;
while( getline(infile,line) )
{
  // now break the line into its individual parts


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

did you change lines 19 and 20 like I said?

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

You need to check that the file was opened successfully. Put this after line 16

if( !infile.is_open())
{
   cout << "Error opening file\n";
   return 1;
 }

line 19: move the declaration of x up outside the loop so that it can be used to index into the array.
line 20: use the index value instead of 51 infile>>list[x++]; Change line 21 like that too.

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

The only one who can make a definitive answer is your teacher. Ask him/her.

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

You are reading too much into the problem. It doesn't say to increase the voltage every 2 seconds.

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

call strlen() to find the length of sentence then set a pointer to that position. In a loop you will have to decrement instead of increment the pointer so that you get the string in reverse order.

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

line 10: You are treating modify as if it were of type std::string, it isn't. modify is of type char* and character arrays don't have methods like begin() and end().

lines 3-5: What is the purpose of those lines? You can't convert a single character as you declared on line 3 as a character array. The pointer sentence should already point to a string of characters. What you probably want to do is convert from char* to std::string

std::string modify = sentence;

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

The way I read the problem is that the program should print either 0 or 3 depending on the time. There is no equation for that, just a simple if/else statement.

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

Which was exactly my point.

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

line 9: the typecast and & symbol are not necessary, just extra fluff that means nothing.

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

when you compiled it did you check to see if there are any errors or warning messages? Also, use Windows File Explorer to see if the executable exists in the project folder.

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

Dani has changed it in the past, but never for a specific holiday.

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

Post the code you have written so that someone can help you with any questions you may have. No one is going to just give you the solution to the program.

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

the loop on line 46 of the code you posted is wrong. All arrays are numbered 0, 1, 2, 3, etc. a[2] has numbers 0 and 1, there is no number 2. The loop sould be
for(i = 0; i < 2; i++)

You may have to adjust other loops with similar construct.

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

So where am i wrong in my code???

Reread my previous post because I already told you what's wrong.

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

there is nothing wrong with my current code,..

Are you blind or don't you comprehend what you are doing?

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

I think you need to use dynamic_cast instead of static_cast. Read the requirements for derived_class here and here As indicated in the second link if you use virtual functions in base class you may not need casts at all.

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

When you swap rows in a sorted array you also have to swap all the colums in the same row of the original array so that the rows in both arrays remain in the same position. There is an easier way to do it, but get what you have working first so that you will understand the easier way.

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

no, you can't get it free. You can get OpenOffice for free, the files are compatible with Microsoft Office.

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

Are you trying to do something like this?

class base
{
public:
    base() {x = 0;}
protected:
    int x;
};

class derived : public base
{
public:
    derived() {x = 1;}
protected:
    int y;
};

void foo(base* b)
{
  derived* d = static_cast<derived*>(b); // <<<< this line
}

int main()
{
   derived d;
   foo(&d);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is open() fails because you're trying to open the file for reading when the file doesn't exist. The file must exist in order to use ios::read flag.

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

the source codes should not be copied from the internet..

pls send me the code and how it works.,.and what language

So you're asking us to help you cheat??

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

If you want the array sorted by the sum value of each line then you will have to put the sum values into the array. Instead of hard-coding them like I did you can create a loop, calculate the sum and save the sum in the last column of each row. You could put the sums in another array, but that would make sorting even more difficult and complex.

Your program must do this in three stages
1. In a loop, sum each row and store the result in the array itself or in another array
2. Sort the array using any one of several sorting algorithms.
3. Print the array

You can't do all the above in the same loop, its not that simple.

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

One way to solve it is to keep track of the original row numbers and the sum for each row, then when the rows are sorted the program will remember the original row numbers. Expand the array by two columns to do that

int tekmovalci[rows][cols+2]={{7, 6, 9,0,22},
                                {8, 7, 8,1,23},
                                {6, 9, 10,2,25},
                                {7, 7, 9,3,23},
                                {8, 8, 10,4,26}};

Next, sort the array by the last column (total). When you print it out use the next-to-last column as the row number instead of the loop counter.

Sorting would be a lot easier if you used a structure to contain all the values then have an array of structures.

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

Where is function Traverse()?

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

There are lots of online tutorials, just google for them (click here).

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

National Treasure -- very good three-star movie.

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

That is a poorly written program becuse it passes the vector to PlayWithStrings() by value instead of by reference, causing the program to duplicate the entire vector on each entry to that function.

What compiler and operating system are you using?

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

I don't know how you declared Point, but below is a function that works assuming Point is a class or structure name, not declared as a pointer. This snippet just inserts the nodes at the beginning of the two linked lists, instead of at the tail. Also note that the originial linked list is not value after this function returns.

void Sort(Point* P, Point* &AT50, Point* &AO50){
    Point* temp;
    while(P)
    {
        temp = P;
        P = P->next;
        if( temp->value <= 50)
        {
            temp->next = AT50;
            AT50 = temp;
        }
        else
        {
            temp->next = AO50;
            AO50 = temp;

        }
    }
}