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

cant get any more open than that as to why you posted ,sell online ,and you sig is what it is

There is nothing wrong with his sig links, and his post was relevent to this thread. So I don't understand your beef with his post.

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

You have to include wininet.h and shlobj.h, then compile the program for UNICODE

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

replace all 7 loops with something a function

void GetMartks(std::string prompt, float& mark)
{
    cout << prompt << '\n';
    cin >> mark;
    mark = decimal(mark);
}

And call it in main() like this:

GetMark("T1:", a[n].vert.t1);
          GetMark("T2:", a[n].vert.t2);
          GetMark("T3:", a[n].vert.t3);
          GetMark("T4:", a[n].vert.t4);
          GetMark("T5:", a[n].vert.t5);
          GetMark("T6:", a[n].vert.t6;
          GetMark("T7:", a[n].vert.t7);

2) Because your program does not validate input. The decimal() function is broken when I enter a value > 99 or < 10. There are standard floating point functions to extract the decimal value of a float. This is a list of all the standard C/C++ math functions.

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

There are two ways to add a library to the program

1) #pragma comment(lib, "toolkit.lib"); Put this near the top of any *.cpp file that is in the project.

2) Select menu item Project --> Properties --> Configuration Properties --> Linker -->Input. Now add the name of the library in the "Additional Dependencies" edit control.

But I don't see why you need that library to solve your problem. Just use std::string substr() method to split the line.

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

>>if(!cookieOrdered.compare(flavors))

You can just simply write this: if( cookieOrdered == flavors[i] ) , assuming flavors is an array or vector of strings/character arrays..

>>cookieOrdered.clear();
Could also be: cookieOrdered = ""; line 8: There is really no point in using an iterator in that function. Just use a loop similar to line 13.


line 8 of the second code snippet: That is ignoring the return value of check_cookieordered().

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

The value 0.1 can not be represented exactly as a double.

Salem commented: Well said +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can always click the "Unanswered Threads" link on the right side of the screen.

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

line 23 and 29: You can't add an node that's allocated on the stack to the linked list. Reason: when the function returns the memory address of that node is destroyed and becomes invalid. To fix this you need to call malloc() to allocate memory for the node from the heap so that it doesn't get destroyed then the function returns.

// line 23 -- make node a pointer
linked_list* node = malloc( sizeof(linked_list));
node->next = NULL;
//
// line 29
lst->data = node; // removed the & address operator

You are going to have other problems with that insert function because all the code above does is toss the current value of lst->data into the bit bucket and replaces it with a newly allocated node. You will NOT get a linked list by doing that, but you WILL get lots of memory leaks. At line 29 you need to add the newly allocated node either to the beginning of the linked list chain or to the tail -- your choice.

If you want to add to the beginning of the list, then do this

node->next = lst->data;
lst->data = node;

If you want to add the newly allocated node to the tail of the linked list then you have to first find the tail (last node) and add the newly allocated node to it.

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

First create an temporary array to hold the values

int array[] = {Q1[0], Q2[0], Q3[0], Q4[0], Q5[0], Q6[0], Q7[0], Q8[0]};
// now for the array
for(int i = 0; i < 7; i++)
{
   for(int j = i+1; j < 8; j++)
   {
       if( array[i] > array[j] )
       {
           int temp = array[i];
           array[i] = array[j];
           array[j]= temp;
         }
    }
 }
 // now the median is the middle value of array
int median = array[4];

Once you get the above compiled and working, make a function out of it so that the function can be called for each row in the Q arrays.

int median(int Q1, int Q2, int Q3, int Q4, int Q5, int Q6, int Q7, int Q8)
{
    // calculate and return the median of the parameters
}

int main()
{
    int Q1[8], Q2[8], Q3[8] ... Q8[8];

    for(int i = 0; i < 8; i++)
    {
        int m = median( Q1[i], Q2[i], ... Q8[i]);
    }
}
mrnutty commented: Appreciate that you are helping this one. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

summer -- I hate snow and ice in the winter because it makes driving so hazardous.

Grn Xtrm commented: Same here +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Of course that doesn't discount the possibility that you are hermaphrodite (both male and female) :)

sknake commented: ++ +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Create a new project but instead of a console project create a static library, then add the files to it.

Or, if the files are small enough just add them to your console project as if you wrote them yourself. That way you don't have to bother making libraries out of them.

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

getline() will permit you to enter spaces in the string. If you don't want the spaces then use >> operator cin >> this->name; , but the problem with that is the >> operator will allow you to enter more characters than what this->name can hold.

>>would this lead to memory leaks or problems further down the line?
Probably if you fail to delete[] the memory.

In c++ it is better to use std::string instead of char* because you don't have to bother with memory allocation; the class will allocate memory as necessary.

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

turbo c++ is just too old, it won't even run on Windows 7 or Vista on PC. Get Code::Blocks, MinGW, or VC++ 2008 Express.

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

Yes I could, but give it a try yourself. Its easy to do, just write the loop first and after the loop delete the array. If you wrote that code snippet to allocate the memory then I'm confident you can write the code to delete it.

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

The last two arguments have similar problems.

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

you need to typecast the base class pointer into a derived class pointer before it can call functions unique to the derived class. Base class knows nothing about those functions. derived_class *pDerived = reinterpret_cast<derived_class*>(obj);

int main(void) {
  base_class *obj;

  obj = new derived_class (10);
  derived_class* pDerived = reinterpret_cast<derived_class*>(obj);     
  obj->func_1();
  obj->func_2();
  pDerived->func_3();
  pDerived->print_y();

  return 0;
}
C++NOOOB commented: Perfect! Solved my problem. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Already got my Christmas present this year -- Samsung 55" 400+ Hz LED TV, Blue-Ray DVD player, and Bose speakers.

William Hemsworth commented: Awesome :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is one way to do it -- use stringstream class

#include <sstream>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

int main(int argc, char* argv[])
{
    int day = 20;
    int month = 1;
    int year = 8;
    stringstream str;
    str << setw(2) << setfill('0') << year << setw(2) << month << setw(2)<< day;
    cout << str.str() << "\n";
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

string resides in std namespace and you have to tell the compiler what namespace it's in. You have several options (use only one of the options listed below)

  1. using namespace std; put that after the include files (least desireable option)
  2. using std::string; put that after the includes
  3. int extract_d(std::string s){ specify the namespace every time you declare an object of type string.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another way

if( file.is_open() )
{
    int n, x;
    float f;
    file >> n >> x; // get first line
    setM(n);
    setX(x);
    MatrixHandler data(n, n);
    while( file >> n >> x >> f ) // process remaining lines
    {

        // fill in the matrix here
    }
    

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

Yes because MFC doesn't know a thing about std::string. CString is the data type used by MFC to transfer strings from member variables to/from the MFC controls, such as edit box. There is a lot of code in the CView derived class that will be broken if you just simply replace CString with std::string. Until you learn how MFC works don't change a thing. Yes the compiler produces lots of code, and the MFC learning curve is about one year.

Carrots commented: Thanks buddy! :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you mean you read a c++ tutorial (you did NOT write it), and you want to know how to compile it? What compiler do you have? Each compiler is different.

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

Did you try deleting all object files and recompiling everything? If that doesn't work then post the offending source file.

NicAx64 commented: experienced can't be teached, it should obtained +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No worries ... we always love feedback so anytime you have anything to say, please be my guest ... and know that you're being heard. :)

Yea, right. Like you ignoring this thread.

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

I've looked at the assembly code quite a bit and have found it contains very little "useless junk". But you can have it produce assembly code listing if you want. Look in the c++ options and there you will see it. Unless you want to hand-code the entire program you will not be able to change the assembly code that it produces.

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

line 67: amic is an ininitialized pointer.

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

>>for(int i = 0; i < strlen(buffer); i++)

buffer is NOT a null-terminated string, so strlen() can/will not work with it. The buffer you created is just an array of characters, and memset set each byte of the array to the value of 0x01.

>>Why is it that when I use 0 instead of 1 in the above memset code, the buffer appears to have been wiped ou
Because the string functions in string.h all; use null-terminated string, and 0 is the same as NULL. So when you memset the buffer with 0 then you are telling strlen() and other string functions that the buffer is empty. strlen() returns the number of non-0 bytes in the buffer. It will scan the buffer until it encounters the first 0 byte, where-ever that may be. If you memset() the buffer with all 1s then strlen() will continuing looking through memory until it finds a byte whose value is 0.


>>as noted in my original post, everything past the pageFrameOffset appears to have been wiped from my buffer. The length of the array is much smaller when this happens.
That's because you are writing the binary value of the integer to the buffer, not the text value. Take the case of an integer whose value is 1. After memcpy() the buffer will contain (*nix operating system the bytes are in reverse order)
buffer[0] = 1
buffer[1] = 0
buffer[2] = 0
buffer[3] …

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

vector doesn't have a find() method. Maybe what you want is std::map instead of two vectors.

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

you can not convert an integer to character array like you tried to do. Use sprintf() instead sprintf(t, "%ld", i);

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

1) you failed to read Aia's comment.

2) The printf() statement is incorrect. %s is for a charcter array, shape is not a character array. What you want os %c

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

