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

>>No. I definitely do not know how to do it
That's why you are in school -- to learn how :)

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

>>Anyone know how to accomplish this task on visual studio with C++?
Yes. Do you? Hint: start out the program very simply and prompt for input. When that is done put that in a loop. Compile and correct all errors again. After that, add code to implement the rest of the requirements.

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

The problem is line 9: remove the \ (line continuation character) at the end of the line.

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

Check to see if the number is already in the list before adding it. The delete() function is not the place to do that. Write another class method that does nothing but search the list for a number, return true if the number already exists in the list or false if it doesn't. Then if it doesn't call that Insert() function.

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

The problem is in main(), not that delete function. First it calls insert to insert a new number then turns right around and deletes it. Delete that line

while(inFile>>number.item)
{
	display.Insert(number.item);
	//display.Delete(number.item);  <<<<< delete this line
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post new code.

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

Its done something like this: Note: not compiled or tested.

node* temp=start_ptr;
node* prev = NULL;
while( temp )
{
   if( temp->item == item) 
   {
          // delete this node
         if( prev == NULL)
         {
            // we are at the head of the linked list, for remove the head
            start_ptr = start_ptr->nxt;
         }
         else
         {
               // we're somewhere in the middle of the linked list
               prev->nxt = temp->nxt;
        }
        delete temp;
        break; // all done
   }
   prev = hold;
    hold = hold->next;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while (nodePtr->pointer != a)
    {
       nodePtr = nodePtr->next;
    }

What happens when thre are no nodes whose value is equal to variable a? Answer: infinite loop that will eventually crash your program. That loop needs to also check for end-of-linked-list, which is normally indicated by NULL nodePtr

while ( (nodePtr != NULL) & (nodePtr->pointer != a) )
    {
       nodePtr = nodePtr->next;
    }

What kind of object is nodePtr->pointer ? Is it a pointer to something? If it is, it can't normally be compared to an integer.

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

To convert an ascii digit to numeris, all you have to do is subtract '0'. Here's one way to do it. Note that getchar() returns an int, not char.

int a = -1, b = -1;
int input.
while( (input = getchar()) != EOF)
{
    if( isdigit(a) )
    {
         if( a == -1)     
        {
            a = input - '0'; // convert input to binary digit
        }
        else
        {
            b = input - '0'; // convert input to binary digit
        }
        if( a > -1 && b > -1)
        {
            cout<< "a " <<a << " b" << b <<endl;
            a = -1, b = -1;
       }
   } // end if( isdigit() )
} // end while loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

class Bicicleta must implement all pure virtual methods of its base class before it can be instiantiated. It does not do that, hence the error message. Add the function virtual float calcImposto() const; (identical to the one in Veiculo but without the =0 part) to Biciclets and it should resolve the problem.

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

What you posted looks ok, so the problem is after that while loop. If its prompting for more user input, such as a string, then you have to clear the input stream of the '\n' that's still in the input buffer from inputting an integer. See this thread for how to do that.

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

From the original post

int main (void)
{
    float a;

    int n;

    printf("\n enter values of a an n");

    printf("\n %.4f to the power of % d is %.4f",a,n,power(a,n)); 
}

What's the value of n ? Answer: It just has some random value because it was never initialized to anything. You forgot to get user input using scanf() or something else.

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

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

typedef vector<string> row;

vector<row> *vec1 = new vector<row>;

That's not managed code, but managed code is probably something similar.

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

If this is a C program then do not code it in a file with *.cpp extension because the compiler may give some wrong error messages. Rename the file to have *.c extension for better compile messages.

line 7: it should be int main() -- you can not leave off the function's return type

compare the differences between lines 4 and 17. They must both have the same parameters.

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

if you are getting multiple definition errors, change your headers to look like this:

#ifndef HEADERNAME_H
#define HEADERNAME_H

// Your code here

#endif

That way if you include a header more than once, it'll only be included if it hasn't been.

Read previous responses -- that isn't the problem.

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

No it doesn't matter because the second parameter to FindEventR() is not a member of any class.

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

The problem is that you defined ListNode as a private member of Event class. So you can't use that structure outside ListNode. Make the structure public or move it outside any class. If you leave it as public member of Event class then you have to use Event::ListNode in order to access/reference it.

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

Same thing ArkM told you a half hour ago.

The problem is that you are including readcharacter.cpp in main.cpp as if readcharacter.cpp were a header file. Never ever do that. Each *.cpp file must be compiled as if it were the only *.cpp file in the project. After the files are compiled, the compiler will link them all together.

What you need to do is remove that line #include "readcharacter.cpp" from main.cpp. After that the whole think links correctly. That doesn't mean the program is bug free -- it only means the compiler successfully compiled and linked it.

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

You people are making a mountain out of a molehill.

int main()
{
char arr[] = {'a', 'b', 'c', ' ', ' ', ' ', ' ', ' ', 'd', 'e', 'f', '\0'};
char *p1, *p2;

p1 = strchr(arr,' '); // find 1st space
p2 = strrchr(arr,' '); // find last space
if(p1 && p2)
   memmove(p1,p2+1,strlen(p2)+1); // remove all spaces
cout << arr << "\n";

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

Just zip up the whole project (minus object files) and attach them to your post so we can test it for you.

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

Are you sure you have the prequisits for that course? It sounds pretty advanced for a beginner.

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

If its so trivel post the code. Your code needs to come up with
562262574607502830000000000000000000000000000000
00000000000000000000.0000000000


That number is too huge for normal c-language math.

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

I have no idea how your teacher's program works -- you would have to post it. I can only suspect he used one of the huge integer libraries like I previously suggested. Its also possible he used strings instead of integers to avoid the limitations of integers.

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

If you want huge numbers then use one of the many huge integer libraries. I think boost has one and here is another.

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

Its integer overflow. Add a cout in the factorial function and you will see it. Integers, regardless of size, can only hold a finite value. When that value is exceeded the result is undefined and unpredictable.

long long factorial( int num )
{
	long long answer = 1;
	while ( num > 1 ) {
		answer *= num;
		num--;
	}
cout << fixed << answer << "\n";
	return answer;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <algorithm>
...
...
cout << fixed << result << endl; // I use this here to see the results of the factorial
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is that inline assembly code I see in both your programs? I guess you don't code for portability so that the code can be compiled by other people using other operating systems and/or compilers. And I'm sure a programming teacher would deduct points for that, unless its required as part of the assignment.

>>Personally I prefer speed to readability
Depends. Maintainability (and readability) are pretty important in the real-world.

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

You might need to revise this, as it will only remove one white-space.

That code must be put in a loop in order to remove other instances of multiple white spaces. I did not intend to post the entire solution, only a suggestion about how to go about solving it.

Not to mention the use of these tools for what should be simple strings is pretty dangerous!

memmove() is intended only for character arrays, not std::string. All C style string functions can be dangerous if the programmer uses them in a haphazard manner.

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

you can use memmove() to shift everything left one place to overwrite the second consecutive space.

char str[] = "Hello  World";
char* p = str;
while( !isspace(*p) )
   p++;
if( isspace(*p) && isspace(*(p+1)) )
   memmove(p+1, p+2, strlen(p+2) + 1); // + 1 to also move the NULL terminator
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>start = std::clock(); //reset clock
You can't use namespaces in *.c files.

Nick Evan commented: Oh duh... What the hell was I thinking? +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't compare directly (without operator overload) an instance of another clas (node->item) with c++ strings.

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

my GUESS is that item and first_name are character arrays. If that is right then you have to call strcmp() to check if the two strings are the same. Or you can change them to std::string.

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

Put the timer code in another thread. How to create the thread depends on the operatin system.

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

>>the char ctext[n_line_text][133] is not possible, n_line_text is not const
It is possible with a c99 compliant compiler. But not very many compilers have implemented that yet.

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

getline() reads 25 charcters, or up to end-of-line, which ever is shorter. In order for that to work the description field in the data file must always be 25 characters (fixed length). The newest file example you just posted has 3 words in some description fields, which tosses out my previous suggestion. Here is how I would do that NOTE: This has not been compiled or tested.

std::string line;
while( getline(fin, line) )
{
    size_t pos = 0;
     // find first non-digit character
    while( idsigit(line[pos]) )
          pos++;
    // extract pid
    nnptr->pid = atol( line.substr(0,pos).c_str());
    line = line.substr(pos+1);
    // find first digit field (end of description)
    for(pos = 0; !isdigit(line[pos]); pos++)
        ;
    // extract description
    strcpy(nnptr->description, line.substr[0,pos].c_str());
    line = line.substr(pos);
    // convert remainint integers
    strstring str(line);
    str >> nnptr->wholesale >> nnptr->markup >> nnptr->quantity;
    // add nnptr to linked list
    <snip>
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>but wrong way
Oh, now I see what you want to do. To my knowledge you can't do it. char *ctext[133]; is an array of 133 pointers but you want an array of n_lines_text number of pointers. It might be possible with a compiler that is C99 compliant, but most compilers aren't. You need char *ctext[n_lines_text]; or possibly even char ctext[n_lines_text][133];

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

line 77: >> fin.getline(description, 25);

Unfortunately that doesn't work because the description field is not a fixed size of 25 characters in the data file. What you need to do is just read the next two words and concantinate them together: something like this

std::string temp;
fin >> nnptr->description;
fin >> temp; temp = " " + temp;
strcat(nnptr->description, temp.c_str();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume num_lines_text is the valid size of the 2d array. If so

vector<string> theList;
for(int i = 0; i < num_lines_text; i++)
    theList.push_back(text_string[i]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Clink this link then scroll down the page a little and you will find the answer to your question.

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

what errors does your compiler produce -- and what compiler/operating system are you using ?

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

1) const char* A = a[0]; will point to the first of 25 strings in the 2d array.

2) A = x.c_str() doesn[t work because x is not c++ std::string class. character arrays like x do not have methods.

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

line 36: case is a c++ keyword so use another variable name in that loop.

line 38: you have to put variable names inside the parentheses, not data types.

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

did you try google?

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

>>please help me...if anybody is having any idea

Help you do what exactly? I didn't see a question in your post.

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

You have to use win32 api console functions.. And check out the console object here for example code

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

strcat() appends one string to the end of the other string. Before that will work you have to insure the destination string is big enough to hold both strings.

str3 is not needed, so just get rid of it.

The second problem with your program is that string literals can not be changed because they normally reside in read-only memory.

To correct the able problems

include<stdio.h>
#include<string.h>
int main()
{
char str1[126] ="United";
char *str2="front";
strcat(str1,str2);
printf("\n%s",str1);
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

should have been bstrVal

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

See the spelling in the error message -- you spelled it wrong. For the header file, just include windows.h or see MSDN

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

Here is how to allocate a BSTR. There are a few variations of SysAllocString() -- use the one that suits the purpose of your program.

VARIANT vt;
VariantInit(&vt); // initialize the variant
vt.vt = VT_BSTR; // set to BSTR string
vt.bstr_val = SysAllocString(_TEXT("Hello World"));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster