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

But if i have g++ compailer it is compatible.

No they are not. Read the link I posted earlier about the differences between the two languages. You can not always compile a C program with a c++ compiler without making some changes. One simple example: char *ptr = malloc(255); . That will compile with C but not C++.

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

According to this Austrilia is a continent. If the only geographical difference between a continent and and island is size, then why is Austrilia considered a continent and Greenland (2,175,600 sq km/840,000 sq mi) an island. Why isn't Greeland also a continent ? Or why isn't Austrilia an island? The answer I suspect is arbitrary.

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

you mean in the old ancient Turbo C ? You can't. Get a newer compiler that supports such things.

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

My oppinion is the next one.
I call C with C. :D
But C++ i call C with class.

Huh? Would you like to try to say that again :)

Yes, you can call C functions with c++, but can not call c++ functions that require c++ classes with C. The two languages are not compatible.

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

fscanf() may not work for this purpose-- (1) it will allow you to enter more characters than the buffer can hold which will cause your program to crash and (2) it stops reading the keyboard at the first space so the name you enter can not contain spaces.

The solution to both those problems is to use fgets()

char filename[255];
fgets(filename, sizeof(filename), stdin);

Now the above has its problems too. fgets() will add the '\n' (Enter key) to the end of filename, so you have to strip it off before using it for anything.

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

To do cleanup such as deallocate memory before the class is destroyed.

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

I agree PacMan, Donkey Kong, Super Mario Brothers, Doom and Diablo were probably the most influential to the gaming industry. Most of the others were probably very good games but did they have all that much influence on the way gamers wrote games in the future ?

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

I merged the two threads because they were the same question.

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

That's the only way to do it when using basic C-style arrays. If you are writing a c++ program then use std::string instead of char* and you will be able to easily get the array size whenever you need it.

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

Let me guess: you are using an ancient compiler such as Turbo C in MS-Windows operating system. If that is correct then you can forget about doing that because the os will not allow it, as you have already found out.

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

Do u have any more idea about the advatages of using cin and cout compared to printf() and scanf()?

Personally I think the c++ implementation of cout is absolutely horrible. In its simplest for cout is pretty easy to use, but get really complicated when you want nicely formatted code such as specifying field widths. printf() on the otherhand is compact and easy to learn. printf() beats the pants off cout every time.

>>What are the differences between C language and C++ language?
There are lots of differences and C99 made even more. Here is a discussion of them.

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

I suppose the first thing you need to do is complete that structure

struct MonthDat
{
    double rainfall;
    // etc
    
};

>> char monthname[][NUM_MONTHS] = {"January", "Febuary", "March", "April", "May", "June",
"June", "August", "September", "October", "November", "December" };

That's not the right way to do that. Here is a better way, which is simply an array of pointers to strings. You don't have to specify the number of elements in the array -- let the compiler to that for you.

char *monthname[] = {"January", "Febuary", "March", "April", "May", "June",
                                   "June", "August", "September", "October", "November", "December" };
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>'A Plus!'
grade can only hold a single character, and that is not a single character but a string. If that is what you want then change grade to a string. Note the use of the double quote instead of single quotes.

char studentScore (int score)
{
 int  temp = score / 100;
 char grade;
 switch (temp)
    {
     case 100 : grade = 'A Plus!';
               break;
     case  90 : grade = 'A';
               break;
     case  80 : grade = 'B';
               break;
     case  70 : grade = 'C';
               break;
     case  60 : grade = 'D';
               break;
     default : grade = 'F';
    } // switch
 return grade;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post what you have done so far. You will need an array of those structures, one for each month. Then just loop through the array and sum up the values.

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

What is that? [a.out]

The default name of the executable when using *nix compilers is a.out. Don't know why but probably just the custom by now.

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

>>The reverse when you store in string3 is to add '0'
Marauder: Note that you can only store a single digit using this -- '0' through '9'. Doesn't work for numeric values 10 and above or negative numbers.

>>char string1[10] ={'0','0','0','9','3','1','4','0','9','1'};
Well that's one way to do it -- and the hardest way too. This is easier to type and creates standard null-terminated string that can be used with all standard c and c++ library fundtions. char string1[] ="0009314091";

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

>>I am a moth major
what is a moth major? An Entomology major perhaps?

>>and don't understand C++ programming language
What you posted isn't c++. Its C, which is a different language.

What are the prerequisits for the class you are now taking? Is one of them at least one semester of C or C++ languages? Any other programming language?

Where in the world did you get all that horribly formatted code? It isn't necessary to manually add the line numbers if you use code tags correctly

[code=c++] // your code here

[/code]

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

There is no standard C or C++ library function to do that, you have to get it from os api. I'm not *nix programmer so I can't help you there. Sorry.

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

How much of this have you already written ? None? then why not? Do it in small steps and it will be a lot easier for you to code. Start here

int main()
{
    return 0;
}

Compile that and if it compiles add another little bit, such as display the first prompt you need. Do it in very small steps and you will soon have the whole program written.

Good luck :) Please post code and ask questions about what confuses you.

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

This shows the effects of the two calculations Salem posted. The first one assumes the bytes need to be swapped while the second assumes they do not. The buffer that contains the two bytes must be declared as unsigned char otherwise you will get the wrong results.

The code below first copies the binary values of a short int into the unsigned char buffer as it would be done on the sending side of your program. The rest would be executed on the receiving side.

int main()
{
    short n = 1000;
    unsigned char buf[3];
    memcpy(buf,&n,sizeof(short));
    //  
    // swap bytes
    short result = (buf[0] << 8) | buf[1];
    cout << "result = " << result << "\n";
    // do not swap bytes
    result =  buf[0] | ( buf[1] << 8 );
    cout << "result = " << result << "\n";
    // another way to do it if the bytes to not need to be swapped
    result = *(short *)buf;
    cout << "result = " << result << "\n";

    return 0;


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

I'm really supprised no one has posted this! I didn't find it but got the link from mattireland at PFO

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
char *  strcpy(char * to, char * from)
{
    char * temp=to; 
  
    while((*to++=*from++) != 0) {};
// what to is pointing to takes what from is 
// pointing to and the pointers move on.
// when end of string encountred (0) it stops
return temp;
// temp has the initial value of to in it so the
// copy can be cascaded.
}

Nice code and explaination, but doesn't solve the problem. Apparently the purpose of the exercise is to use the strcpy() function.

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

line 30: modf() takes pointers to two doubles. value is not a double. And it returns a double, not an integer. Please read the documentation for functions you use.

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

>>Then you'll have to read the documentation to find out
There may be other ways too. Lets say we are writing a server program that runs on *nix computer and the clients are a mixture of *nix, MAC and MS-Windows computers. The MS-Windows client program will just have to reverse the bytes of the data coming from the server. But in this case the server will have to look at who sent it the information before it can determine whether to byte swap or not. I think the htons function/macro might resolve that problem, but I'm not all that experienced in network programming.

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

The .dat file extension usually refers to files that contain binary information as opposed to text files. So if you want to read a binary file you have to open it with ios::binary flag as the second argument to the open() function. If you don't do that and if you are using MS-Windows operating system the stream object may mis-interpret any bytes that are the same as the '\n' line terminator. *nix and MAC don't have that problem.

The second thing about binary files is that the >> extraction operator don't work. That is for text files, not finary files. You have to use the stream's read() method.

The easiest way to determine if a file is binary or not is open it with Notpad. If you see a bunch of unreadable garbage such as small squares, then the file is binary. If everything can be read normally then it is a text file.

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

Sorry I misunderstood. What I suggested obviously won't work then. Normally I would do this: int x = *(short *)&buf[14]; . But that also assumed a short is two bytes, which may or may not be correct. And it may not work anyway due to byte ordering as previously mentioned.

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

I guess you have to take care of the order in which the bytes are packed as well ( e.g/ Big Endian, Little Endian ,etc0

Not necessary in this case because there is only one byte to the integer.

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

Open the file in vi and match braces.

That has to be the one most useful features of any program editor, other than of course the ability to type. And most good editors have it -- probably stolen from vi. It doesn't work well though if the code contains braces in quotes.

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

All I see are those little squares where the menubar should be. This just started in the last 6 hours or so. (IE7 on Vista Home)

[edit]Oops! its back to normal now. I have no idea what went wrong.[/edit]

~s.o.s~ commented: Nice avatar Mel. ;-) +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you search your school text book for those two functions? We are not here to write all the code for you but to help you write it yourself. If we write it you will learn nothing. Search around and you will find millions of examples of those two functions.

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

how about just simple assignment

int x1 = buf[14]; // 15th byte
int x2 = buf[15]; // 16th byte
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This worked ok for me

#include <vector>
#include <iostream>
using namespace std;

class DisjointSets
{

   public:
      void addelements(int n);
      int find(int a);
      void setunion(int a, int b);
      vector<int> ds;

};

//Creates n root nodes
void DisjointSets::addelements(int n)
{
   ds.resize(0);
   for(int i = 0; i < n; i++)
   {

      ds.push_back(-1);

   }

}

int _tmain(int argc, _TCHAR* argv[])
{
    DisjointSets s;
    s.addelements(5);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I was just taking a looking at that too.
Like I said before you can use a 1d array to simulate a 2d matrix if you do the math.

void Matrix::delData()
{
    if(data)
    {
        delete[] data;
        data = 0;
    }

}
void Matrix::allocate()
{
    delData();
    int n = numCols * numRows;
    data = new int[n];
    for(int i = 0; i < n; i++)
        data[i] = 0;

}
Matrix & Matrix::operator = (Matrix &m)
{
    delData();
	numCols = m.numCols;
	numRows = m.numRows;
    allocate();
    int n = numCols * numRows;
    for(int i = 0; i < n; i++)
        data[i] = m.data[i];
     return *this;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

vector<int> ds; does not go in a header file but in the *.cpp file, unless of course it is a member of some much larger c++ class which you didn't post.

vector<int> ds;
ds.push_back(0);

If the above still does not work then you are doing something wrong some other place, possible trashing memory. Post the whole probram so we can take a look.

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

You class has several problems. I am not detailing all of them, but giving you a few to get you going.
1. data must be declared as a 2-dimensional array. What you have is only one dimensional. It can work that way but is somewhat more difficult. Should be declared like this with two stars, not one: int **data; 2. The constructor needs to allocate space for the matrix

Matrix::Matrix(int r, int c)
{
	numCols = c;
	numRows = r;
    data = int*[numRows];
    for(int i = 0; i < numRows; i++)
        data[i] = new int[numCols];
}

The destructor needs to delete the matrix

Matrix::~Matrix()
{
    if(data)
    {
        for(int i = 0;i < numRows; i++)
        {
            delete[] data[i];
            data[i] = 0;
        }
        delete[] data;
        data = 0;
    }
}

The copy constructor needs to delete the current matrix if it exists and copy the matrix from the parameter

Matrix::Matrix(Matrix &m)
{
    if(data)
    {
        for(int i = 0;i < numRows; i++)
        {
            delete[] data[i];
            data[i] = 0;
        }
        delete[] data;
        data = 0;
    }
    numCols = m.numCols;
    numRows =  m.numRows;
    data = int*[numRows];
    for(int i = 0; i < numRows; i++)
        data[i] = new int[numCols];

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

Well, here is one way to do it. You can download a demo project that contains complete source code.

Here is another with a little more explaination of how to use it.

I'm sure if you search these google links you will find other ways.

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

Actually I think my previous post was wrong. You can't multiply two matrices by simply using the + operator and replacing the + with a *. And I don't think the + operator you posted is correct (or complete) either.

>>How do I multiply them though?

How about something like this->data[i][j] *= m.data[i][j]; . Put that inside an i and j loop where i goes from 0 to numRows and j from 0 to numCols

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

I've done that a time or two too. That's why another pair of eyes are often useful.

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

line 16: semicolon is missing at end of the line.

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

I have no idea because I don't know what the matrix class looks like. You did not post it. But probably something like this:

for(int row = 0; row < numRows; ++row)
{
   for(int col = 0; col < numCols; ++col)
   {
        cout << data[row][col] << " ";
   }
   cout << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>then how do I need to adjust this implementation file to work with it!?
You have to add two more methods: (1) print(), and (2) the * operator. The code you posted already has the = and + operators so make the * operator look similar to that + operator. Just substitute * for + and you have it done.

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

I don't think there is an age requirement to get a sponsor account. Anyone can donate $$$ to DaniWeb.

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

What is your question -- perhaps you forgot to post it? If you have a question about the code you posted then you have to tell us because we are not mind readers.

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

It doesn't run because it won't compiler -- you have some syntax errors in the code you posted. For example, line 21 is wrong because MAX_ROWS and MAX_COLUMNS have not been defined.

>>"How many columns or rows there are in the sudoku?\n";
Well, which are you asking us to input -- the number of columns or the number of rows? If you want both then you have to have an integer for each one because they can not be both in the same integer, like this:

cout <<"Enter the number of columns and rows  in the sudoku?\n";    
cin >> columns >> rows;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

cool. is area 51 any good?

Yes, that's where all the jucy gosip occurs :) (just kidding)

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

>>should I include that as an extern variable as well?
No. All you have to do is include the head file that defines the struct at the top of example.h. And don't forget to use code gards in both head files.

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

a turkey pot pie for breakfast

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

Do you need any help because according to the title of your thread you do.

He needs help all right, but it's not the king of help any of us can give him.

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

hnx ancient drgo for ur help.but im inmiddle of my examsand have to sbmit this project that inserts,deletes and searches anumber in ahash table with linear probing using c++.
Ifu can gie me the proram ,i wll b rly grateful to u...plz ur the only 1to ont upon..plz dont dissapont me..plz help me..i have tosubmit roject on 10december..plz help.

Huh???? I have no idea what you wrote. Please read the rules about using chatroom slang

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

>>Oh so the rows that do not hold more then one cell are free cause they where not filled.
No. they are free because they were never allocated.

>>because it hold no value.
Not quite -- they do hold a value but the code you just posted that value is some random and unpredictable value. It contains whatever was previously in that memory location, and that's why it is very important to initialize variables to a known value, usually 0

char*tab_veld[80] = {0};