Using TurboC++ is like riding horse&buggy on todays interstates or autobahns (in europe). Ditch the horse&buggy and get a free modern ferrari.

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

Now you are using yet another new object that you have not told us about. What is m_pVect2Grid?? Please refrain from introducing new objects without defining them for use.

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

>>if (length=breadth)

you are using the wrong operator -- use == boolean operator instead of = assignment operator.

>> shape= 'square';
Two problems with that line

  1. All strings (two or more characters) have to be enclosed in double quotes, such as "square"
  2. variable [shape] can only hold a single character, such just do this: shape = 's'; . If you want shape to contain the entire string then redefine it as char shape[15]; and use strcpy() to copy it strcpy(shape,"square");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using a 32-bit compiler on either MS-Windows or *nix then forget those two functions because they are not implemented by any 32-bit/64-bit compiler. The operating system will not permit direct access to hardware or computer ports. You have to use normal operating system api functions. Those two functions were written for 16-bit MS-DOS which did permit programs direct access to hardware.

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

lines 22 and 25: delete the = " " There is no value to initializing the strings with a single space.

line 25: delete that line because it has no value.

line 48: useless. What you want is to build a std::string object, then after the loop finishes insert it into the vector

   for(int i = 1; i < num+1; i++)
    {
      str1 = ""; // clear the string for new line 
      for(int j = 0; j < i; j++, n++)
        {
        str1 += chars[n%26];
        }
      myVector.push_back(str1);
     }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

cout only works with text buffers -- your buffer contains binary information and most likely the very first byte is a 0.

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

simple colution

int main()
{
    int num;
    char chars[] = "abcdefghijklmnopqrstuvwxyz";
    cout << "How many strings do you want to create?\n";
    cin >> num;
    long n = 0;
    for(int i = 1; i < num+1; i++)
    {
        for(int j = 0; j < i; j++, n++)
            cout << chars[n%26];
        cout << '\n';
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

On my computer Alt+2 generages '☻', not ^B

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

It should exchange the value of the two variable parameters. The two parameters are passed by reference so that swap() can change them and the calling function will see the change.

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

>>is it a standard one?
Yes -- all compilers are required to implement it like that. Here is info about ansi c standards

>>the array name cannot be changed is it the standard or compiler dependent.
Standard -- its impossible to change the name of an object once it has been instantiated.

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

You can solve for pc first in a similar manner that I posted. I think the problem in ComputerMove() is that if a square is already eith 'x' or 'o' you need to generate another random number and try again. At some point the computer is going to generate a random number for a square that has already been used. When that happes it needs to generate another random number. You already had such a loop coded but you commented it out.

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

It doesn't make a lick of sense to write a custom print function for every conceivable data type using printf() or fprintf(). cout, ofstream and ifstream already have overloaded functions that do it for you. And formatting can be easily done using cout or fstream class.

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

This minor change made it work when I move first

if (choice==1)                                  //if player wishes to go first
      { 
            bool done = false;
            do{ 
                cout<<"\n turn = "<<t<<endl;
                HumanMove(Board);
                w=CheckWin(Board);
                if (w==1)
                {
                    cout<<"Youwin!";
                    done = true;
                }
                else if (w==2)
                {
                  cout<<"You lose!";
                  done = true;
                }
                else if (t==9&&w==0)
                {
                    cout<<"Tie Game";
                    done = true;
                }
                if( done == false)
                {
                    PrintBoard(Board);
                    ComputerMove(Board);
                    w=CheckWin(Board);
			        PrintBoard(Board);
                    t=t+1;
                }
            }while(done == false);
      }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh I see -- I guess I misunderstood. You would have to sort the list after it was finished. When sorting linked lists just exchange the actual data, not the entire nodes, to preserve the link pointers.

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

If all you want to do is run that program once when what' the point of making the text file into a fixed-length records? Such a scheme would limit the usefullness of your program.

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

where is your code? No one here will write that program for you.

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

what compiler are you using? I compiled/ran with vc++ 2008 express and your first program worked ok.

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

Change AddWord() to add the new node in ascending or descending order. Then you won't have to bother about sorting later.

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

1) remove conio.h -- its non'standard and not implemented by very many compilers. Code snippets should not use compiler-specific stuff.

2) delete all those global variables on lines 12 and 13. Just declare them inside the functions that use them. And you will probably have to pass the std* head pointer as a parameter to the functions that use it.

3) a few comments would be nice to explain what those functions do. Your entire program contains not even one comment. Subtract 3 points from your grade for that.

If I were going to grade this I would give it a grade of B. There is a lot of good code there, just needs to be cleaned up.